]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/cli/Manager.java
Actually store preKeys
[signal-cli] / src / main / java / cli / Manager.java
index 1e7f02266554e6b5defdbb183c86e07f1035beac..b745988b5b1ee945c9ae223d10e30f75dc90f63a 100644 (file)
@@ -24,6 +24,7 @@ import org.whispersystems.libaxolotl.InvalidVersionException;
 import org.whispersystems.libaxolotl.state.PreKeyRecord;
 import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
 import org.whispersystems.libaxolotl.util.KeyHelper;
 import org.whispersystems.libaxolotl.state.PreKeyRecord;
 import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
 import org.whispersystems.libaxolotl.util.KeyHelper;
+import org.whispersystems.libaxolotl.util.Medium;
 import org.whispersystems.libaxolotl.util.guava.Optional;
 import org.whispersystems.textsecure.api.TextSecureAccountManager;
 import org.whispersystems.textsecure.api.TextSecureMessagePipe;
 import org.whispersystems.libaxolotl.util.guava.Optional;
 import org.whispersystems.textsecure.api.TextSecureAccountManager;
 import org.whispersystems.textsecure.api.TextSecureMessagePipe;
@@ -81,7 +82,9 @@ public class Manager {
         JSONObject in = new JSONObject(IOUtils.toString(new FileInputStream(getFileName())));
         username = in.getString("username");
         password = in.getString("password");
         JSONObject in = new JSONObject(IOUtils.toString(new FileInputStream(getFileName())));
         username = in.getString("username");
         password = in.getString("password");
-        signalingKey = in.getString("signalingKey");
+        if (in.has("signalingKey")) {
+            signalingKey = in.getString("signalingKey");
+        }
         axolotlStore = new JsonAxolotlStore(in.getJSONObject("axolotlStore"));
         registered = in.getBoolean("registered");
         accountManager = new TextSecureAccountManager(URL, TRUST_STORE, username, password);
         axolotlStore = new JsonAxolotlStore(in.getJSONObject("axolotlStore"));
         registered = in.getBoolean("registered");
         accountManager = new TextSecureAccountManager(URL, TRUST_STORE, username, password);
@@ -115,12 +118,16 @@ public class Manager {
         return registered;
     }
 
         return registered;
     }
 
-    public void register() throws IOException {
+    public void register(boolean voiceVerication) throws IOException {
         password = Util.getSecret(18);
 
         accountManager = new TextSecureAccountManager(URL, TRUST_STORE, username, password);
 
         password = Util.getSecret(18);
 
         accountManager = new TextSecureAccountManager(URL, TRUST_STORE, username, password);
 
-        accountManager.requestSmsVerificationCode();
+        if (voiceVerication)
+            accountManager.requestVoiceVerificationCode();
+        else
+            accountManager.requestSmsVerificationCode();
+
         registered = false;
     }
 
         registered = false;
     }
 
@@ -131,13 +138,21 @@ public class Manager {
 
         //accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
         registered = true;
 
         //accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
         registered = true;
+
         int start = 0;
         List<PreKeyRecord> oneTimePreKeys = KeyHelper.generatePreKeys(start, 100);
         int start = 0;
         List<PreKeyRecord> oneTimePreKeys = KeyHelper.generatePreKeys(start, 100);
+        for (int i = start; i < oneTimePreKeys.size(); i++) {
+            axolotlStore.storePreKey(i, oneTimePreKeys.get(i));
+        }
+
         PreKeyRecord lastResortKey = KeyHelper.generateLastResortPreKey();
         PreKeyRecord lastResortKey = KeyHelper.generateLastResortPreKey();
+        axolotlStore.storePreKey(Medium.MAX_VALUE, lastResortKey);
+
         int signedPreKeyId = 0;
         SignedPreKeyRecord signedPreKeyRecord;
         try {
             signedPreKeyRecord = KeyHelper.generateSignedPreKey(axolotlStore.getIdentityKeyPair(), signedPreKeyId);
         int signedPreKeyId = 0;
         SignedPreKeyRecord signedPreKeyRecord;
         try {
             signedPreKeyRecord = KeyHelper.generateSignedPreKey(axolotlStore.getIdentityKeyPair(), signedPreKeyId);
+            axolotlStore.storeSignedPreKey(signedPreKeyId, signedPreKeyRecord);
         } catch (InvalidKeyException e) {
             // Should really not happen
             System.out.println("invalid key");
         } catch (InvalidKeyException e) {
             // Should really not happen
             System.out.println("invalid key");