Commit 0b8bd163 authored by amrani's avatar amrani

adding friedly user password to cryptostorage

parent d963b0a5
...@@ -75,6 +75,7 @@ module.exports = function (grunt) { ...@@ -75,6 +75,7 @@ module.exports = function (grunt) {
indent: 2, indent: 2,
maxerr: 3, maxerr: 3,
predef: [ predef: [
'DataView',
'define', 'define',
'exports', 'exports',
'require', 'require',
......
This diff is collapsed.
...@@ -255,12 +255,15 @@ ...@@ -255,12 +255,15 @@
}) })
.push(function (evt) { .push(function (evt) {
if (evt.target.response instanceof Blob) { if (evt.target.response instanceof Blob) {
return evt.target.response; //create a new blob with type AES-GCM to decrypt back
var cryptblob = new Blob([evt.target.response],
{type: "application/x-jio-aes-gcm-encryption"});
return cryptblob;
} }
return new Blob( return new Blob(
[evt.target.responseText], [evt.target.responseText],
{"type": evt.target.getResponseHeader('Content-Type') || {"type": "application/x-jio-aes-gcm-encryption"}
"application/octet-stream"} // evt.target.getResponseHeader('Content-Type') ||
); );
}, function (error) { }, function (error) {
if (error.target !== undefined && error.target.status === 409) { if (error.target !== undefined && error.target.status === 409) {
...@@ -325,4 +328,4 @@ ...@@ -325,4 +328,4 @@
jIO.addStorage('dropbox', DropboxStorage); jIO.addStorage('dropbox', DropboxStorage);
}(jIO, RSVP, Blob, JSON)); }(jIO, RSVP, Blob, JSON));
\ No newline at end of file
...@@ -11,9 +11,15 @@ ...@@ -11,9 +11,15 @@
equal = QUnit.equal, equal = QUnit.equal,
throws = QUnit.throws, throws = QUnit.throws,
module = QUnit.module, module = QUnit.module,
key = {"alg": "A256GCM", "ext": true, key = "password",
"k": "seeaLzpu8dHG07bO2ANH2GywbTqs_zrs4Vq8zmtYeE4", key_generated_by_password = {
"key_ops": ["encrypt", "decrypt"], "kty": "oct"}; "alg": "A256GCM",
"ext": true,
"k": "wBHHU4Es8IqMCnH03Jxhc1ZTQN7hzo6GkCNnbA_0kjI",
"key_ops": ["encrypt", "decrypt"],
"kty": "oct"
};
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Custom test substorage definition // Custom test substorage definition
...@@ -362,8 +368,7 @@ ...@@ -362,8 +368,7 @@
test("return substorage getattachment if not data url", function () { test("return substorage getattachment if not data url", function () {
var id = "/", var id = "/",
attachment = "stringattachment", attachment = "stringattachment",
blob = new Blob(['foo'], blob = new Blob(['foo'], {type: 'application/x-jio-aes-gcm-encryption'});
{type: 'application/x-jio-aes-gcm-encryption'});
Storage200.prototype.getAttachment = function (arg1, arg2) { Storage200.prototype.getAttachment = function (arg1, arg2) {
equal(arg1, id, "getAttachment 200 called"); equal(arg1, id, "getAttachment 200 called");
...@@ -390,10 +395,12 @@ ...@@ -390,10 +395,12 @@
var id = "/", var id = "/",
attachment = "stringattachment", attachment = "stringattachment",
value = "azertyuio\npàç_è-('é&", value = "azertyuio\npàç_è-('é&",
tocheck = "data:application/x-jio-aes-gcm-encryption;base64" + tocheck = "data:application/x-jio-aes-gcm-encryption" +
",+p/Ho+KgGHZC2zDLMbQQS2tXcsy0g+Ho41VZnlPEkXdmG9zm36c8iLCkv" + ";base64,2lHQ9xpJJ9qd81DxZEyd1LICtaV3XD+I2d5cp137L4NQC" +
"lanyWCN510NK4hj1EgWQ6WrLS5pCmA/yeAWh+HyfPkYKDRHVBl6+Hxd53I" + "vdkasBaFkPUE5XiY88g5z0oN9dcDASfChmvgqrkDExKS+zVglvVVs" +
"TmiWQ6Vix2jaIQg==", "CyECYorZ5fwgMCWAL5vUNCCaqhFVFyng==",
blob = jIO.util.dataURItoBlob(tocheck); blob = jIO.util.dataURItoBlob(tocheck);
...@@ -427,6 +434,7 @@ ...@@ -427,6 +434,7 @@
}); });
}); });
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// CryptStorage.putAttachment // CryptStorage.putAttachment
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -445,7 +453,7 @@ ...@@ -445,7 +453,7 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return crypto.subtle.importKey("jwk", key, return crypto.subtle.importKey("jwk", key_generated_by_password,
"AES-GCM", false, ["decrypt"]); "AES-GCM", false, ["decrypt"]);
}) })
.push(function (res) { .push(function (res) {
...@@ -460,11 +468,10 @@ ...@@ -460,11 +468,10 @@
coded = coded.target.result; coded = coded.target.result;
iv = new Uint8Array(coded.slice(0, 12)); iv = new Uint8Array(coded.slice(0, 12));
return crypto.subtle.decrypt({name : "AES-GCM", iv : iv}, return crypto.subtle.decrypt({name: "AES-GCM", iv: iv},
decryptKey, coded.slice(12)); decryptKey, coded.slice(12));
}) })
.push(function (arr) { .push(function (arr) {
arr = String.fromCharCode.apply(null, new Uint8Array(arr)); arr = String.fromCharCode.apply(null, new Uint8Array(arr));
equal( equal(
arr, arr,
...@@ -492,6 +499,7 @@ ...@@ -492,6 +499,7 @@
return decodeAES(arg3); return decodeAES(arg3);
}; };
stop(); stop();
expect(7); expect(7);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment