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);
}
}
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);
}
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());
}
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);
}
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;
}
Aggregations