Search in sources :

Example 1 with InvalidTCTokenException

use of org.openecard.binding.tctoken.ex.InvalidTCTokenException in project open-ecard by ecsec.

the class TCTokenContext method generateTCToken.

private static TCTokenContext generateTCToken(String data, ResourceContext base) throws InvalidTCTokenException, AuthServerException, InvalidRedirectUrlException, InvalidTCTokenElement, InvalidTCTokenUrlException, SecurityViolationException, UserCancellationException {
    // correct common TCToken shortcomings
    data = TCTokenHacks.fixPathSecurityParameters(data);
    LOG.debug("Cleaned up TCToken:\n{}", data);
    // Parse the TCToken
    TCTokenParser parser = new TCTokenParser();
    List<TCToken> tokens = parser.parse(data);
    if (tokens.isEmpty()) {
        throw new InvalidTCTokenException(NO_TCTOKEN_IN_DATA);
    }
    // Verify the TCToken
    TCToken token = tokens.get(0);
    TCTokenVerifier ver = new TCTokenVerifier(token, base);
    if (ver.isErrorToken()) {
        String minor = ResultMinor.CLIENT_ERROR;
        throw new AuthServerException(token.getComErrorAddressWithParams(minor), ESERVICE_ERROR);
    }
    DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    List<Pair<URL, TlsServerCertificate>> resultPoints = base.getCerts();
    // probably just for tests
    if (!resultPoints.isEmpty()) {
        Pair<URL, TlsServerCertificate> last = resultPoints.get(0);
        dynCtx.put(TR03112Keys.TCTOKEN_URL, last.p1);
    }
    ver.verifyUrlToken();
    return new TCTokenContext(token, base);
}
Also used : URL(java.net.URL) TlsServerCertificate(org.openecard.bouncycastle.tls.TlsServerCertificate) InvalidTCTokenException(org.openecard.binding.tctoken.ex.InvalidTCTokenException) AuthServerException(org.openecard.binding.tctoken.ex.AuthServerException) DynamicContext(org.openecard.common.DynamicContext) Pair(org.openecard.common.util.Pair)

Example 2 with InvalidTCTokenException

use of org.openecard.binding.tctoken.ex.InvalidTCTokenException in project open-ecard by ecsec.

the class TCTokenParser method parse.

/**
 * Parse TCTokens from given the input stream.
 *
 * @param inputStream Input stream
 * @return List of TCTokens
 * @throws InvalidTCTokenException Thrown in case the SAX parser had an error reading the stream.
 */
public List<TCToken> parse(@Nonnull InputStream inputStream) throws InvalidTCTokenException {
    try {
        // Parse TCTokens
        SAXParser saxParser = saxFactory.newSAXParser();
        LimitedInputStream stream = new LimitedInputStream(inputStream);
        saxParser.parse(stream, saxHandler);
        // Get TCTokens
        List<TCToken> tokens = saxHandler.getTCTokens();
        return tokens;
    } catch (ParserConfigurationException | SAXException | IOException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new InvalidTCTokenException(MALFORMED_TOKEN, ex);
    }
}
Also used : InvalidTCTokenException(org.openecard.binding.tctoken.ex.InvalidTCTokenException) LimitedInputStream(org.openecard.common.io.LimitedInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

InvalidTCTokenException (org.openecard.binding.tctoken.ex.InvalidTCTokenException)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 AuthServerException (org.openecard.binding.tctoken.ex.AuthServerException)1 TlsServerCertificate (org.openecard.bouncycastle.tls.TlsServerCertificate)1 DynamicContext (org.openecard.common.DynamicContext)1 LimitedInputStream (org.openecard.common.io.LimitedInputStream)1 Pair (org.openecard.common.util.Pair)1 SAXException (org.xml.sax.SAXException)1