use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.
the class RegistrationService method handleCommonRegistration.
private void handleCommonRegistration(SignalServiceAccountManager accountManager, String number, String password, String signalingKey, boolean supportsGcm) throws IOException {
setState(new RegistrationState(RegistrationState.STATE_GENERATING_KEYS, number));
Recipient self = RecipientFactory.getRecipientsFromString(this, number, false).getPrimaryRecipient();
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(this);
List<PreKeyRecord> records = PreKeyUtil.generatePreKeys(this);
PreKeyRecord lastResort = PreKeyUtil.generateLastResortKey(this);
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateSignedPreKey(this, identityKey, true);
accountManager.setPreKeys(identityKey.getPublicKey(), lastResort, signedPreKey, records);
setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));
if (supportsGcm) {
String gcmRegistrationId = GoogleCloudMessaging.getInstance(this).register(GcmRefreshJob.REGISTRATION_ID);
accountManager.setGcmId(Optional.of(gcmRegistrationId));
TextSecurePreferences.setGcmRegistrationId(this, gcmRegistrationId);
TextSecurePreferences.setGcmDisabled(this, false);
} else {
TextSecurePreferences.setGcmDisabled(this, true);
}
TextSecurePreferences.setWebsocketRegistered(this, true);
DatabaseFactory.getIdentityDatabase(this).saveIdentity(self.getRecipientId(), identityKey.getPublicKey());
DirectoryHelper.refreshDirectory(this, accountManager, number);
DirectoryRefreshListener.schedule(this);
RotateSignedPreKeyListener.schedule(this);
}
use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by signalapp.
the class CreateSignedPreKeyJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) 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;
}
IdentityKeyPair identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context);
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKeyPair, true);
accountManager.setSignedPreKey(signedPreKeyRecord);
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
}
use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by signalapp.
the class IdentityKeyUtil method getLegacyIdentityKeyPair.
private static IdentityKeyPair getLegacyIdentityKeyPair(@NonNull Context context, @NonNull MasterSecret masterSecret) {
try {
MasterCipher masterCipher = new MasterCipher(masterSecret);
byte[] publicKeyBytes = Base64.decode(retrieve(context, IDENTITY_PUBLIC_KEY_CIPHERTEXT_LEGACY_PREF));
IdentityKey identityKey = new IdentityKey(publicKeyBytes, 0);
ECPrivateKey privateKey = masterCipher.decryptKey(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_CIPHERTEXT_LEGACY_PREF)));
return new IdentityKeyPair(identityKey, privateKey);
} catch (IOException | InvalidKeyException e) {
throw new AssertionError(e);
}
}
use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by signalapp.
the class IdentityKeyUtil method migrateIdentityKeys.
public static void migrateIdentityKeys(@NonNull Context context, @NonNull MasterSecret masterSecret) {
if (!hasIdentityKey(context)) {
if (hasLegacyIdentityKeys(context)) {
IdentityKeyPair legacyPair = getLegacyIdentityKeyPair(context, masterSecret);
save(context, IDENTITY_PUBLIC_KEY_PREF, Base64.encodeBytes(legacyPair.getPublicKey().serialize()));
save(context, IDENTITY_PRIVATE_KEY_PREF, Base64.encodeBytes(legacyPair.getPrivateKey().serialize()));
delete(context, IDENTITY_PUBLIC_KEY_CIPHERTEXT_LEGACY_PREF);
delete(context, IDENTITY_PRIVATE_KEY_CIPHERTEXT_LEGACY_PREF);
} else {
generateIdentityKeys(context);
}
}
}
use of org.whispersystems.libsignal.IdentityKeyPair in project toshi-android-client by toshiapp.
the class ProtocolStore method generateIdentityKeyPair.
private IdentityKeyPair generateIdentityKeyPair() {
final IdentityKeyPair ikp = KeyHelper.generateIdentityKeyPair();
SignalPreferences.setSerializedIdentityKeyPair(ikp.serialize());
return ikp;
}
Aggregations