今天在校内尝试从git.bistu.edu.cn克隆代码,使用https协议时候发现clone失败,于是开始实验,使用curl连接cas.bistu.edu.cn、x.bistu.edu.cn、chat.bistu.edu.cn、community.bistu.edu.cn、site.bistu.edu.cn
发现只有cas和site正常,其他的都报错了,但是浏览器访问并未发现错误。
联想之前ZFZ的safari访问git报错而我电脑的浏览器却没事,瞬间意识到之前配置的HTTPS可能很多都有问题。
经过一翻折腾,发现之前的补链不全导致有些浏览器无法识别完整的信任链,最终通过补链解决。
当Apache、IIS、Nginx都不报错之后,只有Tomcat还有问题。
Tomcat之前的jks使用的是http://www.agentbob.info/agentbob/79-AB.html这篇文章的工具生成的,说明这个工具有问题。
继续搜索发现可以使用
openssl s_client -msg -connect cas.bistu.edu.cn:8443
这个命令来调试详细的ssl连接过程
和正常的过程对比发现Tomcat的信任链依然不一样。遂放弃这个工具。
最终在文末的文章中找到了解决方案。
废话说完了,下面是完整操作记录。
—————————————————————–
拿到手的有bistu.crt证书一张、bistu.key私钥一个。
实际需要开启HTTPS的服务器若干,服务器种类为Tomcat、Nginx、Apache、IIS。
到证书签发机构官网下载root根证书和中间证书,在windows上另存为Base64PEM格式
分别为root.crt和intermediate.crt
拷贝到Linux下开始制作
| 0 1 2 3 |     cat bistu.crt >> bistu.chained.crt     cat intermediate.crt >> bistu.chained.crt     cat root.crt >> bistu.chained.crt | 
补链后证书为bistu.chained.crt
| 0 1 2 3 4 |     cat intermediate.crt >> combined.crt     cat root.crt >> combined.crt     openssl pkcs12 -export -in bistu.crt -inkey bistu.key -out bistu.p12 -name tomcat -CAfile combined.crt -caname root -chain     keytool -importkeystore -srckeystore bistu.p12 -srcstoretype pkcs12 -destkeystore bistu.jks -deststoretype jks | 
生成bistu.jks为tomcat所需格式
openssl pkcs12 -export -out bistu.pfx -inkey bistu.key -in bistu.crt
生成bistu.pfx为IIS所需格式
至此所有文件如下
1.bistu.crt              #原始证书
2.bistu.key            #私钥
3.root.crt               #根证书
4.intermediate.crt   #中间证书
5.bistu.chained.crt  #补链后证书
6.combined.crt       #中间链+根证书
7.bistu.p12            #p12格式的证书库
8.bistu.jks             #jks格式的证书库
9.bistu.pfx             #pfx格式的证书库
Apache需要的:1、2、5
Nginx需要的:2、5
Tomcat需要的:8
IIS需要的:2、9
配置示例
Apache
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |     <VirtualHost *:80>     	ServerAdmin webmaster@localhost     	ServerName example.bistu.edu.cn     	DocumentRoot /var/www/html     	ErrorLog ${APACHE_LOG_DIR}/error.log     	CustomLog ${APACHE_LOG_DIR}/access.log combined       RewriteEngine on       RewriteCond %{SERVER_NAME}=example.bistu.edu.cn       RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,QSA,R=permanent]     </VirtualHost>     <IfModule mod_ssl.c>     	<VirtualHost *:443>     		ServerAdmin webmaster@localhost     		ServerName example.bistu.edu.cn     		DocumentRoot /var/lib/tomcat8/webapps/ROOT     		ErrorLog ${APACHE_LOG_DIR}/ssl_error.log     		CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined     		SSLEngine on        		SSLCertificateFile  /path/to/bistu.crt       		SSLCertificateKeyFile /path/to/bistu.key     		SSLCertificateChainFile /path/to/bistu.chained.crt     		<FilesMatch "\.(cgi|shtml|phtml|php)$">     				SSLOptions +StdEnvVars     		</FilesMatch>     		<Directory /usr/lib/cgi-bin>     				SSLOptions +StdEnvVars     		</Directory>     	</VirtualHost>     </IfModule> | 
Nginx配置示例
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |     server {     	listen 80 default_server;     	server_name example.bistu.edu.cn;     	rewrite ^(.*)$  https://$host$1 permanent;     }     # HTTPS Server     server {         listen 443;         server_name example.bistu.edu.cn;         error_log /path/to/ssl.access.log;         ssl on;         ssl_certificate /path/to/bistu.crt;         ssl_certificate_key /path/to/bistu.key;         ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don’t use SSLv3 ref: POODLE         # other config     } | 
Tomcat配置示例
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |      <!--无代理-->         <Connector port="8080" protocol="HTTP/1.1"                    connectionTimeout="20000"                    URIEncoding="UTF-8"                    redirectPort="8443"/>         <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"                    maxThreads="150" scheme="https" secure="true"                    clientAuth="want" sslProtocol="TLS"                    keystoreFile="/path/to/bistu.jks"                     keystorePass="PASSWORD"                    />       <!--有代理-->         <Connector port="8080" protocol="HTTP/1.1"                    connectionTimeout="20000"                    URIEncoding="UTF-8"                    redirectPort="8443" proxyPort="80"/>         <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"                    maxThreads="150" scheme="https" secure="true"                    clientAuth="want" sslProtocol="TLS" proxyPort="443"                    keystoreFile="/path/to/bistu.jks"                     keystorePass="PASSWORD"                    /> | 
参考:
http://blog.csdn.net/jun55xiu/article/details/8980812
http://www.fourproc.com/2010/06/23/create-a-ssl-keystore-for-a-tomcat-server-using-openssl-.html
https://blogs.oracle.com/blogbypuneeth/entry/steps_to_create_a_jks