时间:2021-07-01 10:21:17 帮助过:70人阅读
由于实验需要,需要手动制作CA证书以及客户端和服务器端证书,总结如下: 最近两天,查阅了一些关于创建证书的资料,发现网上很多介绍并不是很完整,不具有完全的可操作性。 @echo off@rem set OPENSSL_HOME=d:\tools\OpenSSL-Win32set PATH=%OPENSSL_HOME%\
由于实验需要,需要手动制作CA证书以及客户端和服务器端证书,总结如下:
最近两天,查阅了一些关于创建证书的资料,发现网上很多介绍并不是很完整,不具有完全的可操作性。
创建证书,我目前知道的大概这么几种:
1.keytool
不能创建CA证书
2.Sybase ASA自带的createcert.exe
好像不能创建PKCS12型证书
3.OpenSSL
功能最强大。
所以,这里干脆只介绍OpenSSL了。
安装完OpenSSL-Win32到d:\tools之后,修改配置文件d:\tools\OpenSSL-Win32\bin\openssl.cfg
找到:
[ CA_default ]
dir = $ENV::OPENSSL_HOME/CA # Where everything is kept
这里原来值是./demoCA
还是用绝对路径比较好。就放到d:\tools\OpenSSL-Win32\CA目录下。
紧接着,做一些准备工作,创建一些子目录,准备创建证书,
完全的批处理命令如下:
@echo off @rem set OPENSSL_HOME=d:\tools\OpenSSL-Win32 set PATH=%OPENSSL_HOME%\bin;%PATH% mkdir %OPENSSL_HOME%\CA cd /d %OPENSSL_HOME%\CA echo "create subdir certs" mkdir certs mkdir newcerts mkdir private mkdir crl echo "create file: index and serial" echo 0>index.txt echo 01>serial echo "create rand file" openssl rand -out private/.rand 1000 @rem echo %random% >> private/.rand @echo off set PATH=d:\tools\Openssl-Win32\bin;%PATH% echo create private key for rootca @rem the password, set it as 123456 openssl genrsa -aes256 -out private/ca.key.pem 2048 echo generate root ca request openssl req -new -key private/ca.key.pem -out private/ca.csr -subj "/C=CN/ST=BJ/L=BJ/O=zlex/OU=zlex/CN=*.sql9.com" echo create root ca cert openssl x509 -req -days 10000 -sha1 -extensions v3_ca -signkey private/ca.key.pem -in private/ca.csr -out certs/ca.cer echo convert the cert from cer into PKCS12 openssl pkcs12 -export -clcerts -in certs/ca.cer -inkey private/ca.key.pem -out certs/ca.p12 echo use keytool can query the pkcs12 cert status keytool -list -keystore certs/ca.p12 -storetype pkcs12 -v -storepass 123456 echo create server ca openssl genrsa -aes256 -out private/server.key.pem 2048 openssl req -new -key private/server.key.pem -out private/server.csr -subj "/C=CN/ST=BJ/L=BJ/O=zlex/OU=zlex/CN=www.sql9.com" openssl x509 -req -days 3650 -sha1 -extensions v3_req -CA certs/ca.cer -CAkey private/ca.key.pem -CAserial ca.srl -CAcreateserial -in private/server.csr -out certs/server.cer openssl pkcs12 -export -clcerts -inkey private/server.key.pem -in certs/server.cer -out certs/server.p12 echo create client ca openssl genrsa -aes256 -out private/client.key.pem 2048 openssl req -new -key private/client.key.pem -out private/client.csr -subj "/C=CN/ST=BJ/L=BJ/O=zlex/OU=zlex/CN=sql9" openssl ca -days 3650 -in private/client.csr -out certs/client.cer -cert certs/ca.cer -keyfile private/ca.key.pem openssl pkcs12 -export -clcerts -inkey private/client.key.pem -in certs/client.cer -out certs/client.p12 cp -r certs certs.new