Search in sources :

Example 6 with Pair

use of org.openecard.common.util.Pair 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

URL (java.net.URL)6 Pair (org.openecard.common.util.Pair)6 TlsServerCertificate (org.openecard.bouncycastle.tls.TlsServerCertificate)5 IOException (java.io.IOException)3 InvalidAddressException (org.openecard.binding.tctoken.ex.InvalidAddressException)3 DynamicContext (org.openecard.common.DynamicContext)3 URISyntaxException (java.net.URISyntaxException)2 SecurityViolationException (org.openecard.binding.tctoken.ex.SecurityViolationException)2 MalformedURLException (java.net.MalformedURLException)1 Socket (java.net.Socket)1 URI (java.net.URI)1 Header (org.openecard.apache.http.Header)1 HttpEntity (org.openecard.apache.http.HttpEntity)1 HttpException (org.openecard.apache.http.HttpException)1 HttpResponse (org.openecard.apache.http.HttpResponse)1 StatusLine (org.openecard.apache.http.StatusLine)1 BasicHttpEntityEnclosingRequest (org.openecard.apache.http.message.BasicHttpEntityEnclosingRequest)1 BasicHttpContext (org.openecard.apache.http.protocol.BasicHttpContext)1 HttpContext (org.openecard.apache.http.protocol.HttpContext)1 HttpRequestExecutor (org.openecard.apache.http.protocol.HttpRequestExecutor)1