I wrote a Web Service server using Sun Ws implementation and I used a HttpsServer for publication (TLS mutual authentication).
httpServer=HttpsServer.create(...);
ssl=SSLContext.getInstance("TLS");
...
ssl.init(keyFactory.getKeyManagers(),trustFactory.getTrustManagers(),new SecureRandom());
configurator=new HttpsConfigurator(ssl) {
public void configure (HttpsParameters params)
{
SSLContext context;
SSLParameters sslparams;
context=getSSLContext();
sslparams=context.getDefaultSSLParameters();
sslparams.setNeedClientAuth(true);
params.setSSLParameters(sslparams);
}
};
((HttpsServer)httpServer).setHttpsConfigurator(configurator);
...
endPoint=getSunWsProvider().createEndPoint(...);
httpContext=httpServer.createContext(...);
endPoint.publish(httpContext);
httpServer.start();
...
Everything works fine. When the implementation of the server side of the Web Service is executed by a client, I would like to know which client is executing the code (to manage rights). Knowing that each client gets its own certificate, how can I get the client certificate used for the TLS negociation before the Web Service call ? (I would prefer to find a solution based on the client certificate analysis instead of adding an identification information to each Web Service call).
Thank you for your help.
Create a client certificate request. After receiving the certificate, export it to a password-protected PKCS12 file and send the password and the file to the user. Make sure the file is securely sent.
Client Java Implementation First, we create an SSLSocket that establishes a connection with the server. In the background, the socket will set up the TLS connection establishment handshake. As part of this handshake, the client will verify the server's certificate and check that it's in the client truststore.
Using Client Certificates in Web API On the server side, you can get the client certificate by calling GetClientCertificate on the request message. The method returns null if there is no client certificate. Otherwise, it returns an X509Certificate2 instance.
in your handler you get not the HttpExchange
instance but the instance of its subclass HttpsExchange
that has the extra method:
abstract SSLSession getSSLSession();
Among many other things an SSLSession exposes peer identity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With