IPsec certificate身份验证-openssl生成证书

转载请注明出处: http://blog.csdn.net/zhangyang0402/archive/2010/05/27/5626953.aspx

 

操作系统:Windows XP professional SP3

Openssl: 1.0.0 29

 

一、        生成CA证书

 

1. 生成CA私钥

C:/demoCA>openssl genrsa -out ca.key 1024

Loading 'screen' into random state - done

Generating RSA private key, 1024 bit long modulus

............++++++

..............................++++++

e is 65537 (0x10001)

 

2. 生成CA证书请求

C:/demoCA>openssl req -new -key ca.key -out ca.csr

Loading 'screen' into random state - done

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [AU]:CN

State or Province Name (full name) [Some-State]:Beijing

Locality Name (eg, city) []:Beijing

Organization Name (eg, company) [Internet Widgits Pty Ltd]:Intel

Organizational Unit Name (eg, section) []:IT

Common Name (eg, YOUR name) []:Yang Zhang

Email Address []:yang.zhang@intel.com

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:123456

An optional company name []:

 

3. 自签名CA证书

C:/demoCA>openssl x509 -req -in ca.csr -out ca.cert -signkey ca.key -days 3650

Loading 'screen' into random state - done

Signature ok

subject=/C=CN/ST=Beijing/L=Beijing/O=Intel/OU=IT/CN=Yang Zhang/emailAddress=yang

.zhang@intel.com

Getting Private key

 

二、生成客户端证书

 

1. 生成私钥

C:/demoCA>openssl genrsa -out client.key 1024

Loading 'screen' into random state - done

Generating RSA private key, 1024 bit long modulus

.++++++

..........++++++

e is 65537 (0x10001)

 

2. 生成证书请求

C:/demoCA>openssl req -new -key client.key -out client.csr

Loading 'screen' into random state - done

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [AU]:CN

State or Province Name (full name) [Some-State]:BJ

Locality Name (eg, city) []:BJ

Organization Name (eg, company) [Internet Widgits Pty Ltd]:Intel

Organizational Unit Name (eg, section) []:IT

Common Name (eg, YOUR name) []:client

Email Address []:client@intel.com

 

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:654321

An optional company name []:

 

3.CA签名

C:/demoCA>openssl x509 -req -in client.csr -out client.cert -CA ca.cert -CAkey c

a.key -CAcreateserial -days 3650

Loading 'screen' into random state - done

Signature ok

subject=/C=CN/ST=BJ/L=BJ/O=Intel/OU=IT/CN=client/emailAddress=client@intel.com

Getting CA Private Key

 

4. 转换成pfx格式

C:/demoCA>openssl pkcs12 -export -clcerts -in client.cert -inkey client.key -out

 client.pfx

Loading 'screen' into random state - done

Enter Export Password:

Verifying - Enter Export Password:123456

 

三、        配置Ipsec

 

通过上面的方法,生成CA证书ca.cert,两个客户端证书client.pfx, server.pfx

1.       导入证书

在两台测试机中,通过MMC分别导入CA证书和自己的证书,CA证书导入到本地计算机的“受信任的根证书颁发机构”证书下,个人证书导入到本地计算机的“个人”证书下(个人证书导入时要输入先前的export password)

 

注:导入个人证书后,在MMC证书中双击个人证书,在“常规”选项卡时,可看到一个钥匙标记“您有一个与该证书对应的私钥”, 若无此标记,则Ipsec Main Mode协商中将会失败。这也是制作客户端证书时转换成pfx格式证书的原因。

 

2.       设置身份验证方法

在两台测试机中,设置身份验证方法为“使用由此证书颁发机构(CA)颁发的证书”,单击“浏览”按钮,选择CA证书即可(注:不是选择个人证书)

 

四、测试

C:/demoCA>ping 192.168.0.201

 

Pinging 192.168.0.201 with 32 bytes of data:

 

Negotiating IP Security.

Reply from 192.168.0.201: bytes=32 time<1ms TTL=128

Reply from 192.168.0.201: bytes=32 time<1ms TTL=128

Reply from 192.168.0.201: bytes=32 time<1ms TTL=128

 

Ping statistics for 192.168.0.201:

    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

 

测试成功

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenSSL是一个开源的加密库,可以用来生成证书、加密和解密数据以及生成密钥等。在Linux和Unix系统中,OpenSSL已经预装了。在Windows系统中,需要下载并安装OpenSSL。 以下是使用OpenSSL生成证书的步骤: 1. 生成私钥 首先,需要生成一个私钥。私钥是一串密文,用于加密和解密数据。在命令行中输入以下命令: openssl genrsa -out private.key 2048 其中,-out指定生成的私钥文件名为private.key,2048指定私钥长度为2048位。 2. 生成证书请求 生成私钥后,需要生成一个证书请求。证书请求包含了需要证书签名的信息,如组织名称、域名等。在命令行中输入以下命令: openssl req -new -key private.key -out request.csr 其中,-new指定生成一个新的证书请求,-key指定使用先前生成的私钥,-out指定生成证书请求文件名为request.csr。 在生成证书请求时,需要输入一些信息,如组织名称、组织单位、城市等。这些信息将被用于证书签名。 3. 签发证书 生成证书请求后,需要将其发送给证书颁发机构(CA)签名。如果是自签名证书,可以使用以下命令自行签名: openssl x509 -req -days 365 -in request.csr -signkey private.key -out certificate.crt 其中,-req指定使用证书请求签发证书,-days指定证书有效期为365天,-in指定证书请求文件名为request.csr,-signkey指定使用先前生成的私钥签名,-out指定生成证书文件名为certificate.crt。 4. 将证书和私钥打包 生成证书后,需要将证书和私钥打包,以便在需要时一起使用。在命令行中输入以下命令: openssl pkcs12 -export -in certificate.crt -inkey private.key -out certificate.p12 其中,-export指定将证书和私钥打包,-in指定证书文件名为certificate.crt,-inkey指定私钥文件名为private.key,-out指定生成的打包文件名为certificate.p12。 5. 验证证书 最后,可以使用以下命令验证证书是否正确: openssl verify certificate.crt 如果证书正确,会输出certificate.crt: OK。 以上就是使用OpenSSL生成证书的详细步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值