【问题标题】:Subject Alternative Name Missing & ERR_SSL_VERSION_OR_CIPHER_MISMATCH主题备用名称缺失和 ERR_SSL_VERSION_OR_CIPHER_MISMATCH
【发布时间】:2017-10-11 06:48:51
【问题描述】:

我跟随this answer 使https://localhost:3000/ 在Chrome 和Mac 中工作。今天突然不行了。

https://localhost:3000Not Secure

Subject Alternative Name Missing
The certificate for this site does not contain a Subject Alternative Name extension containing a domain name or IP address.

我按照前面的步骤重新信任了此证书,但没有帮助。然后我看到this answer,关于重新制作 ssl 密钥。

所以我发了v3.ext:

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost

那么,

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -sha256 -extfile v3.ext

但是,它会返回

unknown option -extfile
req [options] <infile >outfile
where options  are
 -inform arg    input format - DER or PEM
 -outform arg   output format - DER or PEM
 ... ...

有人知道我的openssl 命令有什么问题吗?

否则,有人知道如何解决这个Subject Alternative Name MissingNET::ERR_CERT_COMMON_NAME_INVALID 错误吗?

编辑1:我尝试关注this answer,这是我的example-com.conf

[ req ]
default_bits        = 2048
default_keyfile     = server-key.pem
distinguished_name  = subject
req_extensions      = req_ext
x509_extensions     = x509_ext
string_mask         = utf8only

# The Subject DN can be formed using X501 or RFC 4514 (see RFC 4519 for a description).
#   Its sort of a mashup. For example, RFC 4514 does not provide emailAddress.
[ subject ]
countryName         = Country Name (2 letter code)
countryName_default     = US

stateOrProvinceName     = State or Province Name (full name)
stateOrProvinceName_default = NY

localityName            = Locality Name (eg, city)
localityName_default        = New York

organizationName         = Organization Name (eg, company)
organizationName_default    = Example, LLC

# Use a friendly name here because its presented to the user. The server's DNS
#   names are placed in Subject Alternate Names. Plus, DNS names here is deprecated
#   by both IETF and CA/Browser Forums. If you place a DNS name here, then you
#   must include the DNS name in the SAN too (otherwise, Chrome and others that
#   strictly follow the CA/Browser Baseline Requirements will fail).
commonName          = Common Name (e.g. server FQDN or YOUR name)
commonName_default      = Example Company

emailAddress            = Email Address
emailAddress_default        = test@example.com

# Section x509_ext is used when generating a self-signed certificate. I.e., openssl req -x509 ...
[ x509_ext ]

subjectKeyIdentifier        = hash
authorityKeyIdentifier  = keyid,issuer

# You only need digitalSignature below. *If* you don't allow
#   RSA Key transport (i.e., you use ephemeral cipher suites), then
#   omit keyEncipherment because that's key transport.
basicConstraints        = CA:FALSE
keyUsage            = digitalSignature, keyEncipherment
subjectAltName          = @alternate_names
nsComment           = "OpenSSL Generated Certificate"

# RFC 5280, Section 4.2.1.12 makes EKU optional
#   CA/Browser Baseline Requirements, Appendix (B)(3)(G) makes me confused
#   In either case, you probably only need serverAuth.
# extendedKeyUsage  = serverAuth, clientAuth

# Section req_ext is used when generating a certificate signing request. I.e., openssl req ...
[ req_ext ]

subjectKeyIdentifier        = hash

basicConstraints        = CA:FALSE
keyUsage            = digitalSignature, keyEncipherment
subjectAltName          = @alternate_names
nsComment           = "OpenSSL Generated Certificate"

# RFC 5280, Section 4.2.1.12 makes EKU optional
#   CA/Browser Baseline Requirements, Appendix (B)(3)(G) makes me confused
#   In either case, you probably only need serverAuth.
# extendedKeyUsage  = serverAuth, clientAuth

[ alternate_names ]

DNS.1       = localhost

# IPv4 localhost
IP.1       = 127.0.0.1

# IPv6 localhost
IP.2     = ::1

然后,我做到了

openssl req -config example-com.conf -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.cert.pem

在 Chrome 中重新打开 https://localhost:3000 给我

localhost uses an unsupported protocol.
ERR_SSL_VERSION_OR_CIPHER_MISMATCH

谁能帮忙?

【问题讨论】:

标签: google-chrome ssl openssl localhost ssl-certificate


【解决方案1】:

我建议以下解决方案:创建自签名 CA 证书和由该 CA 签名的 Web 服务器证书。当您将这个小链安装到您的网络服务器时,它将与 Chrome 一起使用。

使用内容为您的 CA MyCompanyCA.cnf 创建配置文件(您可以根据需要进行更改):

[ req ]
distinguished_name  = req_distinguished_name
x509_extensions     = root_ca

[ req_distinguished_name ]
countryName             = Country Name (2 letter code)
countryName_min         = 2
countryName_max         = 2
stateOrProvinceName     = State or Province Name (full name)
localityName            = Locality Name (eg, city)
0.organizationName      = Organization Name (eg, company)
organizationalUnitName  = Organizational Unit Name (eg, section)
commonName              = Common Name (eg, fully qualified host name)
commonName_max          = 64
emailAddress            = Email Address
emailAddress_max        = 64

[ root_ca ]
basicConstraints            = critical, CA:true

为您的 Web 服务器证书创建扩展配置文件 MyCompanyLocalhost.ext:

subjectAltName = @alt_names
extendedKeyUsage = serverAuth

[alt_names]
DNS.1   = localhost
DNS.2   = mypc.mycompany.com

然后执行以下命令:

openssl req -x509 -newkey rsa:2048 -out MyCompanyCA.cer -outform PEM -keyout MyCompanyCA.pvk -days 10000 -verbose -config MyCompanyCA.cnf -nodes -sha256 -subj "/CN=MyCompany CA"

openssl req -newkey rsa:2048 -keyout MyCompanyLocalhost.pvk -out MyCompanyLocalhost.req -subj /CN=localhost -sha256 -nodes
openssl x509 -req -CA MyCompanyCA.cer -CAkey MyCompanyCA.pvk -in MyCompanyLocalhost.req -out MyCompanyLocalhost.cer -days 10000 -extfile MyCompanyLocalhost.ext -sha256 -set_serial 0x1111

因此,您将获得可安装到 Web 服务器的 MyCompanyCA.cer、MyCompanyLocalhost.cer 和 MyCompanyLocalhost.pvk 文件。

在将证书安装到网络服务器之前,如何检查它是否适用于 Chrome。在本地 PC 上执行以下命令运行 Web 服务器模拟器:

openssl s_server -accept 15000 -cert MyCompanyLocalhost.cer -key MyCompanyLocalhost.pvk -CAfile MyCompanyCA.cer -WWW

然后您可以通过https://localhost:15000/访问此页面 如果您还想消除此错误,您将看到 MyCompanyLocalhost.cer 不受信任的错误 - 然后将 MyCompanyCA.cer 安装到操作系统的证书受信任列表中。

【讨论】:

  • 哇,它有效...谢谢!作为记录,在生成这些文件后,我将www 更改为var config = { key: fs.readFileSync('ssl/MyCompanyLocalhost.pvk'), cert: fs.readFileSync('ssl/MyCompanyLocalhost.cer') }。 Chrome首先给出了ERR_CERT_AUTHORITY_INVALID错误,然后我通过Keychain Access将该证书添加到login,它成功了!
  • Woahhh..我按照你的建议做了,在我挣扎了将近 5 个小时后,它就像一个魅力!!
  • 谢谢!浪费了几个小时寻找答案,但它做到了!
  • 希望我能投票一百万次,这是唯一对我有用的解决方案
  • 我可以确认这适用于 OSX 上最新的 Chrome 65。
【解决方案2】:

感谢 Oleg 提供了很好的解决方案。 在我的例子中,URI 被指定为 IP 地址而不是主机名, 最后,我从here得到了解决方案。

我编辑@Oleg 的MyCompanyLocalhost.ext,来自

subjectAltName = @alt_names
extendedKeyUsage = serverAuth

[alt_names]
DNS.1   = localhost
DNS.2   = mypc.mycompany.com

subjectAltName = @alt_names
extendedKeyUsage = serverAuth

[alt_names]

DNS.1 = domain.com 
# IP address
IP.1 = 192.168.2.221
IP.2 = 127.0.0.1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 2021-06-24
    • 2011-08-21
    相关资源
    最近更新 更多