-
Notifications
You must be signed in to change notification settings - Fork 2k
Issue #6067 - Add TrustManagerWrapper to SslContextFactory.Server #14248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
afarber
wants to merge
2
commits into
jetty:jetty-12.1.x
Choose a base branch
from
afarber:6067-access-invalid-certs
base: jetty-12.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
Contributor
|
@afarber can you make the image public? Seems private and I cannot access it to actually see the code. Thanks! |
Contributor
Contributor
Author
|
Hi @sbordet here my test file: TrustWrapperDemo.java import java.security.cert.*;
import javax.net.ssl.*;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.ssl.*;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.http.HttpHeader;
import java.nio.ByteBuffer;
public class TrustWrapperDemo {
public static void main(String[] args) throws Exception {
Server server = new Server();
SslContextFactory.Server ssl = new SslContextFactory.Server();
ssl.setKeyStorePath("jetty-core/jetty-client/src/test/resources/keystore.p12");
ssl.setKeyStorePassword("storepwd");
ssl.setNeedClientAuth(true);
ssl.setTrustAll(true);
ssl.setTrustManagerWrapper(delegate ->
new SslContextFactory.X509ExtendedTrustManagerWrapper(delegate) {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine)
throws CertificateException {
System.out.println("=== TrustManagerWrapper captured certificate chain ===");
System.out.println("Chain length: " + chain.length);
for (int i = 0; i < chain.length; i++) {
System.out.println("Certificate [" + i + "]:");
System.out.println("Subject: " + chain[i].getSubjectX500Principal());
System.out.println("Issuer: " + chain[i].getIssuerX500Principal());
System.out.println("Valid: " + chain[i].getNotBefore() + " to " + chain[i].getNotAfter());
try {
chain[i].checkValidity();
System.out.println("Status: VALID");
} catch (CertificateExpiredException e) {
System.out.println("Status: EXPIRED");
} catch (CertificateNotYetValidException e) {
System.out.println("Status: NOT YET VALID");
}
}
System.out.println("====================================================\n");
for (X509Certificate cert : chain) {
cert.checkValidity();
}
}
});
ServerConnector connector = new ServerConnector(server, ssl);
connector.setPort(8443);
server.addConnector(connector);
server.setHandler(new Handler.Abstract() {
@Override
public boolean handle(Request req, Response res, Callback cb) throws Exception {
res.setStatus(200);
res.getHeaders().put(HttpHeader.CONTENT_TYPE, "text/plain");
res.write(true, ByteBuffer.wrap("OK\n".getBytes()), cb);
return true;
}
});
server.start();
System.out.println("Server started on https://localhost:8443");
System.out.println("Waiting for client with certificate...");
System.out.println("\nTest with: curl -k --cert /tmp/expired.crt --key /tmp/expired.key https://localhost:8443/");
server.join();
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Fixes #6067
Add
setTrustManagerWrapper(UnaryOperator<X509ExtendedTrustManager>)toSslContextFactory.Serverto allow intercepting certificate validation during TLS handshake.This provides an API to access client certificates even when validation fails, without requiring subclassing.
getTrustManagerWrapper()/setTrustManagerWrapper()methodsnewX509ExtendedTrustManager()protected method for subclass customizationgetTrustManagers()to apply the wrapper