use of io.undertow.server.SSLSessionInfo in project undertow by undertow-io.
the class SSLHeaderHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
HeaderMap requestHeaders = exchange.getRequestHeaders();
final String sessionId = requestHeaders.getFirst(SSL_SESSION_ID);
final String cipher = requestHeaders.getFirst(SSL_CIPHER);
String clientCert = requestHeaders.getFirst(SSL_CLIENT_CERT);
String keySizeStr = requestHeaders.getFirst(SSL_CIPHER_USEKEYSIZE);
Integer keySize = null;
if (keySizeStr != null) {
try {
keySize = Integer.parseUnsignedInt(keySizeStr);
} catch (NumberFormatException e) {
UndertowLogger.REQUEST_LOGGER.debugf("Invalid SSL_CIPHER_USEKEYSIZE header %s", keySizeStr);
}
}
if (clientCert != null || sessionId != null || cipher != null) {
if (clientCert != null) {
if (clientCert.isEmpty() || clientCert.equals(NULL_VALUE)) {
// SSL is in place but client cert was not sent
clientCert = null;
} else if (clientCert.length() > 28 + 26) {
// the proxy client replaces \n with ' '
StringBuilder sb = new StringBuilder(clientCert.length() + 1);
sb.append(Certificates.BEGIN_CERT);
sb.append('\n');
// core certificate data
sb.append(clientCert.replace(' ', '\n').substring(28, clientCert.length() - 26));
sb.append('\n');
sb.append(Certificates.END_CERT);
clientCert = sb.toString();
}
}
try {
SSLSessionInfo info = new BasicSSLSessionInfo(sessionId, cipher, clientCert, keySize);
exchange.setRequestScheme(HTTPS);
exchange.getConnection().setSslSessionInfo(info);
exchange.addExchangeCompleteListener(CLEAR_SSL_LISTENER);
} catch (java.security.cert.CertificateException | CertificateException e) {
UndertowLogger.REQUEST_LOGGER.debugf(e, "Could not create certificate from header %s", clientCert);
}
}
next.handleRequest(exchange);
}
use of io.undertow.server.SSLSessionInfo in project cxf by apache.
the class UndertowHTTPHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange undertowExchange) throws Exception {
try {
// perform blocking operation on exchange
if (undertowExchange.isInIoThread()) {
undertowExchange.dispatch(this);
return;
}
HttpServletResponseImpl response = new HttpServletResponseImpl(undertowExchange, (ServletContextImpl) servletContext);
HttpServletRequestImpl request = new HttpServletRequestImpl(undertowExchange, (ServletContextImpl) servletContext);
if (request.getMethod().equals(METHOD_TRACE)) {
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
ServletRequestContext servletRequestContext = new ServletRequestContext(((ServletContextImpl) servletContext).getDeployment(), request, response, null);
undertowExchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext);
request.setAttribute("HTTP_HANDLER", this);
request.setAttribute("UNDERTOW_DESTINATION", undertowHTTPDestination);
SSLSessionInfo ssl = undertowExchange.getConnection().getSslSessionInfo();
if (ssl != null) {
request.setAttribute(SSL_CIPHER_SUITE_ATTRIBUTE, ssl.getCipherSuite());
try {
request.setAttribute(SSL_PEER_CERT_CHAIN_ATTRIBUTE, ssl.getPeerCertificates());
} catch (Exception e) {
// for some case won't have the peer certification
// do nothing
}
}
undertowHTTPDestination.doService(servletContext, request, response);
} catch (Throwable t) {
t.printStackTrace();
if (undertowExchange.isResponseChannelAvailable()) {
undertowExchange.setStatusCode(500);
final String errorPage = "<html><head><title>Error</title>" + "</head><body>Internal Error 500" + t.getMessage() + "</body></html>";
undertowExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, Integer.toString(errorPage.length()));
undertowExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html");
Sender sender = undertowExchange.getResponseSender();
sender.send(errorPage);
}
}
}
Aggregations