x509.checkHost(name[, options])


  • name <string>
  • options <Object>
    • subject <string> 'default'、'always' 或 'never'。 默认值: 'default'。
    • wildcards <boolean> 默认: true。
    • partialWildcards <boolean> 默认: true。
    • multiLabelWildcards <boolean> 默认: false。
    • singleLabelSubdomains <boolean> 默认: false。
  • 返回:<string> | <undefined> 返回匹配 name 的主题名称,如果没有主题名称匹配 name,则返回 undefined。

检查证书是否与给定的主机名匹配。

🌐 Checks whether the certificate matches the given host name.

如果证书与给定的主机名匹配,则会返回匹配的主题名称。返回的名称可能是完全匹配(例如,foo.example.com),也可能包含通配符(例如,*.example.com)。由于主机名比较不区分大小写,返回的主题名称在大小写上可能也与给定的 name 不同。

🌐 If the certificate matches the given host name, the matching subject name is returned. The returned name might be an exact match (e.g., foo.example.com) or it might contain wildcards (e.g., *.example.com). Because host name comparisons are case-insensitive, the returned subject name might also differ from the given name in capitalization.

如果 'subject' 选项未定义或设置为 'default',证书主题将按照 OpenSSL 的默认行为来考虑。

🌐 If the 'subject' option is undefined or set to 'default', the certificate subject is considered according to OpenSSL's default behavior.

如果 'subject' 选项设置为 'always',并且主题备用名称扩展不存在或不包含匹配的 DNS 名称,则会考虑证书主题。

🌐 If the 'subject' option is set to 'always' and if the subject alternative name extension either does not exist or does not contain a matching DNS name, the certificate subject is considered.

如果将 'subject' 选项设置为 'never',则不会考虑证书主题,即使证书不包含任何主题备用名称。

🌐 If the 'subject' option is set to 'never', the certificate subject is never considered, even if the certificate contains no subject alternative names.