nginx Multi-Certificates

NGINX 配置多个证书一般有两种场景: 同一个域名下提供多种类型证书,如RSA,ECC证书 多个域名部署在同一个IP,使用多个不同证书, 根据客户端上送SNI选择证书 生成证书 使用 ssl_cert_chain_tool.sh 生成一组正式证书 RSA 类型证书 ssl_cert_chain_tool.sh -a RSA -o a_cert -n a.example.com -u ssl_cert_chain_tool.sh -a RSA -o b_cert -n b.example.com -u ssl_cert_chain_tool.sh -a RSA -o c_cert -n c.example.com -u ECC 类型证书 ssl_cert_chain_tool.sh -a ECC -o d_cert -n d.example.com -u ssl_cert_chain_tool.sh -a ECC -o e_cert -n e.example.com -u 支持多种类型证书 http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 0.0.0.0:443 ssl; ssl_protocols TLSv1.3 TLSv1.2; server_name a.example.com b.example.com c.example.com d.example.com e.example.com; ssl_prefer_server_ciphers on; # RSA and ECC Certificates ssl_certificate a_cert/server.cert.pem; ssl_certificate_key a_cert/server.key.pem; ssl_certificate e_cert/server.cert.pem; ssl_certificate_key e_cert/server.key.pem; ssl_certificate d_cert/server.cert.pem; ssl_certificate_key d_cert/server.key.pem; ssl_certificate c_cert/server.cert.pem; ssl_certificate_key c_cert/server.key.pem; ssl_certificate b_cert/server.cert.pem; ssl_certificate_key b_cert/server.key.pem; location / { return 200 'Multi-certificates test\n'; } } } 客户端与服务端握手时根据签名算法选择合适的证书, openssl 中使用tls_post_process_client_hello->tls_choose_sigalg 针对收到client hello报文后进行处理,上送的签名算法和服务端配置选择合适的证书。 ...

2025-01-06 · 6 min · 1226 words

Simplify SSL/TLS Certificate Management

In modern network communication, SSL/TLS certificates are essential for ensuring secure data transmission. However, managing certificate chains for various cryptographic standards, such as RSA, ECC, and China’s SM2, can be a complex task. To streamline this process, we introduce multicertgen, an efficient and flexible open-source tool. Introduction multicertgen is a versatile SSL/TLS certificate generation tool that supports the following cryptographic algorithms: SM2: A commercial cryptographic standard in China. RSA: A globally recognized and widely used classic cryptographic algorithm. ECC: A modern, efficient cryptographic standard based on elliptic curves, offering high security and performance. Designed for developers and system administrators, this tool enables the creation of complete certificate chains, supporting both global and Chinese cryptographic standards. ...

2024-12-22 · 2 min · 315 words

多功能 SSL/TLS 证书生成工具

在当今的网络通信中,SSL/TLS 证书是确保数据传输安全的关键元素。然而,面对不同的加密算法和标准(如国际上的 RSA 和 ECC,以及中国的国密 SM2),生成和管理证书链往往是一项复杂的任务。为了简化这一过程,开发了一个高效、灵活的开源工具——multicertgen。 工具简介 multicertgen 是一款多功能的 SSL/TLS 证书生成工具,支持以下加密算法: SM2: 国密标准,适用于中国的商业密码加密。 RSA: 国际通用的经典加密算法。 ECC: 基于椭圆曲线的现代加密算法,具有高效性和安全性。 该工具专为开发者和运维人员设计,支持生成完整的证书链,适用于全球及中国商密标准的多种场景。 主要功能 支持多种加密算法:可以根据需求选择 SM2、RSA 或 ECC 算法。 生成完整的证书链: 根 CA 证书 中间 CA 证书 服务器签名证书 服务器加密证书(仅适用于 SM2) 灵活的私钥加密:支持生成加密和未加密的私钥。 动态配置环境变量:可以通过 LD_LIBRARY_PATH 和 PATH 指定依赖路径,方便使用定制的 Tongsuo 或 OpenSSL 环境。 自动化证书生成:减少繁琐的命令行输入,提升效率。 安装与使用 1. 克隆项目 git clone git@github.com:weida/multicertgen.git cd multicertgen 2. 设置执行权限 chmod +x ssl_cert_chain_tool.sh 3. 运行脚本 ./ssl_cert_chain_tool.sh -a SM2 -o output_dir -p mypassword 参数说明: -a:选择加密算法(SM2、RSA 或 ECC)。 -o:指定输出目录(默认为 certs)。 -p:设置私钥密码(默认为 garlic)。 -u:生成未加密的私钥。 -t 和 -l:配置 Tongsuo 的二进制路径和动态库路径。 适用场景 国密应用:生成符合中国加密标准的 SSL/TLS 证书链。 国际应用:支持 RSA 和 ECC 算法,满足全球通用的加密需求。 开发与测试:快速搭建开发和测试环境,节省手动配置时间。 开源与贡献 该项目托管在 GitHub 上,欢迎贡献代码和提出建议: GitHub 仓库地址 ...

2024-12-22 · 1 min · 98 words

Detailed Configuration Guide for the NGINX Directive ssl_password_file

Title: Using ssl_password_file in NGINX for SSL/TLS Private Key Management Introduction The ssl_password_file directive in NGINX specifies a file containing passwords used to unlock encrypted SSL/TLS private keys. When NGINX starts or reloads, it reads this file to load and decrypt the private key. Incorrect passwords in this file will prevent NGINX from starting or reloading successfully. Syntax Syntax: ssl_password_file file; Default: — Context: http, server This directive appeared in version 1.7.3. file: Specifies the path to the password file. Each line in the file should contain a single password. When loading a private key, NGINX will try the passwords in sequence. Default By default, the ssl_password_file directive is not enabled, and no password file is set. ...

2024-12-03 · 5 min · 864 words

intermediate CA certificate 中间证书

中间证书 中间证书的使用是随着公共密钥基础设施(PKI)的发展而逐渐普及。 早期数字证书体系中根证书直接签发终端(客户端)证书,这种方式存在的问题 根证书安全风险: 一旦根证书泄露整个信任体系就会崩溃; 证书管理的灵活性:根证书通常有大型认证机构管理,工作不能合理分发; 证书撤销机制:仅用根证书签发,一旦撤销将影响整个信任链; 相关标准 X.509 证书标准: X.509 v3 证书标准中, 引入了更多扩展字段,使得中间证书可以更有效地运作。它允许通过设置 basicConstraints 扩展来定义证书是否是一个证书颁发机构(CA)证书,并引入路径长度约束(pathlen),以确保中间证书不能签发超出其级别的证书。 X.509 v3 是证书链中的关键标准,它允许将证书分层,使得根证书签发中间证书,中间证书再签发终端证书。这一机制在 1996 年被纳入 X.509 v3 标准。 互联网工程任务组 (IETF) 标准:RFC 5280: RFC 5280 是互联网标准的一个重要文档,它详细说明了证书路径验证的标准,定义了如何使用 X.509 证书和证书吊销列表(CRL)来建立信任链。 X.509 v3 侧重于定义证书和结构, RFC 5280 侧重于在互联网应用中的使用,包括如何处理证书路径验证和证书撤销。 记得刚工作时正赶上银行收单系统一机一密改造,为每个终端生成终端密钥,与PKI体系不同,当时的pos和收单系统终端大多用的还是对称加密体系。 收单终端签到会根据其对应终端主密钥生成工作密钥,用于保护用户密码和用于报文校验。最早的终端密钥用的都是各省一个, 后来为每个终端生成一个终端主密钥, 防止主密钥泄露导致全省密钥泄露。 其实大体改造思路和中间正式类似。 实际使用 看下实际网站证书使用情况 # openssl s_client -connect baidu.com:443 -showcerts CONNECTED(00000003) depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA verify return:1 depth=1 C = US, O = DigiCert Inc, CN = DigiCert Secure Site Pro CN CA G3 verify return:1 depth=0 C = CN, ST = \E5\8C\97\E4\BA\AC\E5\B8\82, O = "BeiJing Baidu Netcom Science Technology Co., Ltd", CN = www.baidu.cn verify return:1 --- Certificate chain 0 s:C = CN, ST = \E5\8C\97\E4\BA\AC\E5\B8\82, O = "BeiJing Baidu Netcom Science Technology Co., Ltd", CN = www.baidu.cn i:C = US, O = DigiCert Inc, CN = DigiCert Secure Site Pro CN CA G3 -----BEGIN CERTIFICATE----- ....PMdeTgwOzn2nJhPcJFZ5yUGPZ8thorOYjMLHQ4DKsy7mnGMnKLwmz17L/0Tx 8GU= -----END CERTIFICATE----- 1 s:C = US, O = DigiCert Inc, CN = DigiCert Secure Site Pro CN CA G3 i:C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA -----BEGIN CERTIFICATE----- ....+AgqbDB91mdnxIr1MuTtHGn/Q1YE2x9OSTb2f2k0ArhFxFdcjKTfLLewG1xD -----END CERTIFICATE----- --- Server certificate subject=C = CN, ST = \E5\8C\97\E4\BA\AC\E5\B8\82, O = "BeiJing Baidu Netcom Science Technology Co., Ltd", CN = www.baidu.cn issuer=C = US, O = DigiCert Inc, CN = DigiCert Secure Site Pro CN CA G3 --- 根证书(depth=2):由 DigiCert 签发,是整个信任链的起点,受操作系统或浏览器信任。 中间证书(depth=1):DigiCert 的中间 CA,用于签发百度的终端服务器证书。 服务器证书(depth=0):这是百度的具体服务器证书,表明它属于 www.baidu.cn,并由 DigiCert 的中间 CA 签发。 ...

2024-10-12 · 10 min · 1995 words

证书common name

项目自签名证书,common name 超过64个字节报错 # openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=01234567890123456789012345678901234567890123456789012345678901234" Generating a RSA private key ........................++++ ........................................++++ writing new private key to 'key.pem' ----- problems making Certificate Request 140059529942848:error:0D07A097:asn1 encoding routines:ASN1_mbstring_ncopy:string too long:crypto/asn1/a_mbstr.c:107:maxsize=64 Common Name在 RFC5280中有描述(https://datatracker.ietf.org/doc/html/rfc5280#appendix-A) -- Naming attributes of type X520CommonName id-at-commonName AttributeType ::= { id-at 3 } -- Naming attributes of type X520CommonName: -- X520CommonName ::= DirectoryName (SIZE (1..ub-common-name)) -- -- Expanded to avoid parameterized type: X520CommonName ::= CHOICE { teletexString TeletexString (SIZE (1..ub-common-name)), printableString PrintableString (SIZE (1..ub-common-name)), universalString UniversalString (SIZE (1..ub-common-name)), utf8String UTF8String (SIZE (1..ub-common-name)), bmpString BMPString (SIZE (1..ub-common-name)) } 可以看到ub-common-name就是其长度定义, 当然也有一系列定义。 ...

2024-07-03 · 2 min · 404 words

linux arp 参数整理 – arp_filter

arp_filter: 控制系统对不同网络接口上收到的 ARP 请求的响应行为 取值范围: 1 - 允许您在同一子网上拥有多个网络接口,并根据内核是否会从ARP请求的IP地址出路由数据包来决定是否应答ARP请求(因此,这需要使用基于源的路由来实现)。换句话说,它允许控制哪些网卡(通常是一个)将响应ARP请求。 0 - (默认)内核可以用其他接口的地址来响应ARP请求。这看似不正确,但通常是有意义的,因为它增加了成功通信的机会。在Linux上,IP地址是由整个主机拥有的,而不是特定的接口拥有。只有在更复杂的设置中,如负载均衡,这种行为才会引起问题。如果设置了conf/{all,interface}/arp_filter中的至少一个为TRUE,那么该接口的arp_filter将被启用,否则将被禁用 验证 还是使用负载均衡的环境, rs1地址 # ip netns exec rs1 ip a 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 10.1.1.10/32 scope global lo valid_lft forever preferred_lft forever 264: veth-rs1@if263: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:11:22:33:44:99 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.1.1.13/24 scope global veth-rs1 valid_lft forever preferred_lft forever inet 10.1.1.11/24 scope global secondary veth-rs1 valid_lft forever preferred_lft forever 271: veth-rs1-extra@if270: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 66:82:27:71:76:15 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 172.168.1.3/24 scope global veth-rs1-extra valid_lft forever preferred_lft foreversshezh 设置arp_ignore, arp_filter为默认值0 ...

2024-06-23 · 2 min · 242 words

linux arp 参数整理

linux arp相关参数 在 Linux 中,有多个内核参数可以控制 ARP(地址解析协议)的行为。这些参数可以通过 /proc/sys/net/ipv4/conf/*/ 目录下的文件来配置,或者使用 sysctl 命令来设置。以下是一些常用的 ARP 内核参数及其含义: arp_ignore: 控制系统对不同网络接口上收到的 ARP 请求的响应行为。 取值范围: 0:在任何网络接口上收到 ARP 请求时,系统都会进行响应(默认值)。 1:只有当目标 IP 地址在收到请求的网络接口上配置时,系统才会响应。 2:只有当目标 IP 地址是最接近请求源的地址时,系统才会响应 arp_announce: 控制系统在发送 ARP 请求时,源 IP 地址的选择策略。 取值范围: 0 (默认): 允许使用任意网卡上的 IP 地址作为 ARP 请求的源 IP 地址。通常情况下,会使用 IP 数据包的源 IP。 1: 尽量避免使用不属于该发送网卡子网的本地地址作为发送 ARP 请求的源 IP 地址。 2: 忽略 IP 数据包的源 IP 地址,选择该发送网卡上最合适的本地地址作为 ARP 请求的源 IP 地址。 arp_accept: 控制系统GARP处理,当IP不在ARP表中。(GARP的源地址和目标地址一样), 如果存在直接更新不会判断这个标志 取值范围: 0 (默认值): 始终接受 GARP 数据包并相应地更新 ARP 表。即使 GARP 数据包包含未分配给其任何接口的 IP 地址,系统也会更新其 ARP 缓存。 1: 仅当数据包中的源 IP 地址与分配给系统接口之一的 IP 地址匹配时,才接受 GARP 数据包。这是一种更保守的方法,因为它只更新系统实际使用的地址的 ARP 缓存。 2:(自 Linux 内核 v6.0起)仅当源 IP 地址与接收数据包的接口位于同一子网时,才接受 GARP 数据包。这通过确保仅从同一网络上的设备接受 GARP 数据包来增加另一层安全性。 arp_notify; ...

2024-06-22 · 10 min · 1959 words

负载均衡

负载均衡的定义 In computing, load balancing is the process of distributing a set of tasks over a set of resources (computing units), with the aim of making their overall processing more efficient. Load balancing can optimize response time and avoid unevenly overloading some compute nodes while other compute nodes are left idle. Load balancing is the subject of research in the field of parallel computers. Two main approaches exist: static algorithms, which do not take into account the state of the different machines, and dynamic algorithms, which are usually more general and more efficient but require exchanges of information between the different computing units, at the risk of a loss of efficiency. ...

2024-06-02 · 7 min · 1334 words

VLAN

VLAN A virtual local area network (VLAN) is any broadcast domain that is partitioned and isolated in a computer network at the data link layer (OSI layer 2).[2][3] In this context, virtual refers to a physical object recreated and altered by additional logic, within the local area network. VLANs work by applying tags to network frames and handling these tags in networking systems – creating the appearance and functionality of network traffic that is physically on a single network but acts as if it is split between separate networks. In this way, VLANs can keep network applications separate despite being connected to the same physical network, and without requiring multiple sets of cabling and networking devices to be deployed. ...

2024-05-05 · 27 min · 5562 words