posts - 33, comments - 46, trackbacks - 0, articles - 2

使用openssl生成自签名证书、配置SSL

Posted on 2008-07-18 12:40 在路上... 阅读(5811) 评论(3)  编辑  收藏 所属分类: JAVA相关
首先,下载openssl安装,windows环境从http://www.openssl.org/related/binaries.html下载。
我这里测试下载的版本是:http://www.slproweb.com/download/Win32OpenSSL-0_9_8h.exe
安装完成之后,修改bin目录下面的openssl.cfg为openssl.cnf,在请求证书时需要用到这个配置文件,生成证书,为了方便,编写了下面的批处理文件,供参考:


@echo off
echo 
1.CA 创建一个 RSA 私用密钥
openssl genrsa 
-out %1.key 1024 

echo.
echo 
2.利用 CA 的 RSA 密钥创建一个自签署的 CA 证书(X.509结构)
openssl req 
-new -x509 -days 36500 -key %1.key -out %1.crt -subj /C=CN/ST=GuangDong/L=GuangZhou/O=SinoTech/OU=CA-SinoTech

echo.
echo 
3.CA 创建一个 服务端 RSA 私用密钥
openssl genrsa 
-out %2.key 1024 
echo.

echo 
4.创建服务端签署请求 CSR
openssl req 
-new -key %2.key -out %2.csr -subj "/C=CN/ST=GuangDong/L=GuangZhou/O=SinoTech/OU=Serv-SinoTech/CN=SinoTech Weblogic Server"

echo.
echo 
5.签署证书
rem 准备一些默认文件、目录,否则运行时会报错
if exist "%cd%\newcerts" goto got1
md newcerts
:got1

if exist "%cd%\index.txt" goto got2
echo tmp 
>_tmp
del _tmp 
>index.txt
:got2

if exist "%cd%\serial" goto got3
echo AD 
>serial
:got3

openssl ca 
-in %2.csr -out %2.crt -cert %1.crt -keyfile %1.key 
echo.
echo 处理完成
pause

运行批处理
genca.cmd [CA证书名] [服务端证书名]
例如genca.cmd ca server

通过上面命令,会生成server.crt,server.key,然后将上面参数加到tomcat的配置中就可以使用SSL连接方式访问网站应用了
<Connector 
           
port="8443" minSpareThreads="5" maxSpareThreads="75"
           enableLookups
="true" disableUploadTimeout="true" 
           acceptCount
="100"  maxThreads="200"
           scheme
="https" secure="true" SSLEnabled="true"
           SSLCertificateFile
="C:\apache-tomcat-6.0.16\conf\server.crt" 
           SSLCertificateKeyFile
="C:\apache-tomcat-6.0.16\conf\server.key"
           clientAuth
="false" sslProtocol="TLS"/>

Feedback

# re: 使用openssl生成自签名证书、配置SSL  回复  更多评论   

2009-06-23 20:30 by 王细东
Office文档控件

# re: 使用openssl生成自签名证书、配置SSL  回复  更多评论   

2009-08-15 10:44 by 诺恒
请问这个问题怎样解决?

5.签署证书
Using configuration from C:\OpenSSL\bin\opens
Loading 'screen' into random state - done
I am unable to access the ./demoCA/newcerts d
./demoCA/newcerts: No such file or directory

# re: 使用openssl生成自签名证书、配置SSL  回复  更多评论   

2009-08-15 11:00 by 诺恒
终于解决了

只有注册用户登录后才能发表评论。


网站导航: