Copy getRandomBytes from libaxolotl to libtextsecure
This commit is contained in:
parent
12844590f5
commit
7d2d2d92fc
4 changed files with 14 additions and 11 deletions
|
@ -24,9 +24,6 @@
|
||||||
|
|
||||||
window.axolotl.crypto = {
|
window.axolotl.crypto = {
|
||||||
getRandomBytes: function(size) {
|
getRandomBytes: function(size) {
|
||||||
// At some point we might consider XORing in hashes of random
|
|
||||||
// UI events to strengthen ourselves against RNG flaws in crypto.getRandomValues
|
|
||||||
// ie maybe take a look at how Gibson does it at https://www.grc.com/r&d/js.htm
|
|
||||||
var array = new Uint8Array(size);
|
var array = new Uint8Array(size);
|
||||||
window.crypto.getRandomValues(array);
|
window.crypto.getRandomValues(array);
|
||||||
return array.buffer;
|
return array.buffer;
|
||||||
|
|
|
@ -78,6 +78,12 @@
|
||||||
return encryptedBin.buffer;
|
return encryptedBin.buffer;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getRandomBytes: function(size) {
|
||||||
|
var array = new Uint8Array(size);
|
||||||
|
window.crypto.getRandomValues(array);
|
||||||
|
return array.buffer;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -242,14 +242,14 @@ textsecure.processDecrypted = function(decrypted, source) {
|
||||||
}
|
}
|
||||||
|
|
||||||
window.textsecure.registerSingleDevice = function(number, verificationCode, stepDone) {
|
window.textsecure.registerSingleDevice = function(number, verificationCode, stepDone) {
|
||||||
var signalingKey = axolotl.crypto.getRandomBytes(32 + 20);
|
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
|
||||||
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
||||||
|
|
||||||
var password = btoa(getString(axolotl.crypto.getRandomBytes(16)));
|
var password = btoa(getString(textsecure.crypto.getRandomBytes(16)));
|
||||||
password = password.substring(0, password.length - 2);
|
password = password.substring(0, password.length - 2);
|
||||||
textsecure.storage.putEncrypted("password", password);
|
textsecure.storage.putEncrypted("password", password);
|
||||||
|
|
||||||
var registrationId = new Uint16Array(axolotl.crypto.getRandomBytes(2))[0];
|
var registrationId = new Uint16Array(textsecure.crypto.getRandomBytes(2))[0];
|
||||||
registrationId = registrationId & 0x3fff;
|
registrationId = registrationId & 0x3fff;
|
||||||
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
||||||
|
|
||||||
|
@ -273,14 +273,14 @@ window.textsecure.registerSecondDevice = function(encodedProvisionEnvelope, cryp
|
||||||
return cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(identityKey) {
|
return cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(identityKey) {
|
||||||
stepDone(1);
|
stepDone(1);
|
||||||
|
|
||||||
var signalingKey = axolotl.crypto.getRandomBytes(32 + 20);
|
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
|
||||||
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
||||||
|
|
||||||
var password = btoa(getString(axolotl.crypto.getRandomBytes(16)));
|
var password = btoa(getString(textsecure.crypto.getRandomBytes(16)));
|
||||||
password = password.substring(0, password.length - 2);
|
password = password.substring(0, password.length - 2);
|
||||||
textsecure.storage.putEncrypted("password", password);
|
textsecure.storage.putEncrypted("password", password);
|
||||||
|
|
||||||
var registrationId = new Uint16Array(axolotl.crypto.getRandomBytes(2))[0];
|
var registrationId = new Uint16Array(textsecure.crypto.getRandomBytes(2))[0];
|
||||||
registrationId = registrationId & 0x3fff;
|
registrationId = registrationId & 0x3fff;
|
||||||
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
||||||
|
|
||||||
|
|
|
@ -232,9 +232,9 @@ window.textsecure.messaging = function() {
|
||||||
|
|
||||||
makeAttachmentPointer = function(attachment) {
|
makeAttachmentPointer = function(attachment) {
|
||||||
var proto = new textsecure.protobuf.PushMessageContent.AttachmentPointer();
|
var proto = new textsecure.protobuf.PushMessageContent.AttachmentPointer();
|
||||||
proto.key = axolotl.crypto.getRandomBytes(64);
|
proto.key = textsecure.crypto.getRandomBytes(64);
|
||||||
|
|
||||||
var iv = axolotl.crypto.getRandomBytes(16);
|
var iv = textsecure.crypto.getRandomBytes(16);
|
||||||
return textsecure.crypto.encryptAttachment(attachment.data, proto.key, iv).then(function(encryptedBin) {
|
return textsecure.crypto.encryptAttachment(attachment.data, proto.key, iv).then(function(encryptedBin) {
|
||||||
return textsecure.api.putAttachment(encryptedBin).then(function(id) {
|
return textsecure.api.putAttachment(encryptedBin).then(function(id) {
|
||||||
proto.id = id;
|
proto.id = id;
|
||||||
|
|
Loading…
Reference in a new issue