[英]Two-way (mutual) SSL with Glassfish3/4 or Tomcat 8 and self-signed certificates
我正在嘗試實現雙向(相互)SSL身份驗證,但我經常在Glassfish3 / 4和Tomcat 8服務器上獲得以下異常(stacktrace來自Tomcat 8):
10-Feb-2016 17:13:41.579 SEVERE [http-nio2-18443-exec-2] org.apache.tomcat.util.net.Nio2Endpoint$SocketProcessor.doRun Error running socket processor
java.lang.RuntimeException: Field length overflow, the field length (7189180) should be less than 65536
at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1373)
at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:529)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:807)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:775)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.apache.tomcat.util.net.SecureNio2Channel.handshakeUnwrap(SecureNio2Channel.java:394)
at org.apache.tomcat.util.net.SecureNio2Channel.handshakeInternal(SecureNio2Channel.java:267)
at org.apache.tomcat.util.net.SecureNio2Channel.handshake(SecureNio2Channel.java:204)
at org.apache.tomcat.util.net.Nio2Endpoint$SocketProcessor.doRun(Nio2Endpoint.java:1064)
at org.apache.tomcat.util.net.Nio2Endpoint$SocketProcessor.run(Nio2Endpoint.java:1046)
at org.apache.tomcat.util.net.Nio2Endpoint.processSocket0(Nio2Endpoint.java:598)
at org.apache.tomcat.util.net.Nio2Endpoint.processSocket(Nio2Endpoint.java:583)
at org.apache.tomcat.util.net.SecureNio2Channel$1.completed(SecureNio2Channel.java:83)
at org.apache.tomcat.util.net.SecureNio2Channel$1.completed(SecureNio2Channel.java:76)
at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)
at sun.nio.ch.Invoker$2.run(Invoker.java:218)
at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
經過長時間的搜索,我發現這個鏈接顯示了同樣的問題但是在JBoss上。 這真的與密鑰/信任庫中的條目大小/數量有關嗎? 我現在有存儲〜66.000證書,但作為發展的推移,我們期待更多的方式 (如,幾十萬)。
使用幾乎為空的密鑰庫(僅包含服務器和一個測試客戶端證書),使用curl
測試SSL連接是成功的...
UPDATE
好吧,我想我發現它確實與truststore有關。 以下是sun.security.ssl.HandshakeMessage.CertificateRequest
的代碼片段:
// put certificate_authorities
int len = 0;
for (int i = 0; i < authorities.length; i++) {
len += authorities[i].length();
}
output.putInt16(len);
異常是在putInt()
方法中觸發的,所以我假設我確實存儲了太多的證書。 我現在正在生成自簽名證書,因此我必須將每個生成的證書作為服務器上的CA來信任客戶端,這一定是問題所在。 現在的問題是,有沒有辦法從Java生成非自簽名的證書(例如,我可以使用glassfish的自簽名證書作為CA - 或者我可以)?
好的,我通過創建頒發者設置為服務器自己的證書(在Glassfish中,特別是別名為s1as
)創建證書並使用服務器的私鑰對其進行簽名。 現在我不必在服務器上存儲任何東西,因為它識別客戶端,因為它在其trustStore(本質上,它本身)中知道它們的發行者是CA.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.