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