Chinaunix首页 | 论坛 | 博客
  • 博客访问: 75133
  • 博文数量: 14
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 156
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-23 09:58
个人简介

Dev Ops, 我刚起步啊

文章分类

全部博文(14)

文章存档

2017年(2)

2016年(5)

2015年(7)

我的朋友

分类: 系统运维

2015-04-14 11:46:30

首先需要知道,这个过程并不复杂,但是确实比在nginx和apache中设置要复杂的多!

核心的任务是生成一个keystore,java需要从此keystore中获取证书和私钥的信息。
基于此,大致步骤如下:(参考自http://www.eclipse.org/jetty/documentation/9.2.6.v20141205/configuring-ssl.html)

1.you should get an certificated(public key)/private key
 如果没有,自己用keytool 生成一个测试一下,如果互联网上提供服务,则必须用从CA处购买的才可以。

2.import them into a keystore
  Note if your public key and private key are in separate files, you need use openssl to concat them  into one single file.
 The order of certificates must be from server to rootCA, as per RFC2246 section 7.4.2.
 
cat myserver-2014.crt intermediate-CA.crt root-cert.crt > cert-chain.txt

openssl pkcs12 -inkey thawte-dev-2014.key -in cert-chain.txt -export -out combined-dev-2014.pkcs12
[export password must be given- 密码最好和下面的步骤一致,可以省去很多麻烦]

then import 
keytool -importkeystore -srckeystore combined-dev-2014.pkcs12 -srcstoretype PKCS12 -destkeystore dev_keystore -srcstorepass changeit -deststorepass changeit
为了避免出现 java.security.UnrecoverableKeyException: Cannot recover key,索性就将两者密码设置为一样的。

3.setup jetty or tomcat
add this line into start.ini ,the keystore path is better to point to ${jetty.home}/dev_keystore 
etc/jetty-ssl.xml, 然后进行设置密码和路径.安全起见,密码用下面的命令进行一下处理。



obfuse passwd:
java -cp lib/jetty-http-7.6.16.v20140903.jar;lib/jetty-util-7.6.16.v20140903.jar org.eclipse.jetty.util.security.Password  userid changeit
将生成的密码字符串配置到jetty-ssl.xml中即可。
OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0
MD5:b91cd1a54781790beaa2baf741fa6789
CRYPT:us9J/seUyYoZs


另外,有时候在访问其他https地址时,系统会报异常PKIX path building failed,这是由于对方所用的证书,本地java环境中还没有导入,需要将对方的证书拿下来,导入到java的cacerts中。



--完。


阅读(2739) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~