Commit 0b8bd163 authored by amrani's avatar amrani

adding friedly user password to cryptostorage

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