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);
}
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);
}
}
Aggregations