Java Code Examples for io.undertow.server.HttpServerExchange#getSslSessionInfo()

The following examples show how to use io.undertow.server.HttpServerExchange#getSslSessionInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSLInformationAssociationHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    ServletRequest request = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getServletRequest();
    SSLSessionInfo ssl = exchange.getSslSessionInfo();
    if (ssl != null) {
        String cipherSuite = ssl.getCipherSuite();
        request.setAttribute("javax.servlet.request.cipher_suite", cipherSuite);
        request.setAttribute("javax.servlet.request.key_size", getKeyLength(cipherSuite));
        request.setAttribute("javax.servlet.request.ssl_session_id", ssl.getSessionId());
        X509Certificate[] certs = getCerts(ssl);
        if (certs != null) {
            request.setAttribute("javax.servlet.request.X509Certificate", certs);
        }

    }
    next.handleRequest(exchange);
}
 
Example 2
Source File: SslSessionConfig.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void setSessionId(final HttpServerExchange exchange, final String sessionId) {
    UndertowLogger.SESSION_LOGGER.tracef("Setting SSL session id %s on %s", sessionId, exchange);
    SSLSessionInfo sslSession = exchange.getSslSessionInfo();
    if (sslSession == null) {
        if (fallbackSessionConfig != null) {
            fallbackSessionConfig.setSessionId(exchange, sessionId);
        }
    } else {
        Key key = new Key(sslSession.getSessionId());
        synchronized (this) {
            sessions.put(key, sessionId);
            reverse.put(sessionId, key);
        }
    }
}
 
Example 3
Source File: SslSessionConfig.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void clearSession(final HttpServerExchange exchange, final String sessionId) {
    UndertowLogger.SESSION_LOGGER.tracef("Clearing SSL session id %s on %s", sessionId, exchange);
    SSLSessionInfo sslSession = exchange.getSslSessionInfo();
    if (sslSession == null) {
        if (fallbackSessionConfig != null) {
            fallbackSessionConfig.clearSession(exchange, sessionId);
        }
    } else {
        synchronized (this) {
            Key sid = reverse.remove(sessionId);
            if (sid != null) {
                sessions.remove(sid);
            }
        }
    }
}
 
Example 4
Source File: SslSessionConfig.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public String findSessionId(final HttpServerExchange exchange) {
    SSLSessionInfo sslSession = exchange.getSslSessionInfo();
    if (sslSession == null) {
        if (fallbackSessionConfig != null) {
            return fallbackSessionConfig.findSessionId(exchange);
        }
    } else {
        synchronized (this) {
            String sessionId = sessions.get(new Key(sslSession.getSessionId()));
            if(sessionId != null) {
                UndertowLogger.SESSION_LOGGER.tracef("Found SSL session id %s on %s", sessionId, exchange);
            }
            return sessionId;
        }
    }
    return null;
}
 
Example 5
Source File: ClientCertAuthenticationMechanism.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public AuthenticationMechanismOutcome authenticate(final HttpServerExchange exchange, final SecurityContext securityContext) {
    SSLSessionInfo sslSession = exchange.getSslSessionInfo();
    if (sslSession != null) {
        try {
            Certificate[] clientCerts = getPeerCertificates(exchange, sslSession, securityContext);
            if (clientCerts[0] instanceof X509Certificate) {
                Credential credential = new X509CertificateCredential((X509Certificate) clientCerts[0]);

                IdentityManager idm = getIdentityManager(securityContext);
                Account account = idm.verify(credential);
                if (account != null) {
                    securityContext.authenticationComplete(account, name, false);
                    return AuthenticationMechanismOutcome.AUTHENTICATED;
                }
            }
        } catch (SSLPeerUnverifiedException e) {
            // No action - this mechanism can not attempt authentication without peer certificates so allow it to drop out
            // to NOT_ATTEMPTED.
        }
    }

    /*
     * For ClientCert we do not have a concept of a failed authentication, if the client did use a key then it was deemed
     * acceptable for the connection to be established, this mechanism then just 'attempts' to use it for authentication but
     * does not mandate success.
     */

    return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
 
Example 6
Source File: SslSessionIdAttribute.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public String readAttribute(HttpServerExchange exchange) {
    SSLSessionInfo ssl = exchange.getSslSessionInfo();
    if(ssl == null || ssl.getSessionId() == null) {
        return null;
    }
    return FlexBase64.encodeString(ssl.getSessionId(), false);
}
 
Example 7
Source File: SslCipherAttribute.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public String readAttribute(HttpServerExchange exchange) {
    SSLSessionInfo ssl = exchange.getSslSessionInfo();
    if(ssl == null) {
        return null;
    }
    return ssl.getCipherSuite();
}