org.whispersystems.libsignal.state.PreKeyRecord Java Examples

The following examples show how to use org.whispersystems.libsignal.state.PreKeyRecord. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public void registerPreKeys(IdentityKey identityKey,
                            SignedPreKeyRecord signedPreKey,
                            List<PreKeyRecord> records)
    throws IOException
{
  List<PreKeyEntity> entities = new LinkedList<>();

  for (PreKeyRecord record : records) {
    PreKeyEntity entity = new PreKeyEntity(record.getId(),
                                           record.getKeyPair().getPublicKey());

    entities.add(entity);
  }

  SignedPreKeyEntity signedPreKeyEntity = new SignedPreKeyEntity(signedPreKey.getId(),
                                                                 signedPreKey.getKeyPair().getPublicKey(),
                                                                 signedPreKey.getSignature());

  makeServiceRequest(String.format(PREKEY_PATH, ""), "PUT",
                     JsonUtil.toJson(new PreKeyState(entities, signedPreKeyEntity, identityKey)));
}
 
Example #2
Source File: OneTimePreKeyDatabase.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public @Nullable PreKeyRecord getPreKey(int keyId) {
  SQLiteDatabase database = databaseHelper.getReadableDatabase();

  try (Cursor cursor = database.query(TABLE_NAME, null, KEY_ID + " = ?",
                                      new String[] {String.valueOf(keyId)},
                                      null, null, null))
  {
    if (cursor != null && cursor.moveToFirst()) {
      try {
        ECPublicKey  publicKey  = Curve.decodePoint(Base64.decode(cursor.getString(cursor.getColumnIndexOrThrow(PUBLIC_KEY))), 0);
        ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(cursor.getString(cursor.getColumnIndexOrThrow(PRIVATE_KEY))));

        return new PreKeyRecord(keyId, new ECKeyPair(publicKey, privateKey));
      } catch (InvalidKeyException | IOException e) {
        Log.w(TAG, e);
      }
    }
  }

  return null;
}
 
Example #3
Source File: PreKeyUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public synchronized static List<PreKeyRecord> generatePreKeys(Context context) {
  PreKeyStore        preKeyStore    = new TextSecurePreKeyStore(context);
  List<PreKeyRecord> records        = new LinkedList<>();
  int                preKeyIdOffset = TextSecurePreferences.getNextPreKeyId(context);

  for (int i=0;i<BATCH_SIZE;i++) {
    int          preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
    ECKeyPair    keyPair  = Curve.generateKeyPair();
    PreKeyRecord record   = new PreKeyRecord(preKeyId, keyPair);

    preKeyStore.storePreKey(preKeyId, record);
    records.add(record);
  }

  TextSecurePreferences.setNextPreKeyId(context, (preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);

  return records;
}
 
Example #4
Source File: IqGenerator.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
                               final Set<PreKeyRecord> preKeyRecords, final int deviceId, Bundle publishOptions) {
    final Element item = new Element("item");
    item.setAttribute("id", "current");
    final Element bundle = item.addChild("bundle", AxolotlService.PEP_PREFIX);
    final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic");
    signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId());
    ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey();
    signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.NO_WRAP));
    final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
    signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.NO_WRAP));
    final Element identityKeyElement = bundle.addChild("identityKey");
    identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.NO_WRAP));

    final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX);
    for (PreKeyRecord preKeyRecord : preKeyRecords) {
        final Element prekey = prekeys.addChild("preKeyPublic");
        prekey.setAttribute("preKeyId", preKeyRecord.getId());
        prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.NO_WRAP));
    }

    return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item, publishOptions);
}
 
Example #5
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
public void registerPreKeys(IdentityKey identityKey,
                            SignedPreKeyRecord signedPreKey,
                            List<PreKeyRecord> records)
    throws IOException
{
  List<PreKeyEntity> entities = new LinkedList<>();

  for (PreKeyRecord record : records) {
    PreKeyEntity entity = new PreKeyEntity(record.getId(),
                                           record.getKeyPair().getPublicKey());

    entities.add(entity);
  }

  SignedPreKeyEntity signedPreKeyEntity = new SignedPreKeyEntity(signedPreKey.getId(),
                                                                 signedPreKey.getKeyPair().getPublicKey(),
                                                                 signedPreKey.getSignature());

  makeServiceRequest(String.format(PREKEY_PATH, ""), "PUT",
                     JsonUtil.toJson(new PreKeyState(entities, signedPreKeyEntity, identityKey)));
}
 
Example #6
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
private List<PreKeyRecord> generatePreKeys() {
    List<PreKeyRecord> records = new ArrayList<>(ServiceConfig.PREKEY_BATCH_SIZE);

    final int offset = account.getPreKeyIdOffset();
    for (int i = 0; i < ServiceConfig.PREKEY_BATCH_SIZE; i++) {
        int preKeyId = (offset + i) % Medium.MAX_VALUE;
        ECKeyPair keyPair = Curve.generateKeyPair();
        PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);

        records.add(record);
    }

    account.addPreKeys(records);
    account.save();

    return records;
}
 
Example #7
Source File: Manager.java    From signald with GNU General Public License v3.0 6 votes vote down vote up
private List<PreKeyRecord> generatePreKeys() throws IOException {
    List<PreKeyRecord> records = new LinkedList<>();

    for (int i = 0; i < PREKEY_BATCH_SIZE; i++) {
        int preKeyId = (accountData.preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair keyPair = Curve.generateKeyPair();
        PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);

        accountData.axolotlStore.preKeys.storePreKey(preKeyId, record);
        records.add(record);
    }

    accountData.preKeyIdOffset = (accountData.preKeyIdOffset + PREKEY_BATCH_SIZE + 1) % Medium.MAX_VALUE;
    accountData.save();

    return records;
}
 
Example #8
Source File: IqGenerator.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
                               final Set<PreKeyRecord> preKeyRecords, final int deviceId, Bundle publishOptions) {
    final Element item = new Element("item");
    item.setAttribute("id", "current");
    final Element bundle = item.addChild("bundle", AxolotlService.PEP_PREFIX);
    final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic");
    signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId());
    ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey();
    signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.NO_WRAP));
    final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
    signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.NO_WRAP));
    final Element identityKeyElement = bundle.addChild("identityKey");
    identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.NO_WRAP));

    final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX);
    for (PreKeyRecord preKeyRecord : preKeyRecords) {
        final Element prekey = prekeys.addChild("preKeyPublic");
        prekey.setAttribute("preKeyId", preKeyRecord.getId());
        prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.NO_WRAP));
    }

    return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item, publishOptions);
}
 
Example #9
Source File: PreKeyUtil.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public static List<PreKeyRecord> generatePreKeys(Context context, AccountContext accountContext) {
    PreKeyStore preKeyStore = new TextSecurePreKeyStore(context, accountContext);
    List<PreKeyRecord> records = new LinkedList<>();
    int preKeyIdOffset = getNextPreKeyId(context, accountContext);

    for (int i = 0; i < BATCH_SIZE; i++) {
        int preKeyId = (preKeyIdOffset + i) % Medium.MAX_VALUE;
        ECKeyPair keyPair = Curve.generateKeyPair();
        PreKeyRecord record = new PreKeyRecord(preKeyId, keyPair);

        preKeyStore.storePreKey(preKeyId, record);
        records.add(record);
    }

    setNextPreKeyId(context, accountContext,(preKeyIdOffset + BATCH_SIZE + 1) % Medium.MAX_VALUE);
    return records;
}
 
Example #10
Source File: SimultaneousInitiateTests.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
private PreKeyBundle createBobPreKeyBundle(SignalProtocolStore bobStore) throws InvalidKeyException {
  ECKeyPair bobUnsignedPreKey   = Curve.generateKeyPair();
  int       bobUnsignedPreKeyId = new Random().nextInt(Medium.MAX_VALUE);
  byte[]    bobSignature        = Curve.calculateSignature(bobStore.getIdentityKeyPair().getPrivateKey(),
                                                           bobSignedPreKey.getPublicKey().serialize());

  PreKeyBundle bobPreKeyBundle = new PreKeyBundle(1, 1,
                                                  bobUnsignedPreKeyId, bobUnsignedPreKey.getPublicKey(),
                                                  bobSignedPreKeyId, bobSignedPreKey.getPublicKey(),
                                                  bobSignature, bobStore.getIdentityKeyPair().getPublicKey());

  bobStore.storeSignedPreKey(bobSignedPreKeyId, new SignedPreKeyRecord(bobSignedPreKeyId, System.currentTimeMillis(), bobSignedPreKey, bobSignature));
  bobStore.storePreKey(bobUnsignedPreKeyId, new PreKeyRecord(bobUnsignedPreKeyId, bobUnsignedPreKey));

  return bobPreKeyBundle;
}
 
Example #11
Source File: SimultaneousInitiateTests.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
private PreKeyBundle createAlicePreKeyBundle(SignalProtocolStore aliceStore) throws InvalidKeyException {
  ECKeyPair aliceUnsignedPreKey   = Curve.generateKeyPair();
  int       aliceUnsignedPreKeyId = new Random().nextInt(Medium.MAX_VALUE);
  byte[]    aliceSignature        = Curve.calculateSignature(aliceStore.getIdentityKeyPair().getPrivateKey(),
                                                             aliceSignedPreKey.getPublicKey().serialize());

  PreKeyBundle alicePreKeyBundle = new PreKeyBundle(1, 1,
                                                    aliceUnsignedPreKeyId, aliceUnsignedPreKey.getPublicKey(),
                                                    aliceSignedPreKeyId, aliceSignedPreKey.getPublicKey(),
                                                    aliceSignature, aliceStore.getIdentityKeyPair().getPublicKey());

  aliceStore.storeSignedPreKey(aliceSignedPreKeyId, new SignedPreKeyRecord(aliceSignedPreKeyId, System.currentTimeMillis(), aliceSignedPreKey, aliceSignature));
  aliceStore.storePreKey(aliceUnsignedPreKeyId, new PreKeyRecord(aliceUnsignedPreKeyId, aliceUnsignedPreKey));

  return alicePreKeyBundle;
}
 
Example #12
Source File: SQLiteAxolotlStore.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Store a local PreKeyRecord.
 *
 * @param preKeyId the ID of the PreKeyRecord to store.
 * @param record   the PreKeyRecord.
 */
@Override
public void storePreKey(int preKeyId, PreKeyRecord record) {
    mXmppConnectionService.databaseBackend.storePreKey(account, record);
    currentPreKeyId = preKeyId;
    boolean success = this.account.setKey(JSONKEY_CURRENT_PREKEY_ID, Integer.toString(preKeyId));
    if (success) {
        mXmppConnectionService.databaseBackend.updateAccount(account);
    } else {
        Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Failed to write new prekey id to the database!");
    }
}
 
Example #13
Source File: SignalBot.java    From signal-bot with GNU General Public License v3.0 5 votes vote down vote up
private void refreshPreKeys(IdentityKeyPair identityKeyPair) throws IOException, InvalidKeyException {
    int initialPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
    List<PreKeyRecord> records = KeyHelper.generatePreKeys(initialPreKeyId, BATCH_SIZE);
    records.forEach((v) -> this.protocolStore.storePreKey(v.getId(), v));
    int signedPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
    SignedPreKeyRecord signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, signedPreKeyId);
    this.protocolStore.storeSignedPreKey(signedPreKey.getId(), signedPreKey);
    this.accountManager.setPreKeys(identityKeyPair.getPublicKey(), signedPreKey, records);
}
 
Example #14
Source File: SQLiteAxolotlStore.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load a local PreKeyRecord.
 *
 * @param preKeyId the ID of the local PreKeyRecord.
 * @return the corresponding PreKeyRecord.
 * @throws InvalidKeyIdException when there is no corresponding PreKeyRecord.
 */
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
    PreKeyRecord record = mXmppConnectionService.databaseBackend.loadPreKey(account, preKeyId);
    if (record == null) {
        throw new InvalidKeyIdException("No such PreKeyRecord: " + preKeyId);
    }
    return record;
}
 
Example #15
Source File: DatabaseBackend.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public void storePreKey(Account account, PreKeyRecord record) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(SQLiteAxolotlStore.ID, record.getId());
    values.put(SQLiteAxolotlStore.KEY, Base64.encodeToString(record.serialize(), Base64.DEFAULT));
    values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
    db.insert(SQLiteAxolotlStore.PREKEY_TABLENAME, null, values);
}
 
Example #16
Source File: JsonPreKeyStore.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
    try {
        if (!store.containsKey(preKeyId)) {
            throw new InvalidKeyIdException("No such prekeyrecord!");
        }

        return new PreKeyRecord(store.get(preKeyId));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
Example #17
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
void refreshPreKeys() throws IOException {
    List<PreKeyRecord> oneTimePreKeys = generatePreKeys();
    final IdentityKeyPair identityKeyPair = getIdentityKeyPair();
    SignedPreKeyRecord signedPreKeyRecord = generateSignedPreKey(identityKeyPair);

    accountManager.setPreKeys(identityKeyPair.getPublicKey(), signedPreKeyRecord, oneTimePreKeys);
}
 
Example #18
Source File: JsonPreKeyStore.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
    try {
        if (!store.containsKey(preKeyId)) {
            throw new InvalidKeyIdException("No such prekeyrecord!");
        }

        return new PreKeyRecord(store.get(preKeyId));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
Example #19
Source File: SQLiteAxolotlStore.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Store a local PreKeyRecord.
 *
 * @param preKeyId the ID of the PreKeyRecord to store.
 * @param record   the PreKeyRecord.
 */
@Override
public void storePreKey(int preKeyId, PreKeyRecord record) {
	mXmppConnectionService.databaseBackend.storePreKey(account, record);
	currentPreKeyId = preKeyId;
	boolean success = this.account.setKey(JSONKEY_CURRENT_PREKEY_ID, Integer.toString(preKeyId));
	if (success) {
		mXmppConnectionService.databaseBackend.updateAccount(account);
	} else {
		Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Failed to write new prekey id to the database!");
	}
}
 
Example #20
Source File: SilencePreKeyStore.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
  synchronized (FILE_LOCK) {
    try {
      return new PreKeyRecord(loadSerializedRecord(getPreKeyFile(preKeyId)));
    } catch (IOException | InvalidMessageException e) {
      Log.w(TAG, e);
      throw new InvalidKeyIdException(e);
    }
  }
}
 
Example #21
Source File: SilencePreKeyStore.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void storePreKey(int preKeyId, PreKeyRecord record) {
  synchronized (FILE_LOCK) {
    try {
      storeSerializedRecord(getPreKeyFile(preKeyId), record.serialize());
    } catch (IOException e) {
      throw new AssertionError(e);
    }
  }
}
 
Example #22
Source File: InMemoryPreKeyStore.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
  try {
    if (!store.containsKey(preKeyId)) {
      throw new InvalidKeyIdException("No such prekeyrecord!");
    }

    return new PreKeyRecord(store.get(preKeyId));
  } catch (IOException e) {
    throw new AssertionError(e);
  }
}
 
Example #23
Source File: SessionBuilderTest.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public void testRepeatBundleMessageV2() throws InvalidKeyException, UntrustedIdentityException, InvalidVersionException, InvalidMessageException, InvalidKeyIdException, DuplicateMessageException, LegacyMessageException, NoSessionException {
  SignalProtocolStore aliceStore          = new TestInMemorySignalProtocolStore();
  SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS);

  SignalProtocolStore bobStore = new TestInMemorySignalProtocolStore();

  ECKeyPair bobPreKeyPair            = Curve.generateKeyPair();
  ECKeyPair bobSignedPreKeyPair      = Curve.generateKeyPair();
  byte[]    bobSignedPreKeySignature = Curve.calculateSignature(bobStore.getIdentityKeyPair().getPrivateKey(),
                                                                bobSignedPreKeyPair.getPublicKey().serialize());

  PreKeyBundle bobPreKey = new PreKeyBundle(bobStore.getLocalRegistrationId(), 1,
                                            31337, bobPreKeyPair.getPublicKey(),
                                            0, null, null,
                                            bobStore.getIdentityKeyPair().getPublicKey());

  bobStore.storePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair));
  bobStore.storeSignedPreKey(22, new SignedPreKeyRecord(22, System.currentTimeMillis(), bobSignedPreKeyPair, bobSignedPreKeySignature));

  try {
    aliceSessionBuilder.process(bobPreKey);
    throw new AssertionError("Should fail with missing signed prekey!");
  } catch (InvalidKeyException e) {
    // Good!
    return;
  }
}
 
Example #24
Source File: SignalOmemoKeyUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public TreeMap<Integer, PreKeyRecord> generateOmemoPreKeys(int currentPreKeyId, int count) {
    List<PreKeyRecord> preKeyRecords = KeyHelper.generatePreKeys(currentPreKeyId, count);
    TreeMap<Integer, PreKeyRecord> map = new TreeMap<>();
    for (PreKeyRecord p : preKeyRecords) {
        map.put(p.getId(), p);
    }
    return map;
}
 
Example #25
Source File: SignalOmemoStoreConnector.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public PreKeyRecord loadPreKey(int i) throws InvalidKeyIdException {
    PreKeyRecord preKey;
    try {
        preKey = omemoStore.loadOmemoPreKey(getOurDevice(), i);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    if (preKey == null) {
        throw new InvalidKeyIdException("No PreKey with Id " + i + " found.");
    }

    return preKey;
}
 
Example #26
Source File: SignalOmemoStoreConnector.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public void storePreKey(int i, PreKeyRecord preKeyRecord) {
    try {
        omemoStore.storeOmemoPreKey(getOurDevice(), i, preKeyRecord);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #27
Source File: SignalOmemoRatchet.java    From Smack with Apache License 2.0 5 votes vote down vote up
SignalOmemoRatchet(OmemoManager omemoManager,
                          OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord,
                                         SessionRecord, SignalProtocolAddress, ECPublicKey, PreKeyBundle,
                                         SessionCipher> store) {
    super(omemoManager, store);
    this.storeConnector = new SignalOmemoStoreConnector(omemoManager, store);
}
 
Example #28
Source File: SignalOmemoService.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
protected SignalOmemoRatchet instantiateOmemoRatchet(
        OmemoManager manager,
        OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord, SessionRecord,
                SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher> store) {

    return new SignalOmemoRatchet(manager, getOmemoStoreBackend());
}
 
Example #29
Source File: DatabaseBackend.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public void storePreKey(Account account, PreKeyRecord record) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(SQLiteAxolotlStore.ID, record.getId());
    values.put(SQLiteAxolotlStore.KEY, Base64.encodeToString(record.serialize(), Base64.DEFAULT));
    values.put(SQLiteAxolotlStore.ACCOUNT, account.getUuid());
    db.insert(SQLiteAxolotlStore.PREKEY_TABLENAME, null, values);
}
 
Example #30
Source File: SQLiteAxolotlStore.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load a local PreKeyRecord.
 *
 * @param preKeyId the ID of the local PreKeyRecord.
 * @return the corresponding PreKeyRecord.
 * @throws InvalidKeyIdException when there is no corresponding PreKeyRecord.
 */
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
	PreKeyRecord record = mXmppConnectionService.databaseBackend.loadPreKey(account, preKeyId);
	if (record == null) {
		throw new InvalidKeyIdException("No such PreKeyRecord: " + preKeyId);
	}
	return record;
}