use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.
the class MobileCoinPublicAddressProfileUtilTest method can_not_verify_a_tampered_signature.
@Test
public void can_not_verify_a_tampered_signature() {
IdentityKeyPair identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair();
byte[] address = Util.getSecretBytes(100);
SignalServiceProtos.PaymentAddress signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair);
byte[] signature = signedPaymentAddress.getMobileCoinAddress().getSignature().toByteArray();
signature[0] = (byte) (signature[0] ^ 0x01);
SignalServiceProtos.PaymentAddress tamperedSignature = signedPaymentAddress.toBuilder().setMobileCoinAddress(signedPaymentAddress.getMobileCoinAddress().toBuilder().setSignature(ByteString.copyFrom(signature))).build();
assertThatThrownBy(() -> MobileCoinPublicAddressProfileUtil.verifyPaymentsAddress(tamperedSignature, identityKeyPair.getPublicKey())).isInstanceOf(PaymentsAddressException.class).hasMessage("Invalid MobileCoin address signature on payments address proto");
}
use of org.whispersystems.libsignal.IdentityKeyPair in project Smack by igniterealtime.
the class LegacySignalOmemoKeyUtilTest method generateOmemoSignedPreKeyTest.
@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());
}
}
use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.
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 WhisperSystems.
the class RefreshPreKeysJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws IOException {
if (!TextSecurePreferences.isPushRegistered(context))
return;
int availableKeys = accountManager.getPreKeysCount();
if (availableKeys >= PREKEY_MINIMUM && TextSecurePreferences.isSignedPreKeyRegistered(context)) {
Log.w(TAG, "Available keys sufficient: " + availableKeys);
return;
}
List<PreKeyRecord> preKeyRecords = PreKeyUtil.generatePreKeys(context);
PreKeyRecord lastResortKeyRecord = PreKeyUtil.generateLastResortKey(context);
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);
Log.w(TAG, "Registering new prekeys...");
accountManager.setPreKeys(identityKey.getPublicKey(), lastResortKeyRecord, signedPreKeyRecord, preKeyRecords);
PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
ApplicationContext.getInstance(context).getJobManager().add(new CleanPreKeysJob(context));
}
use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.
the class RotateSignedPreKeyJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws Exception {
Log.w(TAG, "Rotating signed prekey...");
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);
ApplicationContext.getInstance(context).getJobManager().add(new CleanPreKeysJob(context));
}
Aggregations