Chinaunix首页 | 论坛 | 博客
  • 博客访问: 630541
  • 博文数量: 102
  • 博客积分: 7242
  • 博客等级: 少将
  • 技术积分: 1440
  • 用 户 组: 普通用户
  • 注册时间: 2005-06-06 14:59
文章分类

全部博文(102)

文章存档

2011年(1)

2010年(12)

2009年(6)

2008年(83)

分类: LINUX

2008-12-25 18:11:47

生成证书

  为了生成证书, 需要使用下面的命令:

# openssl req -new -nodes -out req.pem -keyout cert.pem
Generating a 1024 bit RSA private key
................++++++
.......................................++++++
writing new private key to 'cert.pem'
-----
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]:US
State or Province Name (full name) [Some-State]:PA
Locality Name (eg, city) []:Pittsburgh
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Company
Organizational Unit Name (eg, section) []:Systems Administrator
Common Name (eg, YOUR name) []:localhost.example.org
Email Address []:trhodes@FreeBSD.org

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:SOME PASSWORD
An optional company name []:Another Name

  请注意, 在 “Common Name” 提示后面我们输入的是一个域名。这个提示要求输入服务器的名字, 这个名字今后将用于完成验证过程;如果在这里输入域名以外的内容, 那么证书也就失去其意义了。 您还可以指定一些其他的选项,比如证书的有效期, 以及使用的加密算法等等。 这些选项的完整列表, 可以在 联机手册中找到。

  在您执行前述命令的目录中将生成两个文件。 证书申请, 即 req.pem, 可以发给一家发证机构, 它将验证您输入的凭据的真实性,并对申请进行签名, 再把证书返还给您。 第二个文件的名字将是 cert.pem, 它包含了证书的私钥, 应被全力保护; 如果它落入别人手中,则可以被用来伪造您 (或您的服务器)。

  如果不需要来自 CA 的签名,也可以创建自行签名的证书。 首先, 需要生成 RSA 密钥:

# openssl dsaparam -rand -genkey -out myRSA.key 1024

  接下来, 生成 CA 密钥:

# openssl gendsa -des3 -out myca.key myRSA.key

  然后用这个密钥来创建证书:

# openssl req -new -x509 -days 365 -key myca.key -out new.crt

  上述步骤将在当前目录中生成两个新文件: 一个是权威发证机构的签名文件, myca.key; 另一个是证书本身, new.crt。这些文件应该放到同一个目录中, 一般而言, 推荐放到 /etc,并且只允许 root 读取。 建议把权限设置为 0700, 这可以通过 chmod 工具来完成。

阅读(1352) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~