org.whispersystems.libsignal.IdentityKeyPair Java Examples

The following examples show how to use org.whispersystems.libsignal.IdentityKeyPair. 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: RotateSignedPreKeyJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    Log.w(TAG, "Rotating signed prekey...");
    if (AMELogin.INSTANCE.isLogin()) {
        IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(accountContext);
        SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, accountContext, identityKey, false);

        if (!AmeLoginCore.INSTANCE.refreshSignedPreKey(accountContext, signedPreKeyRecord)) {
            throw new Exception("refreshSignedPreKey failed");
        }

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

        JobManager manager = AmeModuleCenter.INSTANCE.accountJobMgr(accountContext);
        if (manager != null) {
            manager.add(new CleanPreKeysJob(context, accountContext));
        }
    } else {
        ALog.w(TAG, "please login first");
    }
}
 
Example #2
Source File: SignalAccount.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
public static SignalAccount create(String dataPath, String username, IdentityKeyPair identityKey, int registrationId, ProfileKey profileKey) throws IOException {
    IOUtils.createPrivateDirectories(dataPath);
    String fileName = getFileName(dataPath, username);
    if (!new File(fileName).exists()) {
        IOUtils.createPrivateFile(fileName);
    }

    final Pair<FileChannel, FileLock> pair = openFileChannel(fileName);
    SignalAccount account = new SignalAccount(pair.first(), pair.second());

    account.username = username;
    account.profileKey = profileKey;
    account.signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
    account.groupStore = new JsonGroupStore();
    account.contactStore = new JsonContactsStore();
    account.recipientStore = new RecipientStore();
    account.registered = false;

    return account;
}
 
Example #3
Source File: SignalAccount.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
public static SignalAccount createLinkedAccount(String dataPath, String username, UUID uuid, String password, int deviceId, IdentityKeyPair identityKey, int registrationId, String signalingKey, ProfileKey profileKey) throws IOException {
    IOUtils.createPrivateDirectories(dataPath);
    String fileName = getFileName(dataPath, username);
    if (!new File(fileName).exists()) {
        IOUtils.createPrivateFile(fileName);
    }

    final Pair<FileChannel, FileLock> pair = openFileChannel(fileName);
    SignalAccount account = new SignalAccount(pair.first(), pair.second());

    account.username = username;
    account.uuid = uuid;
    account.password = password;
    account.profileKey = profileKey;
    account.deviceId = deviceId;
    account.signalingKey = signalingKey;
    account.signalProtocolStore = new JsonSignalProtocolStore(identityKey, registrationId);
    account.groupStore = new JsonGroupStore();
    account.contactStore = new JsonContactsStore();
    account.recipientStore = new RecipientStore();
    account.registered = true;
    account.isMultiDevice = true;

    return account;
}
 
Example #4
Source File: SessionBuilder.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initiate a new session by sending an initial KeyExchangeMessage to the recipient.
 *
 * @return the KeyExchangeMessage to deliver.
 */
public KeyExchangeMessage process() {
  synchronized (SessionCipher.SESSION_LOCK) {
    try {
      int             sequence         = KeyHelper.getRandomSequence(65534) + 1;
      int             flags            = KeyExchangeMessage.INITIATE_FLAG;
      ECKeyPair       baseKey          = Curve.generateKeyPair();
      ECKeyPair       ratchetKey       = Curve.generateKeyPair();
      IdentityKeyPair identityKey      = identityKeyStore.getIdentityKeyPair();
      byte[]          baseKeySignature = Curve.calculateSignature(identityKey.getPrivateKey(), baseKey.getPublicKey().serialize());
      SessionRecord   sessionRecord    = sessionStore.loadSession(remoteAddress);

      sessionRecord.getSessionState().setPendingKeyExchange(sequence, baseKey, ratchetKey, identityKey);
      sessionStore.storeSession(remoteAddress, sessionRecord);

      return new KeyExchangeMessage(CiphertextMessage.CURRENT_VERSION,
                                    sequence, flags, baseKey.getPublicKey(), baseKeySignature,
                                    ratchetKey.getPublicKey(), identityKey.getPublicKey());
    } catch (InvalidKeyException e) {
      throw new AssertionError(e);
    }
  }
}
 
Example #5
Source File: IdentityKeyUtil.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
public static IdentityKeyPair getIdentityKeyPair(Context context,
                                                 MasterSecret masterSecret,
                                                 int subscriptionId)
{
  if (!hasIdentityKey(context, subscriptionId))
    return null;

  try {
    MasterCipher masterCipher = new MasterCipher(masterSecret);
    IdentityKey  publicKey    = getIdentityKey(context, subscriptionId);
    ECPrivateKey privateKey   = masterCipher.decryptKey(Base64.decode(retrieve(context, getIdentityPrivateKeyDjbPref(subscriptionId))));

    return new IdentityKeyPair(publicKey, privateKey);
  } catch (IOException | InvalidKeyException e) {
    throw new AssertionError(e);
  }
}
 
Example #6
Source File: PreKeyUtil.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public static SignedPreKeyRecord generateSignedPreKey(Context context, AccountContext accountContext, IdentityKeyPair identityKeyPair, boolean active) {
    try {
        SignedPreKeyStore signedPreKeyStore = new TextSecurePreKeyStore(context, accountContext);
        int signedPreKeyId = getNextSignedPreKeyId(context, accountContext);
        ECKeyPair keyPair = Curve.generateKeyPair();
        byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
        SignedPreKeyRecord record = new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);

        signedPreKeyStore.storeSignedPreKey(signedPreKeyId, record);
        setNextSignedPreKeyId(context, accountContext,(signedPreKeyId + 1) % Medium.MAX_VALUE);

        if (active) {
            setActiveSignedPreKeyId(context, accountContext, signedPreKeyId);
        }

        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
 
Example #7
Source File: DeviceConsistencyMessage.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
public DeviceConsistencyMessage(DeviceConsistencyCommitment commitment, IdentityKeyPair identityKeyPair) {
  try {
    byte[] signatureBytes = Curve.calculateVrfSignature(identityKeyPair.getPrivateKey(), commitment.toByteArray());
    byte[] vrfOutputBytes = Curve.verifyVrfSignature(identityKeyPair.getPublicKey().getPublicKey(), commitment.toByteArray(), signatureBytes);

    this.generation = commitment.getGeneration();
    this.signature  = new DeviceConsistencySignature(signatureBytes, vrfOutputBytes);
    this.serialized = SignalProtos.DeviceConsistencyCodeMessage.newBuilder()
                                                                .setGeneration(commitment.getGeneration())
                                                                .setSignature(ByteString.copyFrom(signature.getSignature()))
                                                                .build()
                                                                .toByteArray();
  } catch (InvalidKeyException | VrfSignatureVerificationFailedException e) {
    throw new AssertionError(e);
  }
}
 
Example #8
Source File: IdentityKeyUtil.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public static void migrateIdentityKeys(@NonNull AccountContext accountContext,
                                       @NonNull MasterSecret masterSecret) {
    if (!hasIdentityKey(accountContext)) {
        if (hasLegacyIdentityKeys(accountContext)) {
            IdentityKeyPair legacyPair = getLegacyIdentityKeyPair(accountContext, masterSecret);

            save(accountContext, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(legacyPair.getPublicKey().serialize()));
            save(accountContext, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(legacyPair.getPrivateKey().serialize()));

            delete(accountContext, IDENTITY_PUBLIC_KEY_CIPHERTEXT_LEGACY_PREF);
            delete(accountContext, IDENTITY_PRIVATE_KEY_CIPHERTEXT_LEGACY_PREF);
        } else {
            generateIdentityKeys(accountContext);
        }
    }
}
 
Example #9
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
public void setPendingKeyExchange(int sequence,
                                  ECKeyPair ourBaseKey,
                                  ECKeyPair ourRatchetKey,
                                  IdentityKeyPair ourIdentityKey)
{
  PendingKeyExchange structure =
      PendingKeyExchange.newBuilder()
                        .setSequence(sequence)
                        .setLocalBaseKey(ByteString.copyFrom(ourBaseKey.getPublicKey().serialize()))
                        .setLocalBaseKeyPrivate(ByteString.copyFrom(ourBaseKey.getPrivateKey().serialize()))
                        .setLocalRatchetKey(ByteString.copyFrom(ourRatchetKey.getPublicKey().serialize()))
                        .setLocalRatchetKeyPrivate(ByteString.copyFrom(ourRatchetKey.getPrivateKey().serialize()))
                        .setLocalIdentityKey(ByteString.copyFrom(ourIdentityKey.getPublicKey().serialize()))
                        .setLocalIdentityKeyPrivate(ByteString.copyFrom(ourIdentityKey.getPrivateKey().serialize()))
                        .build();

  this.sessionStructure = this.sessionStructure.toBuilder()
                                               .setPendingKeyExchange(structure)
                                               .build();
}
 
Example #10
Source File: RotateSignedPreKeyJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws Exception {
  Log.i(TAG, "Rotating signed prekey...");

  SignalServiceAccountManager accountManager     = ApplicationDependencies.getSignalServiceAccountManager();
  IdentityKeyPair             identityKey        = IdentityKeyUtil.getIdentityKeyPair(context);
  SignedPreKeyRecord          signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);

  accountManager.setSignedPreKey(signedPreKeyRecord);

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

  ApplicationDependencies.getJobManager().add(new CleanPreKeysJob());
}
 
Example #11
Source File: BobSignalProtocolParameters.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
BobSignalProtocolParameters(IdentityKeyPair ourIdentityKey, ECKeyPair ourSignedPreKey,
                            ECKeyPair ourRatchetKey, Optional<ECKeyPair> ourOneTimePreKey,
                            IdentityKey theirIdentityKey, ECPublicKey theirBaseKey)
{
  this.ourIdentityKey   = ourIdentityKey;
  this.ourSignedPreKey  = ourSignedPreKey;
  this.ourRatchetKey    = ourRatchetKey;
  this.ourOneTimePreKey = ourOneTimePreKey;
  this.theirIdentityKey = theirIdentityKey;
  this.theirBaseKey     = theirBaseKey;

  if (ourIdentityKey == null || ourSignedPreKey == null || ourRatchetKey == null ||
      ourOneTimePreKey == null || theirIdentityKey == null || theirBaseKey == null)
  {
    throw new IllegalArgumentException("Null value!");
  }
}
 
Example #12
Source File: CreateSignedPreKeyJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws IOException {
  if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
    Log.w(TAG, "Signed prekey already registered...");
    return;
  }

  if (!TextSecurePreferences.isPushRegistered(context)) {
    Log.w(TAG, "Not yet registered...");
    return;
  }

  SignalServiceAccountManager accountManager     = ApplicationDependencies.getSignalServiceAccountManager();
  IdentityKeyPair             identityKeyPair    = IdentityKeyUtil.getIdentityKeyPair(context);
  SignedPreKeyRecord          signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKeyPair, true);

  accountManager.setSignedPreKey(signedPreKeyRecord);
  TextSecurePreferences.setSignedPreKeyRegistered(context, true);
}
 
Example #13
Source File: AliceSignalProtocolParameters.java    From libsignal-protocol-java with GNU General Public License v3.0 6 votes vote down vote up
private AliceSignalProtocolParameters(IdentityKeyPair ourIdentityKey, ECKeyPair ourBaseKey,
                                      IdentityKey theirIdentityKey, ECPublicKey theirSignedPreKey,
                                      ECPublicKey theirRatchetKey, Optional<ECPublicKey> theirOneTimePreKey)
{
  this.ourIdentityKey     = ourIdentityKey;
  this.ourBaseKey         = ourBaseKey;
  this.theirIdentityKey   = theirIdentityKey;
  this.theirSignedPreKey  = theirSignedPreKey;
  this.theirRatchetKey    = theirRatchetKey;
  this.theirOneTimePreKey = theirOneTimePreKey;

  if (ourIdentityKey == null || ourBaseKey == null || theirIdentityKey == null ||
      theirSignedPreKey == null || theirRatchetKey == null || theirOneTimePreKey == null)
  {
    throw new IllegalArgumentException("Null values!");
  }
}
 
Example #14
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private void addDevice(String deviceIdentifier, ECPublicKey deviceKey) throws IOException, InvalidKeyException {
    IdentityKeyPair identityKeyPair = getIdentityKeyPair();
    String verificationCode = accountManager.getNewDeviceVerificationCode();

    accountManager.addDevice(deviceIdentifier, deviceKey, identityKeyPair, Optional.of(account.getProfileKey().serialize()), verificationCode);
    account.setMultiDevice(true);
    account.save();
}
 
Example #15
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
private SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair) {
    try {
        ECKeyPair keyPair = Curve.generateKeyPair();
        byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
        SignedPreKeyRecord record = new SignedPreKeyRecord(account.getNextSignedPreKeyId(), System.currentTimeMillis(), keyPair, signature);

        account.addSignedPreKey(record);
        account.save();

        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
 
Example #16
Source File: IdentityKeyUtil.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private static IdentityKeyPair getLegacyIdentityKeyPair(@NonNull AccountContext accountContext,
                                                        @NonNull MasterSecret masterSecret) {
    try {
        MasterCipher masterCipher = new MasterCipher(masterSecret);
        byte[] publicKeyBytes = Base64.decode(retrieve(accountContext, IDENTITY_PUBLIC_KEY_CIPHERTEXT_LEGACY_PREF));
        IdentityKey identityKey = new IdentityKey(publicKeyBytes, 0);
        ECPrivateKey privateKey = masterCipher.decryptKey(Base64.decode(retrieve(accountContext, IDENTITY_PRIVATE_KEY_CIPHERTEXT_LEGACY_PREF)));

        return new IdentityKeyPair(identityKey, privateKey);
    } catch (IOException | InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
 
Example #17
Source File: SignalServiceAccountManager.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public void addDevice(String deviceIdentifier,
                      ECPublicKey deviceKey,
                      IdentityKeyPair identityKeyPair,
                      Optional<byte[]> profileKey,
                      String code)
    throws InvalidKeyException, IOException
{
  ProvisioningCipher       cipher  = new ProvisioningCipher(deviceKey);
  ProvisionMessage.Builder message = ProvisionMessage.newBuilder()
                                                     .setIdentityKeyPublic(ByteString.copyFrom(identityKeyPair.getPublicKey().serialize()))
                                                     .setIdentityKeyPrivate(ByteString.copyFrom(identityKeyPair.getPrivateKey().serialize()))
                                                     .setProvisioningCode(code)
                                                     .setProvisioningVersion(ProvisioningVersion.CURRENT_VALUE);
  if (userE164 != null) {
    message.setNumber(userE164);
  }

  if (userUuid != null) {
    message.setUuid(userUuid.toString());
  }

  if (profileKey.isPresent()) {
    message.setProfileKey(ByteString.copyFrom(profileKey.get()));
  }

  byte[] ciphertext = cipher.encrypt(message.build());
  this.pushServiceSocket.sendProvisioningMessage(deviceIdentifier, ciphertext);
}
 
Example #18
Source File: SignalBot.java    From signal-bot with GNU General Public License v3.0 5 votes vote down vote up
public void listen() throws IOException, InvalidKeyException {
    String username = prefs.get("LOCAL_USERNAME", null);
    String password = prefs.get("LOCAL_PASSWORD", null);
    logger.info("Generating keys for " + username + "...");
    IdentityKeyPair identityKeyPair = KeyHelper.generateIdentityKeyPair();
    int registrationId = prefs.getInt("REGISTRATION_ID", -1);
    this.protocolStore = new InMemorySignalProtocolStore(identityKeyPair, registrationId);
    accountManager = new SignalServiceAccountManager(config, username, password, USER_AGENT);
    refreshPreKeys(identityKeyPair);
    logger.info("Starting message listener...");
    messageRetrieverThread.start();
    // TODO refresh keys job
}
 
Example #19
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 #20
Source File: SQLiteAxolotlStore.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the local client's identity key pair.
 *
 * @return The local client's persistent identity key pair.
 */
@Override
public IdentityKeyPair getIdentityKeyPair() {
	if (identityKeyPair == null) {
		identityKeyPair = loadIdentityKeyPair();
	}
	return identityKeyPair;
}
 
Example #21
Source File: IdentityKeyUtil.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static @NonNull
IdentityKeyPair getIdentityKeyPair(@NonNull AccountContext accountContext) {
    if (!hasIdentityKey(accountContext)) {
        throw new IllegalStateException("There isn't one!");
    }

    try {
        IdentityKey publicKey = getIdentityKey(accountContext);
        ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(retrieve(accountContext, IDENTITY_PRIVATE_KEY_PREF)));

        return new IdentityKeyPair(publicKey, privateKey);
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
Example #22
Source File: IdentityKeyUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static @NonNull IdentityKeyPair getIdentityKeyPair(@NonNull Context context) {
  if (!hasIdentityKey(context)) throw new AssertionError("There isn't one!");

  try {
    IdentityKey  publicKey  = getIdentityKey(context);
    ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_PREF)));

    return new IdentityKeyPair(publicKey, privateKey);
  } catch (IOException e) {
    throw new AssertionError(e);
  }
}
 
Example #23
Source File: SQLiteAxolotlStore.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private IdentityKeyPair loadIdentityKeyPair() {
    synchronized (mXmppConnectionService) {
        IdentityKeyPair ownKey = mXmppConnectionService.databaseBackend.loadOwnIdentityKeyPair(account);

        if (ownKey != null) {
            return ownKey;
        } else {
            Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Could not retrieve own IdentityKeyPair");
            ownKey = generateIdentityKeyPair();
            mXmppConnectionService.databaseBackend.storeOwnIdentityKeyPair(account, ownKey);
        }
        return ownKey;
    }
}
 
Example #24
Source File: SQLiteAxolotlStore.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the local client's identity key pair.
 *
 * @return The local client's persistent identity key pair.
 */
@Override
public IdentityKeyPair getIdentityKeyPair() {
    if (identityKeyPair == null) {
        identityKeyPair = loadIdentityKeyPair();
    }
    return identityKeyPair;
}
 
Example #25
Source File: SessionState.java    From libsignal-protocol-java with GNU General Public License v3.0 5 votes vote down vote up
public IdentityKeyPair getPendingKeyExchangeIdentityKey() throws InvalidKeyException {
  IdentityKey publicKey = new IdentityKey(sessionStructure.getPendingKeyExchange()
                                                          .getLocalIdentityKey().toByteArray(), 0);

  ECPrivateKey privateKey = Curve.decodePrivatePoint(sessionStructure.getPendingKeyExchange()
                                                                     .getLocalIdentityKeyPrivate()
                                                                     .toByteArray());

  return new IdentityKeyPair(publicKey, privateKey);
}
 
Example #26
Source File: LegacySignalOmemoKeyUtilTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Test
public void generateOmemoSignedPreKeyTest() {
    IdentityKeyPair ikp = keyUtil.generateOmemoIdentityKeyPair();
    try {
        SignedPreKeyRecord spk = keyUtil.generateOmemoSignedPreKey(ikp, 1);
        assertNotNull("SignedPreKey must not be null.", spk);
        assertEquals("SignedPreKeyId must match.", 1, spk.getId());
        assertEquals("singedPreKeyId must match here also.", 1, keyUtil.signedPreKeyIdFromKey(spk));
    } catch (CorruptedOmemoKeyException e) {
        fail("Caught an exception while generating signedPreKey (" + e + "): " + e.getMessage());
    }
}
 
Example #27
Source File: SQLiteAxolotlStore.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private IdentityKeyPair loadIdentityKeyPair() {
	synchronized (mXmppConnectionService) {
		IdentityKeyPair ownKey = mXmppConnectionService.databaseBackend.loadOwnIdentityKeyPair(account);

		if (ownKey != null) {
			return ownKey;
		} else {
			Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Could not retrieve own IdentityKeyPair");
			ownKey = generateIdentityKeyPair();
			mXmppConnectionService.databaseBackend.storeOwnIdentityKeyPair(account, ownKey);
		}
		return ownKey;
	}
}
 
Example #28
Source File: SignalOmemoKeyUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public IdentityKeyPair identityKeyPairFromBytes(byte[] data) throws CorruptedOmemoKeyException {
    if (data == null) return null;
    try {
        return new IdentityKeyPair(data);
    } catch (InvalidKeyException e) {
        throw new CorruptedOmemoKeyException(e);
    }
}
 
Example #29
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 #30
Source File: SignalOmemoStoreConnector.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public IdentityKeyPair getIdentityKeyPair() {
    try {
        return omemoStore.loadOmemoIdentityKeyPair(getOurDevice());
    } catch (CorruptedOmemoKeyException | IOException e) {
        LOGGER.log(Level.SEVERE, "IdentityKeyPair seems to be invalid.", e);
        return null;
    }
}