gcm encryption

This commit is contained in:
Abhinav Adduri 2017-06-20 13:03:04 -07:00 committed by Danny Coates
parent a7fcb1a44f
commit 50995238bd
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
4 changed files with 30 additions and 32 deletions

View File

@ -54,36 +54,32 @@ class FileReceiver extends EventEmitter {
{
kty: 'oct',
k: location.hash.slice(1),
alg: 'A128CBC',
alg: 'A256GCM',
ext: true
},
{
name: 'AES-CBC'
name: 'AES-GCM'
},
true,
['encrypt', 'decrypt']
)
])
.then(([fdata, key]) => {
const salt = this.salt;
return Promise.all([
window.crypto.subtle.decrypt(
{
name: 'AES-CBC',
iv: salt
},
key,
fdata.data
),
new Promise((resolve, reject) => {
resolve(fdata.fname);
})
]);
})
.catch(err => {
Raven.captureException(err);
return Promise.reject(err);
});
]).then(([fdata, key]) => {
const salt = this.salt;
return Promise.all([
window.crypto.subtle.decrypt(
{
name: 'AES-GCM',
iv: salt,
tagLength: 128
},
key,
fdata.data
),
new Promise((resolve, reject) => {
resolve(fdata.fname);
})
]);
});
}
}

View File

@ -7,7 +7,7 @@ class FileSender extends EventEmitter {
constructor(file) {
super();
this.file = file;
this.iv = window.crypto.getRandomValues(new Uint8Array(16));
this.iv = window.crypto.getRandomValues(new Uint8Array(12));
}
static delete(fileId, token) {
@ -39,12 +39,13 @@ class FileSender extends EventEmitter {
return Promise.all([
window.crypto.subtle.generateKey(
{
name: 'AES-CBC',
length: 128
name: 'AES-GCM',
length: 256,
tagLength: 128
},
true,
['encrypt', 'decrypt']
),
).catch(err => console.log('There was an error generating a crypto key')),
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsArrayBuffer(this.file);
@ -57,12 +58,13 @@ class FileSender extends EventEmitter {
return Promise.all([
window.crypto.subtle.encrypt(
{
name: 'AES-CBC',
iv: this.iv
name: 'AES-GCM',
iv: this.iv,
tagLength: 128
},
secretKey,
plaintext
),
).catch(err => console.log('Error with encrypting.')),
window.crypto.subtle.exportKey('jwk', secretKey)
]);
})

View File

@ -12,7 +12,7 @@ function ivToStr(iv) {
}
function strToIv(str) {
const iv = new Uint8Array(16);
const iv = new Uint8Array(12);
for (let i = 0; i < str.length; i += 2) {
iv[i / 2] = parseInt(str.charAt(i) + str.charAt(i + 1), 16);
}

View File

@ -171,5 +171,5 @@ app.listen(conf.listen_port, () => {
});
const validateID = route_id => {
return route_id.match(/^[0-9a-fA-F]{32}$/) !== null;
return route_id.match(/^[0-9a-fA-F]{24}$/) !== null;
};