From c1907b14eb62d0c85077abdb90ab1d101bdd5495 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 15 Jan 2015 18:29:32 -1000 Subject: [PATCH] Use axolotl.api for a few more things in libaxolotl/protocol.js --- libaxolotl/protocol.js | 16 ++++++++-------- libtextsecure/axolotl_wrapper.js | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libaxolotl/protocol.js b/libaxolotl/protocol.js index 69491d9b..10a1d7b0 100644 --- a/libaxolotl/protocol.js +++ b/libaxolotl/protocol.js @@ -43,7 +43,7 @@ window.textsecure.protocol = function() { var crypto_storage = {}; crypto_storage.putKeyPair = function(keyName, keyPair) { - textsecure.storage.putEncrypted("25519Key" + keyName, keyPair); + axolotl.api.storage.put("25519Key" + keyName, keyPair); } crypto_storage.getNewStoredKeyPair = function(keyName) { @@ -54,14 +54,14 @@ window.textsecure.protocol = function() { } crypto_storage.getStoredKeyPair = function(keyName) { - var res = textsecure.storage.getEncrypted("25519Key" + keyName); + var res = axolotl.api.storage.get("25519Key" + keyName); if (res === undefined) return undefined; return { pubKey: toArrayBuffer(res.pubKey), privKey: toArrayBuffer(res.privKey) }; } crypto_storage.removeStoredKeyPair = function(keyName) { - textsecure.storage.removeEncrypted("25519Key" + keyName); + axolotl.api.storage.remove("25519Key" + keyName); } crypto_storage.getIdentityKey = function() { @@ -583,7 +583,7 @@ window.textsecure.protocol = function() { var preKeyMsg = new axolotl.protobuf.PreKeyWhisperMessage(); preKeyMsg.identityKey = toArrayBuffer(crypto_storage.getIdentityKey().pubKey); - preKeyMsg.registrationId = textsecure.storage.getUnencrypted("registrationId"); + preKeyMsg.registrationId = axolotl.api.getMyRegistrationId(); if (session === undefined) { return axolotl.crypto.createKeyPair().then(function(baseKey) { @@ -621,11 +621,11 @@ window.textsecure.protocol = function() { self.generateKeys = function() { var identityKeyPair = crypto_storage.getIdentityKey(); var identityKeyCalculated = function(identityKeyPair) { - var firstPreKeyId = textsecure.storage.getEncrypted("maxPreKeyId", 0); - textsecure.storage.putEncrypted("maxPreKeyId", firstPreKeyId + GENERATE_KEYS_KEYS_GENERATED); + var firstPreKeyId = axolotl.api.storage.get("maxPreKeyId", 0); + axolotl.api.storage.put("maxPreKeyId", firstPreKeyId + GENERATE_KEYS_KEYS_GENERATED); - var signedKeyId = textsecure.storage.getEncrypted("signedKeyId", 0); - textsecure.storage.putEncrypted("signedKeyId", signedKeyId + 1); + var signedKeyId = axolotl.api.storage.get("signedKeyId", 0); + axolotl.api.storage.put("signedKeyId", signedKeyId + 1); var keys = {}; keys.identityKey = identityKeyPair.pubKey; diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js index 84fa349a..1a830d5d 100644 --- a/libtextsecure/axolotl_wrapper.js +++ b/libtextsecure/axolotl_wrapper.js @@ -8,6 +8,9 @@ getMyIdentifier: function() { return textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]; }, + getMyRegistrationId: function() { + return textsecure.storage.getUnencrypted("registrationId"); + }, isIdentifierSane: function(identifier) { return textsecure.utils.isNumberSane(identifier); },