解决tomcat6.0.33 配置SSL时报“No Certificate file specified or invalid file format”异常

配置tomcat的SSL双向握手中,由于6.0.33版本中默认启用了APR(APR是通过JNI访问的可移植库,可以提高Tomcat的性能和伸缩性),所以采用传统的配置方式(如下)会报异常;

传统的SSL配置:

Xml代码 收藏代码
  1. <Connectorport="443"protocol="HTTP/1.1"SSLEnabled="true"
  2. maxThreads="150"scheme="https"secure="true"
  3. clientAuth="true"sslProtocol="TLS"
  4. keystoreFile="conf/keystore/test.jks"keystorePass="111111"
  5. truststoreFile="conf/keystore/test.jks"truststorePass="111111"

异常如下:

Java代码 收藏代码
  1. 2011-10-279:26:03org.apache.coyote.http11.Http11AprProtocolinit
  2. 严重:Errorinitializingendpoint
  3. java.lang.Exception:NoCertificatefilespecifiedorinvalidfileformat
  4. atorg.apache.tomcat.jni.SSLContext.setCertificate(NativeMethod)
  5. atorg.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:733)
  6. atorg.apache.coyote.http11.Http11AprProtocol.init(Http11AprProtocol.java:107)
  7. atorg.apache.catalina.connector.Connector.initialize(Connector.java:1022)
  8. atorg.apache.catalina.core.StandardService.initialize(StandardService.java:703)
  9. atorg.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
  10. atorg.apache.catalina.startup.Catalina.load(Catalina.java:538)
  11. atorg.apache.catalina.startup.Catalina.load(Catalina.java:562)
  12. atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
  13. atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  14. atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  15. atjava.lang.reflect.Method.invoke(Method.java:585)
  16. atorg.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
  17. atorg.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
  18. 2011-10-279:26:03org.apache.catalina.core.StandardServiceinitialize
  19. 严重:Failedtoinitializeconnector[Connector[HTTP/1.1-443]]
  20. LifecycleException:Protocolhandlerinitializationfailed:java.lang.Exception:NoCertificatefilespecifiedorinvalidfileformat
  21. atorg.apache.catalina.connector.Connector.initialize(Connector.java:1024)
  22. atorg.apache.catalina.core.StandardService.initialize(StandardService.java:703)
  23. atorg.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
  24. atorg.apache.catalina.startup.Catalina.load(Catalina.java:538)
  25. atorg.apache.catalina.startup.Catalina.load(Catalina.java:562)
  26. atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
  27. atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  28. atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  29. atjava.lang.reflect.Method.invoke(Method.java:585)
  30. atorg.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
  31. atorg.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

解决办法是采用下面的配置:

Xml代码 收藏代码
  1. <Connectorport="443"protocol="org.apache.coyote.http11.Http11Protocol"SSLEnabled="true"
  2. maxThreads="150"scheme="https"secure="true"
  3. clientAuth="true"sslProtocol="TLS"
  4. keystoreFile="conf/keystore/testpsira.jks"keystorePass="111111"
  5. truststoreFile="conf/keystore/testpsira.jks"truststorePass="111111"

其实就是将protocol="HTTP/1.1"替换为protocol="org.apache.coyote.http11.Http11Protocol",问题得以解决;

APR给Tomcat的性能提升起到很大作用,建议配置APR方式。

题外话:

如果辨别Tomcat是否采用APR:

启动Tomcat时,如果采用APR,日志中会有如下信息:

Python代码 收藏代码
  1. 信息:APRcapabilities:IPv6[true],sendfile[true],acceptfilters[false],random[true].

如果没有采用APR,启动时则显示类似的信息:

Python代码 收藏代码
  1. 信息:TheAPRbasedApacheTomcatNativelibrarywhichallowsoptimalperformanceinproductionenvironmentswasnotfoundonthejava.library.path:....后面省略

你可能感兴趣的:(certificate)