Search in sources :

Example 1 with AuthCredentialResponse

use of org.signal.zkgroup.auth.AuthCredentialResponse in project Signal-Android by WhisperSystems.

the class GroupsV2AuthorizationSignalStoreCache method read.

@Override
@NonNull
public Map<Integer, AuthCredentialResponse> read() {
    byte[] credentialBlob = store.getBlob(KEY, null);
    if (credentialBlob == null) {
        Log.i(TAG, "No credentials responses are cached locally");
        return Collections.emptyMap();
    }
    try {
        TemporalAuthCredentialResponses temporalCredentials = TemporalAuthCredentialResponses.parseFrom(credentialBlob);
        HashMap<Integer, AuthCredentialResponse> result = new HashMap<>(temporalCredentials.getCredentialResponseCount());
        for (TemporalAuthCredentialResponse credential : temporalCredentials.getCredentialResponseList()) {
            result.put(credential.getDate(), new AuthCredentialResponse(credential.getAuthCredentialResponse().toByteArray()));
        }
        Log.i(TAG, String.format(Locale.US, "Loaded %d credentials from local storage", result.size()));
        return result;
    } catch (InvalidProtocolBufferException | InvalidInputException e) {
        throw new AssertionError(e);
    }
}
Also used : TemporalAuthCredentialResponse(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponse) InvalidInputException(org.signal.zkgroup.InvalidInputException) HashMap(java.util.HashMap) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TemporalAuthCredentialResponses(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponses) AuthCredentialResponse(org.signal.zkgroup.auth.AuthCredentialResponse) TemporalAuthCredentialResponse(org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponse) NonNull(androidx.annotation.NonNull)

Example 2 with AuthCredentialResponse

use of org.signal.zkgroup.auth.AuthCredentialResponse in project Signal-Android by WhisperSystems.

the class GroupsV2Authorization method getAuthorizationForToday.

public GroupsV2AuthorizationString getAuthorizationForToday(@NonNull ACI self, @NonNull GroupSecretParams groupSecretParams) throws IOException, VerificationFailedException {
    final int today = currentTimeDays();
    Map<Integer, AuthCredentialResponse> credentials = cache.read();
    try {
        return getAuthorization(self, groupSecretParams, credentials, today);
    } catch (NoCredentialForRedemptionTimeException e) {
        Log.i(TAG, "Auth out of date, will update auth and try again");
        cache.clear();
    } catch (VerificationFailedException e) {
        Log.w(TAG, "Verification failed, will update auth and try again", e);
        cache.clear();
    }
    Log.i(TAG, "Getting new auth credential responses");
    credentials = groupsV2Api.getCredentials(today);
    cache.write(credentials);
    try {
        return getAuthorization(self, groupSecretParams, credentials, today);
    } catch (NoCredentialForRedemptionTimeException e) {
        Log.w(TAG, "The credentials returned did not include the day requested");
        throw new IOException("Failed to get credentials");
    }
}
Also used : IOException(java.io.IOException) AuthCredentialResponse(org.signal.zkgroup.auth.AuthCredentialResponse) NoCredentialForRedemptionTimeException(org.whispersystems.signalservice.api.groupsv2.NoCredentialForRedemptionTimeException) VerificationFailedException(org.signal.zkgroup.VerificationFailedException)

Example 3 with AuthCredentialResponse

use of org.signal.zkgroup.auth.AuthCredentialResponse in project Signal-Android by WhisperSystems.

the class GroupsV2Api method parseCredentialResponse.

private static HashMap<Integer, AuthCredentialResponse> parseCredentialResponse(CredentialResponse credentialResponse) throws IOException {
    HashMap<Integer, AuthCredentialResponse> credentials = new HashMap<>();
    for (TemporalCredential credential : credentialResponse.getCredentials()) {
        AuthCredentialResponse authCredentialResponse;
        try {
            authCredentialResponse = new AuthCredentialResponse(credential.getCredential());
        } catch (InvalidInputException e) {
            throw new IOException(e);
        }
        credentials.put(credential.getRedemptionTime(), authCredentialResponse);
    }
    return credentials;
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) HashMap(java.util.HashMap) IOException(java.io.IOException) AuthCredentialResponse(org.signal.zkgroup.auth.AuthCredentialResponse)

Aggregations

AuthCredentialResponse (org.signal.zkgroup.auth.AuthCredentialResponse)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 InvalidInputException (org.signal.zkgroup.InvalidInputException)2 NonNull (androidx.annotation.NonNull)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 VerificationFailedException (org.signal.zkgroup.VerificationFailedException)1 TemporalAuthCredentialResponse (org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponse)1 TemporalAuthCredentialResponses (org.thoughtcrime.securesms.database.model.databaseprotos.TemporalAuthCredentialResponses)1 NoCredentialForRedemptionTimeException (org.whispersystems.signalservice.api.groupsv2.NoCredentialForRedemptionTimeException)1