5

How to receive a x509 certificate from client? I'm using Java's Spring-Boot-Framework with embedded tomcat. For protyping I configured this with Java SE:

HttpsExchange httpsExchange = (HttpsExchange) httpReq;

name = httpsExchange.getSSLSession().getPeerPrincipal().getName();

A user gave me a reference to do this here (down below)

@RequestMapping(value = "/grab")
public void grabCert(HttpServletRequest servletRequest) {
    Certificate[] certs = 
            (Certificate[]) servletRequest.getAttribute("javax.servlet.request.X509Certificate");
}

But I'm not able to get some certificate! Maybe because I'm using tomcat, and it is handling all SSL-Connections. So that no certificate is receiving my application. What I have to do, to get the clients certificate? The client certificate is used to get https connection. I need some information from the subject of the certificate. Thanks.

Community
  • 1
  • 1
MissBonbon
  • 141
  • 1
  • 4
  • 16
  • Does this answer your question? [How to get the certificate into the X509 filter (Spring Security)?](https://stackoverflow.com/questions/1102721/how-to-get-the-certificate-into-the-x509-filter-spring-security) – dur Jan 28 '23 at 12:14

2 Answers2

8

You have to get it from the HttpServletRequest.

You can check the answer to this question: How to get the certificate into the X509 filter (Spring Security)?:

No you can't get it that way. You need to grab it from the HttpServletRequest:

X509Certificate[] certs = (X509Certificate[])HttpServletRequest.getAttribute("javax.servlet.request.X509Certificate");

This was the post I was trying to point you to, written by Gandalf.

And this was the original question

Community
  • 1
  • 1
djointster
  • 346
  • 3
  • 12
1

When you upgrade to Spring Boot 3.x the servlet request attribute has been renamed to be consistent with the renamed javax to jakarta packages. So now it's:

request.getAttribute("jakarta.servlet.request.X509Certificate")
Andy Brown
  • 11,766
  • 2
  • 42
  • 61