自签证书的生成及可信列表的添加

1. 正文

1
2
3
4
5
6
# 此处需要让你设置一个密码(好像可以直接忽略密码,但不晓得怎么操作)
## openssl genrsa -out ca.key 4096
openssl genrsa -des3 -out ca.key 4096

# 移除出私钥密码
openssl rsa -in ca.key -out ca.key
  • subj 参数说明
    字段 字段含义 示例
    /C= Country 国家 CN
    /ST= State or Province Chongqing
    /L= Location or City 城市 Shapingba
    /O= Organization 组织或企业 0x5c0f
    /OU= Organization Unit 部门 ops
    /CN= Common Name 域名或IP blog.0x5c0f.cc
1
openssl req -utf8 -x509 -new -nodes -key ca.key -sha512 -days 18250 -out ca.pem -subj "/C=CN/ST=CQ/O=0x5c0f/CN=0x5c0f/emailAddress=mail@0x5c0f.cc"
1
openssl genrsa -out server.key 4096
1
openssl req -new -key server.key -out server.csr -subj "/C=CN/ST=CQ/O=0x5c0f/CN=0x5c0f.cc/emailAddress=mail@0x5c0f.cc"
  • 后续有新域名,直接加入进去即可
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cat > server.ext <<EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth, clientAuth, codeSigning
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.0x5c0f.cc
DNS.2 = *.51ac.cc
DNS.3 = localhost
IP.1 = 127.0.0.1
EOF
1
openssl x509 -req -in server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out server.crt -days 1825 -sha512 -extfile server.ext

https://qastack.cn/unix/90450/adding-a-self-signed-certificate-to-the-trusted-list

  • fedroa32为例
1
2
sudo cp -v ca.pem /etc/pki/ca-trust/source/anchors/ca.pem
sudo update-ca-trust 
  • win 10为例
  1. win + R 打开运行窗口, 键入 mmc 然后回车, 选择 文件-添加/删除单元节点。选择证书-添加,打开选项卡自行判断选择,完成即可。

  2. 上述完成后,在mmc控制台中就可以看到证书节点, 展开证书-受信任的根证书颁发机构,选择其下面证书,然后右键 所有任务-导入,导入生成的ca.pem即可,退出时会提示存储控制台的信息,可以忽略