Is there a way to get the SSL certificate of the authenticated server using Apache HttpClient after the request – just the counterpart to request.getAttribute(“javax.servlet.request.X509Certificate”) on the server side?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ok this is a bit meta in some respects and I’m hopefully doing this in a fashion that will work with any connection manager. I’m assuming you’re running on the latest HttpClient (4.2)
So, what you will have to do is add an HttpResponseInterceptor to the client.
Once that is done, any request made through this client will check to see if the connection is marked as ‘secure’ and then attempt to get the peer certificates.
In this example, I’m just putting in the entire array of certificates that were associated with the peer connection.
At this point, to execute you will do something similar to the following:
Hopefully that will get what you need – if anyone has suggestions beyond this they’d be appreciated.
EDIT This can also be done as a HttpRequestInterceptor and have the same effect as the connection is already established.