Search in sources :

Example 1 with BasicSSLSessionInfo

use of io.undertow.server.BasicSSLSessionInfo 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);
}
Also used : HeaderMap(io.undertow.util.HeaderMap) BasicSSLSessionInfo(io.undertow.server.BasicSSLSessionInfo) SSLSessionInfo(io.undertow.server.SSLSessionInfo) BasicSSLSessionInfo(io.undertow.server.BasicSSLSessionInfo) CertificateException(javax.security.cert.CertificateException)

Example 2 with BasicSSLSessionInfo

use of io.undertow.server.BasicSSLSessionInfo in project undertow by undertow-io.

the class AjpRequestParseState method createSslSessionInfo.

BasicSSLSessionInfo createSslSessionInfo() {
    String sessionId = sslSessionId;
    String cypher = sslCipher;
    String cert = sslCert;
    Integer keySize = null;
    if (cert == null && sessionId == null) {
        return null;
    }
    if (sslKeySize != null) {
        try {
            keySize = Integer.parseUnsignedInt(sslKeySize);
        } catch (NumberFormatException e) {
            UndertowLogger.REQUEST_LOGGER.debugf("Invalid sslKeySize %s", sslKeySize);
        }
    }
    try {
        return new BasicSSLSessionInfo(sessionId, cypher, cert, keySize);
    } catch (CertificateException e) {
        return null;
    } catch (javax.security.cert.CertificateException e) {
        return null;
    }
}
Also used : BasicSSLSessionInfo(io.undertow.server.BasicSSLSessionInfo) CertificateException(java.security.cert.CertificateException) HttpString(io.undertow.util.HttpString)

Aggregations

BasicSSLSessionInfo (io.undertow.server.BasicSSLSessionInfo)2 SSLSessionInfo (io.undertow.server.SSLSessionInfo)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1 CertificateException (java.security.cert.CertificateException)1 CertificateException (javax.security.cert.CertificateException)1