Search in sources :

Example 16 with MalformedResponseException

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

the class RemoteAttestationUtil method makeAttestationRequest.

private static ResponsePair makeAttestationRequest(PushServiceSocket socket, PushServiceSocket.ClientSet clientSet, String authorization, String enclaveName, ECKeyPair keyPair) throws IOException {
    RemoteAttestationRequest attestationRequest = new RemoteAttestationRequest(keyPair.getPublicKey().getPublicKeyBytes());
    Response response = socket.makeRequest(clientSet, authorization, new LinkedList<String>(), "/v1/attestation/" + enclaveName, "PUT", JsonUtil.toJson(attestationRequest));
    ResponseBody body = response.body();
    if (body == null) {
        throw new MalformedResponseException("Empty response!");
    }
    return new ResponsePair(body.string(), parseCookies(response));
}
Also used : MultiRemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.MultiRemoteAttestationResponse) Response(okhttp3.Response) RemoteAttestationResponse(org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationResponse) RemoteAttestationRequest(org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationRequest) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException) ResponseBody(okhttp3.ResponseBody)

Example 17 with MalformedResponseException

use of org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException 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)

Example 18 with MalformedResponseException

use of org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException in project Signal-Android by signalapp.

the class PushServiceSocket method getGroupsV2GroupHistory.

public GroupHistory getGroupsV2GroupHistory(int fromVersion, GroupsV2AuthorizationString authorization, int highestKnownEpoch, boolean includeFirstState) throws IOException {
    Response response = makeStorageRequestResponse(authorization.toString(), String.format(Locale.US, GROUPSV2_GROUP_CHANGES, fromVersion, highestKnownEpoch, includeFirstState), "GET", null, GROUPS_V2_GET_LOGS_HANDLER);
    if (response.body() == null) {
        throw new PushNetworkException("No body!");
    }
    GroupChanges groupChanges;
    try (InputStream input = response.body().byteStream()) {
        groupChanges = GroupChanges.parseFrom(input);
    } catch (IOException e) {
        throw new PushNetworkException(e);
    }
    if (response.code() == 206) {
        String contentRangeHeader = response.header("Content-Range");
        Optional<ContentRange> contentRange = ContentRange.parse(contentRangeHeader);
        if (contentRange.isPresent()) {
            Log.i(TAG, "Additional logs for group: " + contentRangeHeader);
            return new GroupHistory(groupChanges, contentRange);
        } else {
            Log.w(TAG, "Unable to parse Content-Range header: " + contentRangeHeader);
            throw new MalformedResponseException("Unable to parse content range header on 206");
        }
    }
    return new GroupHistory(groupChanges, Optional.absent());
}
Also used : CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) Response(okhttp3.Response) KeyBackupResponse(org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse) ReceiptCredentialResponse(org.signal.zkgroup.receipts.ReceiptCredentialResponse) CredentialResponse(org.whispersystems.signalservice.api.groupsv2.CredentialResponse) StorageAuthResponse(org.whispersystems.signalservice.api.storage.StorageAuthResponse) VerifyDeviceResponse(org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse) DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) ProfileKeyCredentialResponse(org.signal.zkgroup.profiles.ProfileKeyCredentialResponse) TokenResponse(org.whispersystems.signalservice.internal.contacts.entities.TokenResponse) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) GroupChanges(org.signal.storageservice.protos.groups.GroupChanges) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Aggregations

MalformedResponseException (org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)18 GroupsV2AuthorizationString (org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString)10 NonSuccessfulResponseCodeException (org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException)8 IOException (java.io.IOException)6 Response (okhttp3.Response)6 ResponseBody (okhttp3.ResponseBody)4 ProfileKeyCredentialResponse (org.signal.zkgroup.profiles.ProfileKeyCredentialResponse)4 ReceiptCredentialResponse (org.signal.zkgroup.receipts.ReceiptCredentialResponse)4 CredentialResponse (org.whispersystems.signalservice.api.groupsv2.CredentialResponse)4 CallingResponse (org.whispersystems.signalservice.api.messages.calls.CallingResponse)4 VerifyDeviceResponse (org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse)4 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)4 StorageAuthResponse (org.whispersystems.signalservice.api.storage.StorageAuthResponse)4 DiscoveryResponse (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse)4 KeyBackupResponse (org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse)4 MultiRemoteAttestationResponse (org.whispersystems.signalservice.internal.contacts.entities.MultiRemoteAttestationResponse)4 RemoteAttestationResponse (org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationResponse)4 TokenResponse (org.whispersystems.signalservice.internal.contacts.entities.TokenResponse)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2