JAVA SSL: how to get client certificate information

1.1k views Asked by At

I have an SSL-enabled tcp server that can listen to multiple rsyslog clients. Each client has its own certificate that is added in the server's truststore. This setup is working fine. TThe question is whether there is a way to get the client certificate information like CN, location etc. after the socket accepts connection?

Below is the code sample of simple tcp server.

SSLServerSocketFactory sf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
ServerSocket ss = sf.createServerSocket(514);
while(true){
    SSLSocket s = (SSL)ss.accept();        
    // here I need to get client certificate information

}
1

There are 1 answers

0
user207421 On

You need to configure the SSLServerSocket to need or want client authentication, depending on which of those applies. Then you can get the peer certificates out of the SSLSocket's SSLSession, if they were sent.