diff --git a/www/file/file-crypto.js b/www/file/file-crypto.js index 608b3bb6e..35e2f8037 100644 --- a/www/file/file-crypto.js +++ b/www/file/file-crypto.js @@ -7,6 +7,18 @@ define([ var plainChunkLength = 128 * 1024; var cypherChunkLength = 131088; + var encodePrefix = function (p) { + return [ + 65280, // 255 << 8 + 255, + ].map(function (n, i) { + return (p & n) >> ((1 - i) * 8); + }); + }; + var decodePrefix = function (A) { + return (A[0] << 8) | A[1]; + }; + var slice = function (A) { return Array.prototype.slice.call(A); }; @@ -64,6 +76,7 @@ define([ var nonce = createNonce(); var i = 0; + decodePrefix([]); // TODO var takeChunk = function () { var start = i * cypherChunkLength; var end = start + cypherChunkLength; @@ -126,6 +139,8 @@ define([ var encrypt = function (u8, metadata, key) { var nonce = createNonce(); + encodePrefix(); // TODO + // encode metadata var metaBuffer = Array.prototype.slice .call(Nacl.util.decodeUTF8(JSON.stringify(metadata))); diff --git a/www/file/main.js b/www/file/main.js index a7a0f0fb2..223fcc41e 100644 --- a/www/file/main.js +++ b/www/file/main.js @@ -24,16 +24,6 @@ define([ Cryptpad.addLoadingScreen(); - var fetch = function (src, cb) { - var xhr = new XMLHttpRequest(); - xhr.open("GET", src, true); - xhr.responseType = "arraybuffer"; - xhr.onload = function () { - return void cb(void 0, new Uint8Array(xhr.response)); - }; - xhr.send(null); - }; - var myFile; var myDataType; @@ -78,6 +68,7 @@ define([ var uri = ['', 'blob', id.slice(0,2), id].join('/'); console.log("encrypted blob is now available as %s", uri); + // TODO use cryptpad-common utilities window.location.hash = [ '', 2, @@ -88,6 +79,7 @@ define([ $form.hide(); + // check if the uploaded file can be decrypted var newU8 = FileCrypto.joinChunks(chunks); FileCrypto.decrypt(newU8, key, function (e, res) { if (e) { return console.error(e); } @@ -97,7 +89,7 @@ define([ var defaultName = Cryptpad.getDefaultName(Cryptpad.parsePadUrl(window.location.href)); APP.updateTitle(title || defaultName); - + Cryptpad.alert("successfully uploaded: " + title); }); }); }); @@ -212,7 +204,7 @@ define([ if (!uploadMode) { var src = Cryptpad.getBlobPathFromHex(hexFileName); - return fetch(src, function (e, u8) { + return Cryptpad.fetch(src, function (e, u8) { // now decrypt the u8 if (e) { return window.alert('error'); } var cryptKey = secret.keys && secret.keys.fileKeyStr;