use of org.openecard.bouncycastle.tls.TlsServerCertificate in project open-ecard by ecsec.
the class TCTokenVerifier method determineRefreshAddress.
/**
* Determines the refresh URL.
*
* @param ex The exception which caused the abort of the TCToken verification.
* @throws InvalidRedirectUrlException If the CommunicationErrorAddress cant be determined.
* @throws InvalidTCTokenElement If a determination of a refresh or CommunicationError address was successful.
* @throws UserCancellationException Thrown in case {@code ex} is an instance of {@link UserCancellationException}.
*/
private void determineRefreshAddress(ActivationError ex) throws InvalidRedirectUrlException, InvalidTCTokenElement, UserCancellationException {
if (token.getRefreshAddress() != null) {
try {
CertificateValidator validator = new RedirectCertificateValidator(true);
ResourceContext newResCtx = ResourceContext.getStream(new URL(token.getRefreshAddress()), validator);
newResCtx.closeStream();
List<Pair<URL, TlsServerCertificate>> resultPoints = newResCtx.getCerts();
Pair<URL, TlsServerCertificate> last = resultPoints.get(resultPoints.size() - 1);
URL resAddr = last.p1;
String refreshUrl = resAddr.toString();
if (ex instanceof UserCancellationException) {
UserCancellationException uex = (UserCancellationException) ex;
URI refreshUrlAsUrl = createUrlWithErrorParams(refreshUrl, ResultMinor.CANCELLATION_BY_USER, ex.getMessage());
throw new UserCancellationException(refreshUrlAsUrl.toString(), ex);
}
URI refreshUrlAsUrl = createUrlWithErrorParams(refreshUrl, ResultMinor.TRUSTED_CHANNEL_ESTABLISCHMENT_FAILED, ex.getMessage());
throw new InvalidTCTokenElement(refreshUrlAsUrl.toString(), ex);
} catch (IOException | ResourceException | InvalidAddressException | ValidationError | URISyntaxException ex1) {
String errorUrl = token.getComErrorAddressWithParams(ResultMinor.COMMUNICATION_ERROR);
throw new InvalidTCTokenElement(errorUrl, INVALID_REFRESH_ADDRESS, ex1);
}
} else {
String errorUrl = token.getComErrorAddressWithParams(ResultMinor.COMMUNICATION_ERROR);
throw new InvalidTCTokenElement(errorUrl, NO_REFRESH_ADDRESS);
}
}
Aggregations