There is a big difference between the tomcat8.5 version and the tomcat8.0, and the way HTTPS is configured in the default server.xml is also changed:
<connector port= "8443" protocol= "Org.apache.coyote.http11.Http11NioProtocol" sslenabled= "true" secure= "true" uriencoding= "UTF-8" usebodyencodingforuri= "true" > <sslhostconfig certificateverification= "optional" > <certificate certificatekeystorefile= "${catalina.home}/bin/mykey.jks" certificatekeystorepassword= " MyPassword "/> </SSLHostConfig></Connector>
However, when it was started, it reported a null pointer error:
02-dec-2016 17:49:02.885warning [main] org.apache.tomcat.util.net.openssl.OpenSSLContext.init Error initializing SSL context Java.lang.NullPointerException at Org.apache.tomcat.util.net.openssl.OpenSSLContext.init (Opensslcontext.java: 281) at Org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext (Abstractjsseendpoint.java:101) at ORG.APACHE.TOMCAT.UTIL.NET.ABSTRACTJSSEENDPOINT.INITIALISESSL (Abstractjsseendpoint.java:81) at Org.apache.tomcat.util.net.NioEndpoint.bind (Nioendpoint.java:245) at Org.apache.tomcat.util.net.AbstractEndpoint.init (Abstractendpoint.java:875) at Org.apache.tomcat.util.net.AbstractJsseEndpoint.init (Abstractjsseendpoint.java:213) at Org.apache.coyote.AbstractProtocol.init (Abstractprotocol.java:558) at Org.apache.coyote.http11.AbstractHttp11Protocol.init (Abstracthttp11protocol.java:65) at Org.apache.catalina.connector.Connector.initInternal (Connector.java:968) at Org.apache.catalina.util.LifecycleBase.init (Lifecyclebase.java:107) at Org.apache.catalina.core.StandardService.initInternal (Standardservice.java:549) at Org.apache.catalina.util.LifecycleBase.init (Lifecyclebase.java:107) at Org.apache.catalina.core.StandardServer.initInternal (Standardserver.java:875) at Org.apache.catalina.util.LifecycleBase.init (Lifecyclebase.java:107) at Org.apache.catalina.startup.Catalina.load (Catalina.java:30S) at Org.apache.catalina.startup.Catalina.load (Catalina.java:629) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java:62) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (Method.java:498) at Org.apache.catalina.startup.Bootstrap.load (Bootstrap.java:311) at Org.apache.catalina.startup.Bootstrap.main (Bootstrap.java:494)
Chayuan code finds that aliases are required in the tomcat8.5 code, and if not configured, "Tomcat" is used as an alias by default. Obviously, our certificate alias will not be Tomcat.
We can use the following command to view the alias of the certificate:
Keytool-list -v-keystore xxxx.keystore-storepass Password
Like what:
D:\tomcat\tomcat858s\bin>keytool-list-v-keystore Mykey.jks-storepass MyPassword
KeyStore Type: JKs keystore provider: Sun your keystore contains1aliases for each entry:1Date Created: .-3-TenEntry Type: Privatekeyentry certificate chain length:3Certificate [1]: Owner: CN=*.guyezhai.com, O=xxxxxxxxxxxxxxxxxx, l=, st=, Beijing, c=cn published by: CN=wosign Class3OV Server CA G2, o=wosign ca Limited, c=CN serial Number: 567ab6b63782bdb9e44eba04dc27efe8 validity start Date: Thu MarTen -: +: -Cst ., due date: Fri MarTen -: +: -Cst .Certificate thumbprint: MD5: the: the: 7c:5a:4f:d8:5f:c7:d1:a2: in: -: c5:4a:ee:a3 sha1:f7: -: a7:4a: $:D d:b9:5f:Wuyi:Panax Notoginseng: the: -: .: c9:3e: in: 3d:a7:3d:e2 SHA256: -: +: E0: -: 7c:bd:ba: to: E8: the: -: -: 8e:4d:2a:2b:5c:a7: -:D 0:f0:7a: the: B6:d7:9d:b0:d7: -: $: BA: +Signature Algorithm Name: Sha256withrsa version:3...
As you can see, the alias for this certificate is "1" and we can configure the alias in Server.xml:
<connector port= "8443" protocol= "Org.apache.coyote.http11.Http11NioProtocol" sslenabled= "true" secure= "true" uriencoding= "UTF-8" usebodyencodingforuri= "true" > <sslhostconfig certificateverification= "optional" > <certificate certificatekeystorefile= "${catalina.home}/bin/mykey.jks" certificatekeystorepassword= " MyPassword "certificatekeyalias=" 1 "/> </SSLHostConfig></Connector>
Add certificatekeyalias= "1"
Then start Tomcat again, and the null pointer error disappears.
Tomcat8.5 Configuring HTTPS Boot report null pointer error