Search in sources :

Example 1 with DiscoveryResponse

use of org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse 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

ByteString (com.google.protobuf.ByteString)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 InvalidCiphertextException (org.whispersystems.signalservice.api.crypto.InvalidCiphertextException)1 ACI (org.whispersystems.signalservice.api.push.ACI)1 RemoteAttestation (org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation)1 UnauthenticatedResponseException (org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException)1 DiscoveryRequest (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest)1 DiscoveryResponse (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse)1