您的当前位置:首页正文

自己的SSL证书签发工具

来源:要发发知识网

又到了自己造轮子的季节。


安装方法

将工程clone下来,然后进入工程目录,运行

sudo su
apt-get update
apt-get install openssl
./install.sh -l

简单使用场景

$ woodyssl -c -subj "/C=CN/ST=Beijing/L=Beijing/O=Tsinghua/CN=Vlion Club"
$ woodyssl -c -d 
$ woodyssl -l

$ woodyssl -d  -e path/to/export/certficates

第一行命令会创建你自己的根证书。并且记录一些描述性的信息,"/C=CN/ST=Beijing/L=Beijing/O=Tsinghua/CN=Vlion Club"中,/C代表国家,/ST代表省份,/L代表城市,/O代表组织名称,/CN达标常用名。你可以替换成你需要的值。程序会将证书相关内容放在~/.woodyssl下。
第二行命令会为域名创建证书
第三行命令列出现在创建了证书的域名
第四行将站点证书导出到一个文件夹中。之后你就可以在nginx中使用这些证书了。
(更多的命令运行woodyssl -h查看吧)

将根证书加入本机的信任列表来关闭浏览器的警告信息

先在主流的浏览器对于非权威机构的根证书都会弹出警告,部分甚至会禁止用户访问(某果的某Safari)。为了避免这些问题你需要将根证书加入本机的信任列表。
使用下面的命令导出根证书

$ woodyssl -e path/to/export/root-ca

导出的文件包含root-ca.crtroot-ca.key,其中前者是证书文件,后者是秘钥。具体的本机添加新任列表请读者自行GOOGLE一下,这里就不赘述了。

补充

server {
        listen 80;

        server_name 
        error_log /absolute/path/to/error.log;
        access_log /absolute/path/to/access.log;
        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://localhost:8080;
        }

        client_max_body_size 50m;
  
        listen 443 ssl;
        # SSL
        ssl_certificate 
        ssl_certificate_key /path/to/yourdomain.key;

        # Recommendations from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
        ssl_protocols TLSv1.1 TLSv1.2;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;

        chunked_transfer_encoding on;

        if ($scheme != "https") {
            return 301 https://$host$request_uri;
        }
}