vpn的Mschapv2协议与rsa协议在连接时,客户端与服务端会使用证书进行身份认证。

下面就教大家如何使用pki工具生成VPN证书。

参考strongswan官网文档:Certificates Quickstart :: strongSwan Documentation

 

假定服务端为moon,客户端为carol。

1:生成CA证书:(CA证书服务端与客户端公用一份)

 pki --gen --type rsa --size 3072 --outform pem > strongswanKey.pem

   pki --self --type rsa --in strongswanKey.pem --lifetime 3652 \
   --ca --pathlen 1 --dn "C=CH, O=strongSwan Project, CN=strongSwan Root CA" \
   --outform pem > strongswanCert.pem

2、生成服务端moon证书:

  pki --gen --type rsa --size 3072 --outform pem > moonKey.pem

   pki --issue --cakey strongswanKey.pem --cacert strongswanCert.pem --type rsa \
   --in moonKey.pem --lifetime 1826 --san moon.strongswan.org \
   --serial 03 --dn "C=CH, O=strongSwan Project, CN=moon.strongswan.org" \
   --outform pem > moonCert.pem

3、生成carol证书:

pki --gen --type rsa --size 3072 --outform pem > carolKey.pem

   pki --issue --cakey strongswanKey.pem --cacert strongswanCert.pem --type rsa \
   --in carolKey.pem --lifetime 1826 --san carol@strongswan.org \
   --serial 01 --dn "C=CH, O=strongSwan Project, CN=carol@strongswan.org" \
   --outform pem > carolCert.pem

 以上证书生成后,可以使用pki命令进行读取内容:pki -- print --in  ****.pem

4、打包证书:

 openssl pkcs12 -export -inkey carolKey.pem -in carolCert.pem -name "carol"  -passout "pass:123456" -legacy > carolCert.p12

注意:通常基于windows、Android、macOS/iOS的vpn客户端在安装我们的用户证书时,并不能识别pem格式,所以需要将我们的用户证书和私钥打包到p12容器中去才能进行识别安装。 

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐