Search in sources :

Example 31 with ACI

use of org.whispersystems.signalservice.api.push.ACI in project Signal-Android by WhisperSystems.

the class SignalServiceAccountManager method addDevice.

public void addDevice(String deviceIdentifier, ECPublicKey deviceKey, IdentityKeyPair aciIdentityKeyPair, IdentityKeyPair pniIdentityKeyPair, ProfileKey profileKey, String code) throws InvalidKeyException, IOException {
    String e164 = credentials.getE164();
    ACI aci = credentials.getAci();
    PNI pni = credentials.getPni();
    Preconditions.checkArgument(e164 != null, "Missing e164!");
    Preconditions.checkArgument(aci != null, "Missing ACI!");
    Preconditions.checkArgument(pni != null, "Missing PNI!");
    PrimaryProvisioningCipher cipher = new PrimaryProvisioningCipher(deviceKey);
    ProvisionMessage.Builder message = ProvisionMessage.newBuilder().setAciIdentityKeyPublic(ByteString.copyFrom(aciIdentityKeyPair.getPublicKey().serialize())).setAciIdentityKeyPrivate(ByteString.copyFrom(aciIdentityKeyPair.getPrivateKey().serialize())).setPniIdentityKeyPublic(ByteString.copyFrom(pniIdentityKeyPair.getPublicKey().serialize())).setPniIdentityKeyPrivate(ByteString.copyFrom(pniIdentityKeyPair.getPrivateKey().serialize())).setAci(aci.toString()).setPni(pni.toString()).setNumber(e164).setProfileKey(ByteString.copyFrom(profileKey.serialize())).setProvisioningCode(code).setProvisioningVersion(ProvisioningVersion.CURRENT_VALUE);
    byte[] ciphertext = cipher.encrypt(message.build());
    this.pushServiceSocket.sendProvisioningMessage(deviceIdentifier, ciphertext);
}
Also used : ProvisionMessage(org.whispersystems.signalservice.internal.push.ProvisioningProtos.ProvisionMessage) PrimaryProvisioningCipher(org.whispersystems.signalservice.internal.crypto.PrimaryProvisioningCipher) ACI(org.whispersystems.signalservice.api.push.ACI) PNI(org.whispersystems.signalservice.api.push.PNI) ByteString(com.google.protobuf.ByteString)

Example 32 with ACI

use of org.whispersystems.signalservice.api.push.ACI in project Signal-Android by WhisperSystems.

the class SignalServiceAccountManager method getRegisteredUsers.

@SuppressWarnings("SameParameterValue")
public Map<String, ACI> getRegisteredUsers(KeyStore iasKeyStore, Set<String> e164numbers, String mrenclave) throws IOException, Quote.InvalidQuoteFormatException, UnauthenticatedQuoteException, SignatureException, UnauthenticatedResponseException, InvalidKeyException {
    if (e164numbers.isEmpty()) {
        return Collections.emptyMap();
    }
    try {
        String authorization = this.pushServiceSocket.getContactDiscoveryAuthorization();
        Map<String, RemoteAttestation> attestations = RemoteAttestationUtil.getAndVerifyMultiRemoteAttestation(pushServiceSocket, PushServiceSocket.ClientSet.ContactDiscovery, iasKeyStore, mrenclave, mrenclave, authorization);
        List<String> addressBook = new ArrayList<>(e164numbers.size());
        for (String e164number : e164numbers) {
            addressBook.add(e164number.substring(1));
        }
        List<String> cookies = attestations.values().iterator().next().getCookies();
        DiscoveryRequest request = ContactDiscoveryCipher.createDiscoveryRequest(addressBook, attestations);
        DiscoveryResponse response = this.pushServiceSocket.getContactDiscoveryRegisteredUsers(authorization, request, cookies, mrenclave);
        byte[] data = ContactDiscoveryCipher.getDiscoveryResponseData(response, attestations.values());
        HashMap<String, ACI> results = new HashMap<>(addressBook.size());
        DataInputStream uuidInputStream = new DataInputStream(new ByteArrayInputStream(data));
        for (String candidate : addressBook) {
            long candidateUuidHigh = uuidInputStream.readLong();
            long candidateUuidLow = uuidInputStream.readLong();
            if (candidateUuidHigh != 0 || candidateUuidLow != 0) {
                results.put('+' + candidate, ACI.from(new UUID(candidateUuidHigh, candidateUuidLow)));
            }
        }
        return results;
    } catch (InvalidCiphertextException e) {
        throw new UnauthenticatedResponseException(e);
    }
}
Also used : DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) HashMap(java.util.HashMap) ACI(org.whispersystems.signalservice.api.push.ACI) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) DataInputStream(java.io.DataInputStream) RemoteAttestation(org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation) ByteArrayInputStream(java.io.ByteArrayInputStream) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) DiscoveryRequest(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest) UUID(java.util.UUID)

Aggregations

ACI (org.whispersystems.signalservice.api.push.ACI)32 Test (org.junit.Test)13 IOException (java.io.IOException)7 WorkerThread (androidx.annotation.WorkerThread)6 HashMap (java.util.HashMap)5 NonNull (androidx.annotation.NonNull)4 ByteString (com.google.protobuf.ByteString)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 Map (java.util.Map)4 PNI (org.whispersystems.signalservice.api.push.PNI)4 ServiceResponse (org.whispersystems.signalservice.internal.ServiceResponse)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SignatureException (java.security.SignatureException)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 List (java.util.List)3 UUID (java.util.UUID)3 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)3 UnauthenticatedResponseException (org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException)3