OpenSSL

lighttpd SSL用证明书

 
openssl req -new -x509 \ 

  -keyout server.pem -out server.pem \ 

  -days 365 -nodes 

显示证书有效期

 
openssl x509 -noout -dates -in ca.pem 

生成证书

# 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” 提示后面我们输入的是一个域名。

这个提示要求输入服务器的名字, 这个名字今后将用于完成验证过程; 如果在这里输入域名以外的内容, 那么证书也就失去其意义了。

您还可以指定一些其他的选项, 比如证书的有效期, 以及使用的加密算法等等。 这些选项的完整列表, 可以在 openssl(1) 联机手册中找到。

在执行前述命令的目录中将生成两个文件。 证书申请, 即 req.pem, 可以发给一家发证机构, 它将验证您输入的凭据的真实性, 并对申请进行签名, 再把证书返还。

第二个文件的名字将是 cert.pem,它包含了证书的私钥,应被全力保护; 如果它落入别人手中,则可以被用来伪造服务器。

更新公司网站证书

更新VeriSign证书需要创建CSR文件,用OpenSSL创建证书

openssl req -new -nodes -keyout server.key -out server.csr 
#输入相关信息

查看那系统是否安装了openssl

[root@server1 conf]# rpm -qa|grep openssl 
openssl-0.9.7a-2 
openssl-devel-0.9.7a-2

生成证书文件
创建一个rsa私钥,文件名为server.key

[root@server1 php-5.0.4]# openssl genrsa -out server.key 1024 
Generating RSA private key, 1024 bit long modulus 
............++++++ 
............++++++ 
e is 65537 (0x10001)

用 server.key 生成证书签署请求 CSR

#openssl req -new -key server.key -out server.csr 
Country Name:两个字母的国家代号 
State or Province Name:省份名称 
Locality Name:城市名称 
Organization Name:公司名称 
Organizational Unit Name:部门名称 
Common Name:你的姓名 
Email Address:地址 
至于 'extra' attributes 不用输入 
生成 server.csr 文件,并放在安全的地方。

生成证书CRT文件server.crt。

openssl x509 -days 365 -req -in server.csr -signkey server.key -out server.crt

将它们copy到apache的conf目录下
为了安全起见,将它们的权限进行修改

chmod 400 server.*

查看虚拟主机设置

[root@server1 conf]# ../bin/apachectl -S 
VirtualHost configuration: 
wildcard NameVirtualHosts and _default_ servers: 
*:80          dummy-host.example.com (/usr/local/apache22/conf/extra/httpd-vhosts.conf:27) 
*:81          dummy-host2.example.com (/usr/local/apache22/conf/extra/httpd-vhosts.conf:36) 
_default_:443          www.example.com (/usr/local/apache22/conf/extra/httpd-ssl.conf:74) 
Syntax OK

重启apache

#service httpd restart

查看443端口是否被监听

#netstat -an|grep 443 
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN

客户端就能使用https来访问了

/home/yepnnet/public_html/wiki/data/pages/openssl.txt · 最后更改: 2010/02/02 01:59 由 admin
到顶部
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0