- [root@ns1 /]#vim /etc/pki/tls/openssl.cnf
- 编辑CA的配置文件,这个主要是为了颁发证书的时候,直接就可以enter一路向下了。
- 需找到以下的内容,然后更改主要是更改“_default”对于的值。
- (读者打开这个配置文件就可看到以下的内容)
- [ CA_default ]
- dir = /etc/pki/CA # Where everything is kept
- certs = $dir/certs # Where the issued certs are kept
- crl_dir = $dir/crl # Where the issued crl are kept
- database = $dir/index.txt # database index file.
- [ req_distinguished_name ]
- countryName = Country Name (2 letter code)
- countryName_default = CN
- countryName_min = 2
- countryName_max = 2
- stateOrProvinceName = State or Province Name (full name)
- stateOrProvinceName_default = henan
- localityName = Locality Name (eg, city)
- localityName_default = zhengzhou
- 0.organizationName = Organization Name (eg, company)
- 0.organizationName_default = magedu
- # we can do this but it is not needed normally :-)
- #1.organizationName = Second Organization Name (eg, company)
- #1.organizationName_default = World Wide Web Pty Ltd
- organizationalUnitName = Organizational Unit Name (eg, section)
- #organizationalUnitName_default =
- organizationalUnitName_default =Tech
- [root@ns1 CA]#(umask 077; openssl genrsa 2048 > private/cakey.pem)
- 此时生成的一大段密文,就是我们的私钥,保存至private目录下。
- [root@ns1 private]# ls
- cakey.pem
- [root@ns1 private]# pwd
- /etc/pki/CA/private
- [root@ns1 private]# ll
- -rw------- 1 root root 1675 Oct 22 22:44 cakey.pem
- [root@ns1 CA]# openssl req -new -x509 -days 3650 -key private/cakey.pem -out cacert.pem
- 生成自签证书,x509这个选项就是给自己颁发证书的时候用到的 ,同时也会有以下信息输出。
- (这个就是我们为什么要编辑CA的配置文件,减少工作量并且防止我们填错信息)
- CN [CN]:
- State or Province Name (full name) [henan]:
- Locality Name (eg, city) [zhengzhou]:
- Organization Name (eg, company) [magedu]:
- Organizational Unit Name (eg, section) [Tech]:
- 以上信息一路按enter键即可
- Common Name (eg, your name or your server's hostname) []:ca.magedu.com
- 这一项很关键我们现在时自签给CA自己颁发证书,所以我们这里记录为ca.magedu.com,这项
- 和下一项都要手动填写下 。
- Email Address []:caadmin@magecu.com
- [root@ns1 CA]# ll
- -rw-r--r-- 1 root root 1651 Oct 22 22:46 cacert.pem
- drwx------ 2 root root 4096 Oct 22 22:34 private
- 给CA创建运行环境
- [root@ns1 CA]# mkdir certs newcerts crl
- [root@ns1 CA]# ll
- -rw-r--r-- 1 root root 1651 Oct 22 22:46 cacert.pem
- drwxr-xr-x 2 root root 4096 Oct 22 22:47 certs
- drwxr-xr-x 2 root root 4096 Oct 22 22:47 crl
- drwxr-xr-x 2 root root 4096 Oct 22 22:53 newcerts
- drwx------ 2 root root 4096 Oct 22 22:34 private
- [root@ns1 CA]# touch insex.txt serial [root@ns1 CA]# echo 01 > serial
- [root@ns1 CA]# cd /etc/httpd/conf
- [root@ns1 conf]# ls
- httpd.conf httpd.conf.bak magic
- [root@ns1 conf]# mkdir ssl
- 为了方便新建一个目录,把它的私钥,申请证书以及以后CA给它颁发的证书都放到此目录中。
- [root@ns1 conf]# cd ssl
- [root@ns1 ssl]# (umask 077; openssl genrsa 1024 > httpd.key)
- [root@ns1 ssl]# openssl req -new -key httpd.key -out httpd.csr
- 制作申请证书,再次证明为什么我们要编辑CA的配置文件,给CA颁证时为什么后面要手动填写。
- CN [CN]:
- State or Province Name (full name) [henan]:
- Locality Name (eg, city) [zhengzhou]:
- Organization Name (eg, company) [magedu]:
- Organizational Unit Name (eg, section) [Tech]:
- Common Name (eg, your name or your server's hostname) []:www.test.net
- 这项是非常关键的,这一项即是代表了在为谁申请这个证书,即在互联网上要访问的主机的名称。
- Email Address []:webmaster@test.net
- -rw-r--r-- 1 root root 708 Oct 22 22:53 httpd.csr
- -rw------- 1 root root 891 Oct 22 22:50 httpd.key
- 我们的申请证书(httpd.csr)就做好了,现在拿个CA让CA签署我们的申请证书
- [root@ns1 ssl]#openssl ca -in httpd.csr -out httpd.crt -days 365
- [root@ns1 ssl]# ll
- -rw-r--r-- 1 root root 3872 Oct 22 22:53 httpd.crt
- -rw-r--r-- 1 root root 708 Oct 22 22:53 httpd.csr
- -rw------- 1 root root 891 Oct 22 22:50 httpd.key
- 我们的证书(httpd.crt)已经颁发下来了,这时候我们的申请证书(httpd.key)就没用了。
- [root@ns1 /]#yum install mod_ssl
- 这个模块安装好,查看有哪些文件被安装了
- [root@ns1 ~]# rpm -ql mod_ssl
- /etc/httpd/conf.d/ssl.conf
- 生成一个新的配置文件作为主配置文件/etc/httpd/conf/httpd.conf的补充
- /usr/lib/httpd/modules/mod_ssl.so
- /var/cache/mod_ssl
- /var/cache/mod_ssl/scache.dir
- /var/cache/mod_ssl/scache.pag
- /var/cache/mod_ssl/scache.sem
- [root@ns1 /]#vim /etc/httpd/conf.d/ssl.conf
- 找到以下两项,给出web证书以及它的密钥存放的位置然后我们要重新启动下服务
- SSLCertificateKeyFile /etc/httpd/conf/ssl/httpd.key
- SSLCertificateFile /etc/httpd/conf/ssl/httpd.crt
- [root@ns1 /]#service httpd restart
- 检查443端口是否已经打开
- [root@ns1 /]#netstat -tnlp
- tcp 0 0 :::443 :::* LISTEN 7008/httpd
- 这条信息表示443端口已经打开了,ssl和httpd正常服务
五、测试(此处采用本地测试);
- [root@ns1 ssl]# openssl s_client -host www.test.net -port 443 -CAfile /etc/pki/CA/cacert.pem
- 此时会只要在显示的内容当中找到以下内容,就表示成功
- SSL-Session:
- Protocol : TLSv1
- Cipher : DHE-RSA-AES256-SHA
- Session-ID: CAF837F0A8115730CAB4169CEA8029A9732321F60ACD3C7491B8FF6C15835769
- Session-ID-ctx:
- Master-Key: 26E0D0193CF6EEF3C7029FC5F181065E0B378051C2FC5D60C0151F59D9D1CCDFCC9493E74B5D2B26F00A2AFC6DDF157A
- Key-Arg : None
- Krb5 Principal: None
- Start Time: 1351105702
- Timeout : 300 (sec)
- Verify return code: 0 (ok)
访问测试页面
- [root@ns1 ssl]# elinks -dump www.test.net
- welcome to testhome
亲慢慢来 博主 2012-10-29
亲慢慢来 博主 回复了 亲慢慢来 2012-10-29
kikupotter 2012-10-29
kikupotter 2012-10-29
亲慢慢来 博主 回复了 kikupotter 2012-10-29