Skip to content

通过知识获得解放,通过技术获得自由

Menu
  • 专题目录
  • 液压相关
    • 液压技术
    • 液压相邻技术
    • 液压应用
  • 计算机相关
    • 计算机和软件
    • 网络和网站技术
  • 哲学
  • 关于本站
Menu

部署自签名证书[0]

Posted on 2023年11月14日 by

由于bitwarden的本地主密码的生成需要用到https,但是本地的证书是不能采用标准的证书申请方式,故转向部署自签名证书。

  • 简介

OpenSSL是一个开放源代码的软件库包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连线者的身份。这个包广泛被应用在互联网的网页服务器上。

其主要库是以C语言所写成,实现了基本的加密功能,实现了SSL与TLS协议。OpenSSL可以运行在OpenVMS、 Microsoft Windows以及绝大多数类Unix操作系统上(包括Solaris,Linux,Mac OS X与各种版本的开放源代码BSD操作系统)

官网:https://www.openssl.org/

基本定义

1)CA:认证机构。有自己的证书,可以拿自己的证书给别人签名然后收钱,这个星球上的CA被几家说英语的人垄断了。在这里我们会虚拟出一个CA机构,然后用他来给自己的证书认证签名。

2)(网站)证书 :发送给客户端的证书,其中大部分是公钥。是一个包含自己网站的公钥、认证、签名等信息的文件。

3)(网站)私钥 :服务器留存的解密私钥(server)

注意区分 CA机构的证书(可以拿来给其他网站证书签名)和 自己网站的证书(不可以),不一样

  • 部署

带CA和不带CA在服务器端使用下无区别,在客户端下主要是可以将CA添加到系统的证书中心,实现对于其下发的服务器证书的置信(单个计算机有效)。

1)不带CA的自签名证书

cd /root

#通过openssl生成私钥vhost.key
openssl genrsa -out vhost.key 4096

#生成证书申请文件vhost.csr
openssl req -new -key vhost.key -out vhost.csr

#使用私钥对证书申请进行签名从而生成10有效期证书vhost.crt
openssl x509 -req -in server.csr -out vhost.crt -signkey vhost.key -days 3650

echo "证书:vhost.crt"
echo "私钥:vhost.key"

2)带CA的自签名证书

私有CA是相当于虚拟出来一个证书签发机构,网站的证书再由此机构签发。

流程:

  1. 搞一个虚拟的CA机构,生成一个证书
  2. 生成一个自己的密钥,然后填写证书认证申请,拿给上面的CA机构去签名
  3. 于是就得到了自(自建CA机构认证的)签名证书
#创建私有CA密钥private-ca.key
openssl genpkey -algorithm RSA -aes128 -out private-ca.key -outform PEM -pkeyopt rsa_keygen_bits:2048

#创建一个 CA 证书ca-cert.crt
openssl req -x509 -new -nodes -sha256 -days 3650 -key private-ca.key -out ca-cert.crt

#创建创建一个 vhost 密钥vhost.key
openssl genpkey -algorithm RSA -out vhost.key -outform PEM -pkeyopt rsa_keygen_bits:2048

#创建 vhost 证书请求文件vhost.csr
openssl req -new -key vhost.key -out vhost.csr

#配置生成的证书
cat << EOF >/root/vhost.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1 = 10.10.10.8
DNS.2 = 127.0.0.1
EOF

#创建从根 CA 签名的 vhost 证书vhost.crt
openssl x509 -req -in vhost.csr -CA ca-cert.crt -CAkey private-ca.key -CAcreateserial -out vhost.crt -days 365 -sha256 -extfile vhost.ext

echo "网站用证书:vhost.crt"
echo "网站用私钥:vhost.key"

补充说明:

1)自签名证书在nginx部署时需要指定客户端的证书,正常情况下,客户端的证书由第三方证书签发机构下发,但是自签名没有第三方机构的情况下,需要直接指定

2)证书的缓存时间问题,需要将默认的10min改长。

3)常用后缀名

格式说明
.crt .cer证书(Certificate)
.key密钥/私钥(Private Key)
.csr证书认证签名请求(Certificate signing request)
*.pembase64编码文本储存格式,可以单独放证书或密钥,也可以同时放两个;base64编码就是两条——-之间的那些莫名其妙的字符
*.der证书的二进制储存格式(不常用)

4)国家代码查询

https://country-code.cl/

参考资料:

  1. https://ningyu1.github.io/site/post/51-ssl-cert/
  2. https://blog.csdn.net/weixin_46238755/article/details/106311718
  3. https://www.jianshu.com/p/0e9ee7ed6c1d
  4. https://docs.pingcap.com/zh/tidb/stable/generate-self-signed-certificates
  5. https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/

欢迎回来

希望本站对你有所帮助!

如有疑问请联系info@fanlog.org
2023 年 11 月
一二三四五六日
 12345
6789101112
13141516171819
20212223242526
27282930 
« 6 月    

AI辅助 (17)

© 2025 | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT