Search in sources :

Example 26 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by signalapp.

the class PreKeyUtil method generateAndStoreSignedPreKey.

@NonNull
public static synchronized SignedPreKeyRecord generateAndStoreSignedPreKey(@NonNull SignalProtocolStore protocolStore, @NonNull PreKeyMetadataStore metadataStore, boolean setAsActive) {
    Log.i(TAG, "Generating signed prekeys...");
    try {
        int signedPreKeyId = metadataStore.getNextSignedPreKeyId();
        ECKeyPair keyPair = Curve.generateKeyPair();
        byte[] signature = Curve.calculateSignature(protocolStore.getIdentityKeyPair().getPrivateKey(), keyPair.getPublicKey().serialize());
        SignedPreKeyRecord record = new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);
        protocolStore.storeSignedPreKey(signedPreKeyId, record);
        metadataStore.setNextSignedPreKeyId((signedPreKeyId + 1) % Medium.MAX_VALUE);
        if (setAsActive) {
            metadataStore.setActiveSignedPreKeyId(signedPreKeyId);
        }
        return record;
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
Also used : ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) NonNull(androidx.annotation.NonNull)

Example 27 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by signalapp.

the class IdentityKeyUtil method generateIdentityKeyPair.

public static IdentityKeyPair generateIdentityKeyPair() {
    ECKeyPair djbKeyPair = Curve.generateKeyPair();
    IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
    ECPrivateKey djbPrivateKey = djbKeyPair.getPrivateKey();
    return new IdentityKeyPair(djbIdentityKey, djbPrivateKey);
}
Also used : ECPrivateKey(org.whispersystems.libsignal.ecc.ECPrivateKey) IdentityKey(org.whispersystems.libsignal.IdentityKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) IdentityKeyPair(org.whispersystems.libsignal.IdentityKeyPair)

Example 28 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by signalapp.

the class MasterSecretUtil method generateAsymmetricMasterSecret.

public static AsymmetricMasterSecret generateAsymmetricMasterSecret(Context context, MasterSecret masterSecret) {
    MasterCipher masterCipher = new MasterCipher(masterSecret);
    ECKeyPair keyPair = Curve.generateKeyPair();
    save(context, ASYMMETRIC_LOCAL_PUBLIC_DJB, keyPair.getPublicKey().serialize());
    save(context, ASYMMETRIC_LOCAL_PRIVATE_DJB, masterCipher.encryptKey(keyPair.getPrivateKey()));
    return new AsymmetricMasterSecret(keyPair.getPublicKey(), keyPair.getPrivateKey());
}
Also used : ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair)

Example 29 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by signalapp.

the class RemoteAttestationUtil method getAndVerifyRemoteAttestation.

public static RemoteAttestation getAndVerifyRemoteAttestation(PushServiceSocket socket, PushServiceSocket.ClientSet clientSet, KeyStore iasKeyStore, String enclaveName, String mrenclave, String authorization) throws IOException, Quote.InvalidQuoteFormatException, InvalidCiphertextException, UnauthenticatedQuoteException, SignatureException, InvalidKeyException {
    ECKeyPair keyPair = buildKeyPair();
    ResponsePair result = makeAttestationRequest(socket, clientSet, authorization, enclaveName, keyPair);
    RemoteAttestationResponse response = JsonUtil.fromJson(result.body, RemoteAttestationResponse.class);
    return validateAndBuildRemoteAttestation(response, result.cookies, iasKeyStore, keyPair, mrenclave);
}
Also used : MultiRemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.MultiRemoteAttestationResponse) RemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationResponse) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair)

Example 30 with ECKeyPair

use of org.whispersystems.libsignal.ecc.ECKeyPair in project Signal-Android by signalapp.

the class RemoteAttestationUtil method getAndVerifyMultiRemoteAttestation.

public static Map<String, RemoteAttestation> getAndVerifyMultiRemoteAttestation(PushServiceSocket socket, PushServiceSocket.ClientSet clientSet, KeyStore iasKeyStore, String enclaveName, String mrenclave, String authorization) throws IOException, Quote.InvalidQuoteFormatException, InvalidCiphertextException, UnauthenticatedQuoteException, SignatureException, InvalidKeyException {
    ECKeyPair keyPair = buildKeyPair();
    ResponsePair result = makeAttestationRequest(socket, clientSet, authorization, enclaveName, keyPair);
    MultiRemoteAttestationResponse response = JsonUtil.fromJson(result.body, MultiRemoteAttestationResponse.class);
    Map<String, RemoteAttestation> attestations = new HashMap<>();
    if (response.getAttestations().isEmpty() || response.getAttestations().size() > 3) {
        throw new MalformedResponseException("Incorrect number of attestations: " + response.getAttestations().size());
    }
    for (Map.Entry<String, RemoteAttestationResponse> entry : response.getAttestations().entrySet()) {
        attestations.put(entry.getKey(), validateAndBuildRemoteAttestation(entry.getValue(), result.cookies, iasKeyStore, keyPair, mrenclave));
    }
    return attestations;
}
Also used : RemoteAttestation(org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation) HashMap(java.util.HashMap) MultiRemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.MultiRemoteAttestationResponse) RemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationResponse) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException) MultiRemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.MultiRemoteAttestationResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)32 SignedPreKeyRecord (org.whispersystems.libsignal.state.SignedPreKeyRecord)14 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)10 PreKeyRecord (org.whispersystems.libsignal.state.PreKeyRecord)8 SignedPreKeyStore (org.whispersystems.libsignal.state.SignedPreKeyStore)8 ECPrivateKey (org.whispersystems.libsignal.ecc.ECPrivateKey)7 LinkedList (java.util.LinkedList)6 IdentityKey (org.whispersystems.libsignal.IdentityKey)6 TextSecurePreKeyStore (org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore)5 ECPublicKey (org.whispersystems.libsignal.ecc.ECPublicKey)5 PreKeyStore (org.whispersystems.libsignal.state.PreKeyStore)5 NonNull (androidx.annotation.NonNull)4 IdentityKeyPair (org.whispersystems.libsignal.IdentityKeyPair)4 MultiRemoteAttestationResponse (org.whispersystems.signalservice.internal.contacts.entities.MultiRemoteAttestationResponse)4 RemoteAttestationResponse (org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationResponse)4 Cursor (android.database.Cursor)3 SignalPreKeyStore (com.toshi.crypto.signal.store.SignalPreKeyStore)3 IOException (java.io.IOException)3 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)3 Nullable (android.support.annotation.Nullable)2