在实验室中学习 openssl,因此这里没有什么私密内容。我按照以下所述创建,但应用程序抱怨服务器密钥无效。
有人能验证一下吗?然后我就可以联系应用程序供应商了。
创建默认的根 CA 证书设置:
==========================================
cat > ca.cnf <<EOF
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
prompt = yes
[ req_distinguished_name ]
emailAddress = Email Address
CN = Common Name
OU = Organizational Unit
O = Organization
L = Locality
ST = State or Province name
PC = Postal Code
C = Country
[ v3_ca ]
basicConstraints = critical,CA:true
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
EOF
生成根 CA 证书:
==============================
openssl req -new -x509 -newkey rsa:4096 -keyout ca.key -days 365 -out ca.crt -config ca.cnf
产量:
-----BEGIN CERTIFICATE-----
MIIFuTCCA6GgAwIBAgIUaKkDjsxR4Lg9tW8+L4a8GyVJb6kwDQYJKoZIhvcNAQEL
BQAwZDEQMA4GA1UEAwwHbWlraWVDQTELMAkGA1UECwwCSVQxDDAKBgNVBAoMA0JD
UzEUMBIGA1UEBwwLTWlubmVhcG9saXMxEjAQBgNVBAgMCU1pbm5lc290YTELMAkG
A1UEBhMCVVMwHhcNMjQwNDI5MTYxNjIzWhcNMjUwNDI5MTYxNjIzWjBkMRAwDgYD
VQQDDAdtaWtpZUNBMQswCQYDVQQLDAJJVDEMMAoGA1UECgwDQkNTMRQwEgYDVQQH
DAtNaW5uZWFwb2xpczESMBAGA1UECAwJTWlubmVzb3RhMQswCQYDVQQGEwJVUzCC
AiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBALU4Qoqyec+HupBScgPsa53q
5F0uf2OTYXKNEqjD8w+14zKBI/u1svJ89bTh1fEebRo8VwyKzuBBUpVvHUp6f0O7
8GrmNSEJp+0E61U8ak0ZcFeeC2Dpl3z+V5Za5SB6WxxwNMWdNSJX0v4gMjNx9a24
TUZt0FevTkKaMYjAF1vcQ5EPqCz7xLfgJ1JwK+RVqsAB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+TbTqWX7Mj8dko/Sq9eLQ6YN4dGxbuAU9NZg3mFBK8GO3gKcmDjliPaGxjYM/
/MCPkuOBr4ZdEDVc7ZzEt/4CqLa5hsdNZoNW9pQFstP3beNLU2qlmKEmKakWHR+0
lN9vxTF/vxY+vCwvY0vwksc9C9h34d+4hkK9yAiq1ZpmrZK3WC1bumfMH6VzAtPW
y7PUTRGtD+CYSm3JyQHE7F0G/85T2JEHST3Zqt5Rsr2o+57E6gqs9Q6wbqfMgFY4
DyiT0veqWmgrK/kmnWH6KoS+o5rcDQ0Jjjd9GIE=
-----END CERTIFICATE-----
为服务器证书生成 CSR:
=====================================
cat > server.v3.ext <<EOF
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "OpenSSL Generated Server Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
EOF
openssl req -newkey rsa:2048 -nodes -keyout server.key -days 365 -out server.csr
生成服务器证书并使用 RootCA 签名:
===================================================
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -out server.crt -CAcreateserial -sha256 -days 365 -extfile server.v3.ext
产量:
-----BEGIN CERTIFICATE-----
MIIFnjCCA4agAwIBAgIUeuOmldkVaOd+H8OK4BEoQko4hQYwDQYJKoZIhvcNAQEL
BQAwZDEQMA4GA1UEAwwHbWlraWVDQTELMAkGA1UECwwCSVQxDDAKBgNVBAoMA0JD
UzEUMBIGA1UEBwwLTWlubmVhcG9saXMxEjAQBgNVBAgMCU1pbm5lc290YTELMAkG
A1UEBhMCVVMwHhcNMjQwNDI5MTYzNTI0WhcNMjUwNDI5MTYzNTI0WjBrMQswCQYD
VQQGEwJVUzESMBAGA1UECAwJTWlubmVzb3RhMRQwEgYDVQQHDAtNaW5uZWFwb2xp
czEMMAoGA1UECgwDQkNTMQswCQYDVQQLDAJJVDEXMBUGA1UEAwwOMTkyLjE2OC4x
MC4xMDIwggEiMA0GCSqGSIb3DQEB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