OpenSSL command line tool to generate a self signed certificate.

创建 san.cnf

  • 配置文件,用于定义证书的详细信息,包括国家、组织、域名等。
  • 定义扩展属性,如 subjectAltName。
[ req ]
default_bits       = 256
default_md         = sha256
default_keyfile    = key.pem
prompt             = no
encrypt_key        = no
distinguished_name = dn
req_extensions     = req_ext
x509_extensions    = v3_ca

[ dn ]
C=HK
ST=Hong Kong
L=Hong Kong
O=Example Organization
OU=IT Department
emailAddress=contact@example.hk
CN = example.hk

[ req_ext ]
subjectAltName = @alt_names

[ v3_ca ]
subjectAltName = @alt_names

[ alt_names ]
IP.1 = 192.168.1.1
DNS.1 = example.hk

生成 ECDSA 私钥:

openssl ecparam -genkey -name prime256v1 -out ecdsa_private.key

生成证书签名请求 (CSR):

openssl req -new -key ecdsa_private.key -out ecdsa.csr -config san.cnf

生成自签名证书:

openssl x509 -req -in ecdsa.csr -signkey ecdsa_private.key -out ecdsa_certificate.crt -days 365 -extensions v3_ca -extfile san.cnf

自签名 ECDSA 证书和私钥就生成完成了

检查生成的证书:

openssl x509 -in ecdsa_certificate.crt -text -noout