use of org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException in project Signal-Android by WhisperSystems.
the class PushServiceSocket method makeServiceRequest.
private Response makeServiceRequest(String urlFragment, String method, RequestBody body, Map<String, String> headers, ResponseCodeHandler responseCodeHandler, Optional<UnidentifiedAccess> unidentifiedAccessKey, boolean doNotAddAuthenticationOrUnidentifiedAccessKey) throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException {
Response response = getServiceConnection(urlFragment, method, body, headers, unidentifiedAccessKey, doNotAddAuthenticationOrUnidentifiedAccessKey);
ResponseBody responseBody = response.body();
try {
responseCodeHandler.handle(response.code(), responseBody);
return validateServiceResponse(response);
} catch (NonSuccessfulResponseCodeException | PushNetworkException | MalformedResponseException e) {
if (responseBody != null) {
responseBody.close();
}
throw e;
}
}
use of org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException in project Signal-Android by WhisperSystems.
the class PushServiceSocket method submitBoostReceiptCredentials.
public ReceiptCredentialResponse submitBoostReceiptCredentials(String paymentIntentId, ReceiptCredentialRequest receiptCredentialRequest) throws IOException {
String payload = JsonUtil.toJson(new BoostReceiptCredentialRequestJson(paymentIntentId, receiptCredentialRequest));
String response = makeServiceRequestWithoutAuthentication(BOOST_RECEIPT_CREDENTIALS, "POST", payload, (code, body) -> {
if (code == 204)
throw new NonSuccessfulResponseCodeException(204);
});
ReceiptCredentialResponseJson responseJson = JsonUtil.fromJson(response, ReceiptCredentialResponseJson.class);
if (responseJson.getReceiptCredentialResponse() != null) {
return responseJson.getReceiptCredentialResponse();
} else {
throw new MalformedResponseException("Unable to parse response");
}
}
use of org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException in project Signal-Android by WhisperSystems.
the class PushServiceSocket method submitReceiptCredentials.
public ReceiptCredentialResponse submitReceiptCredentials(String subscriptionId, ReceiptCredentialRequest receiptCredentialRequest) throws IOException {
String payload = JsonUtil.toJson(new ReceiptCredentialRequestJson(receiptCredentialRequest));
String response = makeServiceRequestWithoutAuthentication(String.format(SUBSCRIPTION_RECEIPT_CREDENTIALS, subscriptionId), "POST", payload, (code, body) -> {
if (code == 204)
throw new NonSuccessfulResponseCodeException(204);
});
ReceiptCredentialResponseJson responseJson = JsonUtil.fromJson(response, ReceiptCredentialResponseJson.class);
if (responseJson.getReceiptCredentialResponse() != null) {
return responseJson.getReceiptCredentialResponse();
} else {
throw new MalformedResponseException("Unable to parse response");
}
}
use of org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException in project Signal-Android by WhisperSystems.
the class DefaultErrorMapper method parseError.
@Override
public Throwable parseError(int status, String body, Function<String, String> getHeader) {
if (customErrorMappers.containsKey(status)) {
try {
return customErrorMappers.get(status).parseError(status, body, getHeader);
} catch (MalformedResponseException e) {
return e;
}
}
switch(status) {
case 401:
case 403:
return new AuthorizationFailedException(status, "Authorization failed!");
case 402:
return new CaptchaRequiredException();
case 404:
return new NotFoundException("Not found");
case 409:
try {
return new MismatchedDevicesException(JsonUtil.fromJsonResponse(body, MismatchedDevices.class));
} catch (MalformedResponseException e) {
return e;
}
case 410:
try {
return new StaleDevicesException(JsonUtil.fromJsonResponse(body, StaleDevices.class));
} catch (MalformedResponseException e) {
return e;
}
case 411:
try {
return new DeviceLimitExceededException(JsonUtil.fromJsonResponse(body, DeviceLimit.class));
} catch (MalformedResponseException e) {
return e;
}
case 413:
return new RateLimitException("Rate limit exceeded: " + status);
case 417:
return new ExpectationFailedException();
case 423:
PushServiceSocket.RegistrationLockFailure accountLockFailure;
try {
accountLockFailure = JsonUtil.fromJsonResponse(body, PushServiceSocket.RegistrationLockFailure.class);
} catch (MalformedResponseException e) {
return e;
}
AuthCredentials credentials = accountLockFailure.backupCredentials;
String basicStorageCredentials = credentials != null ? credentials.asBasic() : null;
return new LockedException(accountLockFailure.length, accountLockFailure.timeRemaining, basicStorageCredentials);
case 428:
ProofRequiredResponse proofRequiredResponse;
try {
proofRequiredResponse = JsonUtil.fromJsonResponse(body, ProofRequiredResponse.class);
} catch (MalformedResponseException e) {
return e;
}
String retryAfterRaw = getHeader.apply("Retry-After");
long retryAfter = Util.parseInt(retryAfterRaw, -1);
return new ProofRequiredException(proofRequiredResponse, retryAfter);
case 499:
return new DeprecatedVersionException();
case 508:
return new ServerRejectedException();
}
if (status != 200 && status != 202 && status != 204) {
return new NonSuccessfulResponseCodeException(status, "Bad response: " + status);
}
return null;
}
use of org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException in project Signal-Android by WhisperSystems.
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;
}
Aggregations