Actually store preKeys

This commit is contained in:
AsamK 2015-07-07 11:04:59 +02:00
parent 08f8d2b026
commit dbebd38391
2 changed files with 10 additions and 1 deletions

View file

@ -34,7 +34,7 @@ public class JsonSignedPreKeyStore implements SignedPreKeyStore {
public JSONArray getJson() { public JSONArray getJson() {
JSONArray result = new JSONArray(); JSONArray result = new JSONArray();
for (Integer id : store.keySet()) { for (Integer id : store.keySet()) {
result.put(new JSONObject().put("id", id.toString()).put("record", store.get(id))); result.put(new JSONObject().put("id", id.toString()).put("record", Base64.encodeBytes(store.get(id))));
} }
return result; return result;
} }

View file

@ -24,6 +24,7 @@ import org.whispersystems.libaxolotl.InvalidVersionException;
import org.whispersystems.libaxolotl.state.PreKeyRecord; import org.whispersystems.libaxolotl.state.PreKeyRecord;
import org.whispersystems.libaxolotl.state.SignedPreKeyRecord; import org.whispersystems.libaxolotl.state.SignedPreKeyRecord;
import org.whispersystems.libaxolotl.util.KeyHelper; import org.whispersystems.libaxolotl.util.KeyHelper;
import org.whispersystems.libaxolotl.util.Medium;
import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.libaxolotl.util.guava.Optional;
import org.whispersystems.textsecure.api.TextSecureAccountManager; import org.whispersystems.textsecure.api.TextSecureAccountManager;
import org.whispersystems.textsecure.api.TextSecureMessagePipe; import org.whispersystems.textsecure.api.TextSecureMessagePipe;
@ -137,13 +138,21 @@ public class Manager {
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID))); //accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
registered = true; registered = true;
int start = 0; int start = 0;
List<PreKeyRecord> oneTimePreKeys = KeyHelper.generatePreKeys(start, 100); 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; int signedPreKeyId = 0;
SignedPreKeyRecord signedPreKeyRecord; SignedPreKeyRecord signedPreKeyRecord;
try { try {
signedPreKeyRecord = KeyHelper.generateSignedPreKey(axolotlStore.getIdentityKeyPair(), signedPreKeyId); signedPreKeyRecord = KeyHelper.generateSignedPreKey(axolotlStore.getIdentityKeyPair(), signedPreKeyId);
axolotlStore.storeSignedPreKey(signedPreKeyId, signedPreKeyRecord);
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
// Should really not happen // Should really not happen
System.out.println("invalid key"); System.out.println("invalid key");