zoukankan      html  css  js  c++  java
  • 自做CA自签发SSL证书

    一、把证书准备好。
    步骤与使用OpenSSL自签发服务器https证书所述大同小异。在这里再重复一次。
    1、制作CA证书:
    ca.key CA私钥:

    openssl genrsa -des3 -out ca.key 2048
    Enter pass phrase for ca.key:*****          要求创建密码

    制作解密后的CA私钥(一般无此必要):

    openssl rsa -in ca.key -out ca_decrypted.key

    ca.crt CA根证书(公钥):

    openssl req -new -x509 -days 7305 -key ca.key -out ca.crt

    2、制作生成网站的证书并用CA签名认证
    在这里,假设网站域名为blog.creke.net
    生成tdp.up.com证书私钥:

    openssl genrsa -des3 -out tdp.up.com.pem 1024
    Enter pass phrase for tdp.up.com.pem:*****    要求创建密码

    制作解密后的blog.creke.net证书私钥:

     openssl rsa -in tdp.up.com.pem -out tdp.up.com.key

    生成签名请求:

    openssl req -new -key tdp.up.com.pem -out tdp.up.com.csr

    在common name中填入网站域名,如:tdp.up.com,即可生成改站点的证书,同时也可以使用泛域名如*.up.com来生成所有二级域名可用的网站证书。

    用CA进行签名:

    openssl ca -policy policy_anything -days 1460 -cert ca.crt -keyfile ca.key -in tdp.up.com.csr -out tdp.up.com.crt

    其中,policy参数允许签名的CA和网站证书可以有不同的国家、地名等信息,days参数则是签名时限。

    如果在执行签名命令时,出现“I am unable to access the ../../CA/newcerts directory”
    修改/etc/pki/tls/openssl.cnf中“dir = ./CA”

    然后:

    mkdir -p CA/newcerts
    touch CA/index.txt
    touch CA/serial
    echo "01" > CA/serial

    再重新执行签名命令。
    最后把ca.crt的内容粘贴到tdp.up.com.crt后面。这个比较重要!因为不这样做,可能会有某些浏览器不支持。
    好了,现在https需要到的网站私钥tdp.up.com.key和网站证书tdp.up.com.crt都准备完毕。接下来开始配置服务端。

    二、以nginx为例
    新开一个虚拟主机,并在server{}段中设置:

    listen 443;
    ssl on;
    ssl_certificate /path/to/tdp.up.com.crt;
    ssl_certificate_key /path/to/tdp.up.com.key;
    ssl_session_timeout 5m;
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_prefer_server_ciphers on;

    其中的路径是刚刚生成的网站证书的路径。
    然后使用一下命令检测配置和重新加载nginx:
    检测配置:
    nginx -t
    重新加载:
    nginx -s reload

  • 相关阅读:
    企信通自动登录问题解决
    BPM保存提交审核时后台校验数据
    初始化BPM
    BPM删除事件,删除表单
    flowportal数据字典
    百度网盘
    HPC 有哪些应用层?
    公众号改名字了:子郁定投上海
    一些网站和他们的关键词介绍
    如何找到女朋友
  • 原文地址:https://www.cnblogs.com/dongming/p/6378723.html
Copyright © 2011-2022 走看看