简体   繁体   English

未设置getAttribute(“javax.servlet.request.X509Certificate”)(Spring,CXF,Jetty,JAX-RSv1.1)

[英]getAttribute(“javax.servlet.request.X509Certificate”) not set (Spring,CXF,Jetty,JAX-RSv1.1)

My client implements Two-Way SSL in the following way: 我的客户端通过以下方式实现双向SSL:

private final static String KEYSTORE = "/security/client.jks";
    private final static String KEYSTORE_PASSWORD = "secret";
    private final static String KEYSTORE_TYPE = "JKS";
    private final static String TRUSTSTORE = "/security/certificates.jks";
    private final static String TRUSTSTORE_PASSWORD = "secret";
    private final static String TRUSTSTORE_TYPE = "JKS";
    ...
    KeyStore keystore = KeyStore.getInstance(KEYSTORE_TYPE);
    FileInputStream keystoreInput = new FileInputStream(new File(KEYSTORE));
    keystore.load(keystoreInput, KEYSTORE_PASSWORD.toCharArray());
    KeyStore truststore = KeyStore.getInstance(TRUSTSTORE_TYPE);
    FileInputStream truststoreIs = new FileInputStream(new File(TRUSTSTORE));
    truststore.load(truststoreIs, TRUSTSTORE_PASSWORD.toCharArray());
    SSLSocketFactory socketFactory = new SSLSocketFactory(keystore, KEYSTORE_PASSWORD, truststore);
    Scheme scheme = new Scheme("https", 8543, socketFactory);
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(scheme);
    ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
    httpclient = new DefaultHttpClient(ccm);
    HttpResponse response = null;
    HttpGet httpget = new HttpGet("https://mylocalhost.com:8543/test");
    response = httpclient.execute(httpget);
    ...

And I try to retrieve the X.509 certificate on the server's side from the client via javax.servlet.http.HttpServletRequest.getAttribute("javax.servlet.request.X509Certificate") as it is decribed here: http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getAttribute%28java.lang.String%29 . 我尝试通过javax.servlet.http.HttpServletRequest.getAttribute(“javax.servlet.request.X509Certificate”)从客户端检索服务器端的X.509证书,如下所述: http:// tomcat。 apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getAttribute%28java.lang.String%29

I get the HttpServletRequest on the server's side via: 我通过以下方式在服务器端获得HttpServletRequest:
HttpServletRequest servletRequest = (HttpServletRequest) msg.get("HTTP.REQUEST"); HttpServletRequest servletRequest =(HttpServletRequest)msg.get(“HTTP.REQUEST”); via the handleMessage(Message msg) method of my interceptor class which extends AbstractPhaseInterceptor<Message>. 通过我的拦截器类的handleMessage(Message msg)方法,它扩展了AbstractPhaseInterceptor <Message>。 I have to use JAX-RS 1.1.1 on the server's side because of some Maven dependencies which I am not allowed to change and so I cannot use ContainerRequestFilter (supported from JAX-RS 2.0 on). 我必须在服务器端使用JAX-RS 1.1.1,因为我不允许更改一些Maven依赖项,所以我不能使用ContainerRequestFilter(从JAX-RS 2.0支持)。

My problem is that getAttribute("javax.servlet.request.X509Certificate") on the server's side returns null all the time. 我的问题是服务器端的getAttribute(“javax.servlet.request.X509Certificate”)一直返回null。 If I verify the traffic between server and client, I can see that the certificate from the server is sent to the client, that handshake works. 如果我验证服务器和客户端之间的流量,我可以看到来自服务器的证书被发送到客户端,该握手有效。 But I cannot see that the client certificate is sent to the server and I think it is the reason why getAttribute("javax.servlet.request.X509Certificate") returns null . 但我看不到客户端证书被发送到服务器,我认为这是getAttribute("javax.servlet.request.X509Certificate")返回null Does someone know how I can solve that problem? 有人知道如何解决这个问题吗? I tried some other implementations on the client's side already, but with no change. 我已经在客户端尝试了其他一些实现,但没有任何改变。

What am I doing wrong? 我究竟做错了什么? Many thanks in advance! 提前谢谢了!

Additional information: I have seen on the server's side that javax.servlet.request.ssl_session_id, javax.servlet.request.key_size and javax.servlet.request.cipher_suite are set, but the key javax.servlet.request.X509Certificate is not set. 附加信息:我在服务器端看到设置了javax.servlet.request.ssl_session_id,javax.servlet.request.key_size和javax.servlet.request.cipher_suite,但未设置密钥javax.servlet.request.X509Certificate 。 I'm using Jetty Server 8.1.15, Apache CXF 2.7.x and JAX-RS 1.1.1. 我正在使用Jetty Server 8.1.15,Apache CXF 2.7.x和JAX-RS 1.1.1。 I tried with Jetty configuration via http://cxf.apache.org/docs/jetty-configuration.html and http://cxf.apache.org/docs/secure-jax-rs-services.html#SecureJAX-RSServices-Configuringendpoints , the attribute still isn't set. 我通过http://cxf.apache.org/docs/jetty-configuration.htmlhttp://cxf.apache.org/docs/secure-jax-rs-services.html#SecureJAX-RSServices-尝试使用Jetty配置 - Configuringendpoints ,该属性仍未设置。

Problem is solved. 问题解决了。 It wasn't a problem in the code, it was a certificate problem only. 这不是代码中的问题,只是证书问题。 My problem was that I was a beginner regarding X509 certificates as well, it was a handshake problem between server and client. 我的问题是我是X509证书的初学者,这是服务器和客户端之间的握手问题。 In this case, only the SSL/Handshake debug helped me. 在这种情况下,只有SSL / Handshake调试帮助了我。 The debug log told that the server only accepted client certificates from a specific CA, the server told the client the required CA in a certificate request during the ServerHello message. 调试日志告知服务器仅接受来自特定CA的客户端证书,服务器在ServerHello消息期间告知客户端证书请求中所需的CA. Since the Client didn't have a certificate from that CA, it didn't send something and the connection between client and server was closed then, with the result that javax.servlet.request.X509Certificate was not set. 由于客户端没有来自该CA的证书,因此它没有发送内容,并且客户端和服务器之间的连接已关闭,结果是未设置javax.servlet.request.X509Certificate。

For all others who might join the same problem sometime (which seems to be a common SSL configuration problem regarding to IBM as it is mentioned in the first link below), the following sources helped me a lot: 对于可能在某个时间加入同一问题的所有其他人(这似乎是关于IBM的常见SSL配置问题,如下面的第一个链接中所述),以下来源对我有很大帮助:
- http://www-01.ibm.com/support/docview.wss?uid=swg27038122&aid=1 (pages 16 and 17) - http://www-01.ibm.com/support/docview.wss?uid=swg27038122&aid=1 (第16和17页)
- http://java.dzone.com/articles/how-analyze-java-ssl-errors (shows as the handshake should look) - http://java.dzone.com/articles/how-analyze-java-ssl-errors (显示握手应该看起来)
- need help Debugging SSL handshake in tomcat (shows how to debug ssl errors in Java) - 需要帮助在tomcat中调试SSL握手 (演示如何在Java中调试ssl错误)
- https://thomas-leister.de/internet/eigene-openssl-certificate-authority-ca-erstellen-und-zertifikate-signieren/ (in German, but maybe you can find an English equivalent) - https://thomas-leister.de/internet/eigene-openssl-certificate-authority-ca-erstellen-und-zertifikate-signieren/ (德语,但也许你可以找到一个等同的英语)
- https://access.redhat.com/site/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Web_Services_Security_Guide/files/i382674.html (continuation of the German article) - https://access.redhat.com/site/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Web_Services_Security_Guide/files/i382674.html (继续德文文章)
- http://www.webfarmr.eu/2010/04/import-pkcs12-private-keys-into-jks-keystores-using-java-keytool/ (how to create keystore and truststore) - http://www.webfarmr.eu/2010/04/import-pkcs12-private-keys-into-jks-keystores-using-java-keytool/ (如何创建密钥库和信任库)

After creating an own CA, a server and client certificate and after creating the keystore and truststore for both, the attribute was set now: 创建自己的CA,服务器和客户端证书后,在为两者创建密钥库和信任库之后,该属性现在已设置:
- Here15_1: javax.servlet.request.X509Certificate - Here15_1:javax.servlet.request.X509Certificate
- Here16_2: class [Ljava.security.cert.X509Certificate; - Here16_2:class [Ljava.security.cert.X509Certificate;
- Here16_3: [Ljava.security.cert.X509Certificate;@43b8f002 - Here16_3:[Ljava.security.cert.X509Certificate; @ 43b8f002
The server code is able to extract the client certificate information now, too. 服务器代码现在也能够提取客户端证书信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Request.getAttribute(“javax.servlet.request.X509Certificate”)返回Null - Request.getAttribute(“javax.servlet.request.X509Certificate”) Returns Null “ javax.servlet.request.X509Certificate”请求属性未返回CA证书 - “javax.servlet.request.X509Certificate” request attribute does not return CA certs 带有Apache mod_proxy_wstunnel的Websocket到带有javax.servlet.request.X509的tomcat - Websocket with apache mod_proxy_wstunnel to tomcat with javax.servlet.request.X509Certificate 证书请求到X.509 - Certificate request to X.509 javax.servlet.ServletContext set / getAttribute是否安全? - Is javax.servlet.ServletContext set/getAttribute thread safe? javax.security.cert.X509Certificate vs java.security.cert.X509Certificate? - javax.security.cert.X509Certificate vs java.security.cert.X509Certificate? javax.security.cert.X509Certificate与java.security.cert.X509Certificate之间不兼容 - Incompatibility between javax.security.cert.X509Certificate and java.security.cert.X509Certificate 具有X.509证书的Spring Security - Spring Security With X.509 Certificate 如何在Spring Boot下运行的REST控制器中获取与HTTPS请求相关的SSL证书(X.509)? - How to get SSL certificate (X.509) relevant to HTTPS request in REST controller running under Spring boot? X509证书共享的标准(java servlet) - Standard for X509 certificate sharing (java servlet)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM