Search in sources :

Example 1 with InvalidTCTokenElement

use of org.openecard.binding.tctoken.ex.InvalidTCTokenElement 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);
    }
}
Also used : IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) TlsServerCertificate(org.openecard.bouncycastle.tls.TlsServerCertificate) UserCancellationException(org.openecard.binding.tctoken.ex.UserCancellationException) InvalidTCTokenElement(org.openecard.binding.tctoken.ex.InvalidTCTokenElement) InvalidAddressException(org.openecard.binding.tctoken.ex.InvalidAddressException) Pair(org.openecard.common.util.Pair)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 InvalidAddressException (org.openecard.binding.tctoken.ex.InvalidAddressException)1 InvalidTCTokenElement (org.openecard.binding.tctoken.ex.InvalidTCTokenElement)1 UserCancellationException (org.openecard.binding.tctoken.ex.UserCancellationException)1 TlsServerCertificate (org.openecard.bouncycastle.tls.TlsServerCertificate)1 Pair (org.openecard.common.util.Pair)1