Java Code Examples for org.whispersystems.libsignal.state.PreKeyRecord

The following examples show how to use org.whispersystems.libsignal.state.PreKeyRecord. These examples are extracted from open source projects. 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
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
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 Project: mollyim-android   Source File: PreKeyUtil.java    License: 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 Project: bcm-android   Source File: PreKeyUtil.java    License: 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 5
Source Project: signald   Source File: Manager.java    License: 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 6
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 7
Source Project: signal-cli   Source File: Manager.java    License: 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 8
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
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 10
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 Project: Conversations   Source File: IqGenerator.java    License: 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 12
public void insertPreKey(int keyId, PreKeyRecord record) {
  SQLiteDatabase database = databaseHelper.getWritableDatabase();

  ContentValues contentValues = new ContentValues();
  contentValues.put(KEY_ID, keyId);
  contentValues.put(PUBLIC_KEY, Base64.encodeBytes(record.getKeyPair().getPublicKey().serialize()));
  contentValues.put(PRIVATE_KEY, Base64.encodeBytes(record.getKeyPair().getPrivateKey().serialize()));

  database.replace(TABLE_NAME, null, contentValues);
}
 
Example 13
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
  synchronized (FILE_LOCK) {
    PreKeyRecord preKeyRecord = DatabaseFactory.getPreKeyDatabase(context).getPreKey(preKeyId);

    if (preKeyRecord == null) throw new InvalidKeyIdException("No such key: " + preKeyId);
    else                      return preKeyRecord;
  }
}
 
Example 14
@Override
public void onRun() throws IOException {
  if (!TextSecurePreferences.isPushRegistered(context)) {
    Log.w(TAG, "Not registered. Skipping.");
    return;
  }

  SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();

  int availableKeys = accountManager.getPreKeysCount();

  Log.i(TAG, "Available keys: " + availableKeys);

  if (availableKeys >= PREKEY_MINIMUM && TextSecurePreferences.isSignedPreKeyRegistered(context)) {
    Log.i(TAG, "Available keys sufficient.");
    SignalStore.setLastPrekeyRefreshTime(System.currentTimeMillis());
    return;
  }

  List<PreKeyRecord> preKeyRecords       = PreKeyUtil.generatePreKeys(context);
  IdentityKeyPair    identityKey         = IdentityKeyUtil.getIdentityKeyPair(context);
  SignedPreKeyRecord signedPreKeyRecord  = PreKeyUtil.generateSignedPreKey(context, identityKey, false);

  Log.i(TAG, "Registering new prekeys...");

  accountManager.setPreKeys(identityKey.getPublicKey(), signedPreKeyRecord, preKeyRecords);

  PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
  TextSecurePreferences.setSignedPreKeyRegistered(context, true);

  ApplicationDependencies.getJobManager().add(new CleanPreKeysJob());
  SignalStore.setLastPrekeyRefreshTime(System.currentTimeMillis());
  Log.i(TAG, "Successfully refreshed prekeys.");
}
 
Example 15
@Override
public void onRun(MasterSecret masterSecret) throws IOException {

    int availableKeys = AmeLoginCore.INSTANCE.getAvailablePreKeys(accountContext);
    if (availableKeys < 0) {
        throw new IOException("fetch prekey params failed");
    }

    if (availableKeys >= PREKEY_MINIMUM && accountContext.isSignedPreKeyRegistered()) {
        Log.w(TAG, "Available keys sufficient: " + availableKeys);
        return;
    }

    List<PreKeyRecord> preKeyRecords = PreKeyUtil.generatePreKeys(context, accountContext);
    IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(accountContext);
    SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, accountContext,identityKey, false);

    Log.w(TAG, "Registering new prekeys...");

    if (!AmeLoginCore.INSTANCE.refreshPreKeys(accountContext, identityKey.getPublicKey(), signedPreKeyRecord, preKeyRecords)) {
        throw new IOException("upload prekey failed");
    }

    PreKeyUtil.setActiveSignedPreKeyId(context, accountContext, signedPreKeyRecord.getId());
    accountContext.setSignedPreKeyRegistered(true);

    JobManager jobManager = AmeModuleCenter.INSTANCE.accountJobMgr(accountContext);
    if (jobManager != null) {
        jobManager.add(new CleanPreKeysJob(context, accountContext));
    }

}
 
Example 16
@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 17
@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 18
Source Project: signal-bot   Source File: SignalBot.java    License: 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 19
Source Project: signald   Source File: JsonPreKeyStore.java    License: 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 20
Source Project: signald   Source File: PreKeyStore.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
    if (!store.containsKey(preKeyId)) {
        throw new InvalidKeyIdException("No such prekeyrecord!");
    }

    try {
        return new PreKeyRecord(store.get(preKeyId));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
Example 21
Source Project: signal-cli   Source File: Manager.java    License: 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 22
Source Project: signal-cli   Source File: JsonPreKeyStore.java    License: 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
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 24
/**
 * 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 25
/**
 * 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 26
Source Project: Silence   Source File: SilencePreKeyStore.java    License: 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 27
Source Project: Silence   Source File: SilencePreKeyStore.java    License: 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 28
@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 29
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 30
Source Project: Smack   Source File: SignalOmemoKeyUtil.java    License: 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;
}