Search in sources :

Example 36 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class ProfileUtil method getSelfPaymentsAddressProtobuf.

@Nullable
private static SignalServiceProtos.PaymentAddress getSelfPaymentsAddressProtobuf() {
    if (!SignalStore.paymentsValues().mobileCoinPaymentsEnabled()) {
        return null;
    } else {
        IdentityKeyPair identityKeyPair = SignalStore.account().getAciIdentityKey();
        MobileCoinPublicAddress publicAddress = ApplicationDependencies.getPayments().getWallet().getMobileCoinPublicAddress();
        return MobileCoinPublicAddressProfileUtil.signPaymentsAddress(publicAddress.serialize(), identityKeyPair);
    }
}
Also used : IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) MobileCoinPublicAddress(org.thoughtcrime.securesms.payments.MobileCoinPublicAddress) Nullable(androidx.annotation.Nullable)

Example 37 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class MobileCoinPublicAddressProfileUtilTest method can_not_verify_a_tampered_address.

@Test
public void can_not_verify_a_tampered_address() {
    IdentityKeyPair identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair();
    byte[] addressBytes = Util.getSecretBytes(100);
    SignalServiceProtos.PaymentAddress signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(addressBytes, identityKeyPair);
    byte[] address = signedPaymentAddress.getMobileCoinAddress().getAddress().toByteArray();
    address[0] = (byte) (address[0] ^ 0x01);
    SignalServiceProtos.PaymentAddress tamperedAddress = signedPaymentAddress.toBuilder().setMobileCoinAddress(signedPaymentAddress.getMobileCoinAddress().toBuilder().setAddress(ByteString.copyFrom(address))).build();
    assertThatThrownBy(() -> MobileCoinPublicAddressProfileUtil.verifyPaymentsAddress(tamperedAddress, identityKeyPair.getPublicKey())).isInstanceOf(PaymentsAddressException.class).hasMessage("Invalid MobileCoin address signature on payments address proto");
}
Also used : SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Test(org.junit.Test)

Example 38 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class MobileCoinPublicAddressProfileUtilTest method can_not_verify_a_missing_signature.

@Test
public void can_not_verify_a_missing_signature() {
    IdentityKeyPair identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair();
    byte[] address = Util.getSecretBytes(100);
    SignalServiceProtos.PaymentAddress signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair);
    SignalServiceProtos.PaymentAddress removedSignature = signedPaymentAddress.toBuilder().setMobileCoinAddress(signedPaymentAddress.getMobileCoinAddress().toBuilder().clearSignature()).build();
    assertThatThrownBy(() -> MobileCoinPublicAddressProfileUtil.verifyPaymentsAddress(removedSignature, identityKeyPair.getPublicKey())).isInstanceOf(PaymentsAddressException.class).hasMessage("Invalid MobileCoin address signature on payments address proto");
}
Also used : SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Test(org.junit.Test)

Example 39 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class MobileCoinPublicAddressProfileUtilTest method can_not_verify_an_address_with_the_wrong_key.

@Test
public void can_not_verify_an_address_with_the_wrong_key() {
    IdentityKeyPair identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair();
    IdentityKey wrongPublicKey = IdentityKeyUtil.generateIdentityKeyPair().getPublicKey();
    byte[] address = Util.getSecretBytes(100);
    SignalServiceProtos.PaymentAddress signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair);
    assertThatThrownBy(() -> MobileCoinPublicAddressProfileUtil.verifyPaymentsAddress(signedPaymentAddress, wrongPublicKey)).isInstanceOf(PaymentsAddressException.class).hasMessage("Invalid MobileCoin address signature on payments address proto");
}
Also used : SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) IdentityKey(org.whispersystems.libsignal.IdentityKey) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Test(org.junit.Test)

Example 40 with IdentityKeyPair

use of org.whispersystems.libsignal.IdentityKeyPair in project Signal-Android by WhisperSystems.

the class MobileCoinPublicAddressProfileUtilTest method can_not_verify_a_missing_address.

@Test
public void can_not_verify_a_missing_address() {
    IdentityKeyPair identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair();
    byte[] address = Util.getSecretBytes(100);
    SignalServiceProtos.PaymentAddress signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair);
    SignalServiceProtos.PaymentAddress removedAddress = signedPaymentAddress.toBuilder().setMobileCoinAddress(signedPaymentAddress.getMobileCoinAddress().toBuilder().clearAddress()).build();
    assertThatThrownBy(() -> MobileCoinPublicAddressProfileUtil.verifyPaymentsAddress(removedAddress, identityKeyPair.getPublicKey())).isInstanceOf(PaymentsAddressException.class).hasMessage("Invalid MobileCoin address signature on payments address proto");
}
Also used : SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair) Test(org.junit.Test)

Aggregations

IdentityKeyPair (org.whispersystems.libsignal.IdentityKeyPair)40 SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)12 Test (org.junit.Test)9 IdentityKey (org.whispersystems.libsignal.IdentityKey)9 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)8 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)7 IOException (java.io.IOException)6 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)6 ECPrivateKey (org.whispersystems.libsignal.ecc.ECPrivateKey)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)3 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)3 ContentValues (android.content.ContentValues)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 NonNull (android.support.annotation.NonNull)2 Account (de.pixart.messenger.entities.Account)2 Account (eu.siacs.conversations.entities.Account)2