openssl自签名多域名证书

这几天一直在研究如何使用openssl工具来生成多域名证书,今天终于有点眉目了,实现方法如下:

生成私钥

openssl genrsa -out server.key 1024

用私钥生成自签名的cer证书格式文件
openssl req -new -x509 -days 3650 -key server.key -out server.crt -subj "/C=CN/ST=mykey/L=mykey/O=mykey/OU=mykey/CN=domain1/CN=domain2/CN=domain3"

将证书转化成pkcs12格式

openssl pkcs12 -export -in server.cer -inkey server.key -out server.p12

将证书格式转化成jks格式

keytool -importkeystore -srcstoretype pkcs12 -srckeystore server.p12 -destkeystore server.jks

 

另一种生成多域名证书的方法:

生成私钥

openssl genrsa -out server.key 1024

用私钥生成自签名的cer证书格式文件
openssl req -new -x509 -days 3650 -key server.key -out server.crt -config openssl.cnf

根据要求输入多个域名

其中openssl.cnf是一个配置文件,可自己手动配置,如果要支持多个域名,需要在该配置文件多增加几个commonname选项,比如:

[ req_distinguished_name ]

0.commonName = Common Name (hostname, IP, or your name)
0.commonName_max = 64
1.commonName = Common Name (hostname, IP, or your name)
1.commonName_max = 64
2.commonName = Common Name (hostname, IP, or your name)
2.commonName_max = 64

需要支持多少个,就添加多少项,如果要通过配置文件的方式来进行操作,建议首先了解一下openssl.cnf中的配置信息,网上这方面的资料很多

 

posted @ 2012-05-07 00:20  freeman_rain  阅读(3361)  评论(0编辑  收藏  举报