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',只有在主题备用名称扩展不存在或不包含任何 DNS 名称时,才会考虑证书主题。这种行为与 RFC 2818(“通过 TLS 的 HTTP”)一致。

【If the 'subject' option is undefined or set to 'default', the certificate subject is only considered if the subject alternative name extension either does not exist or does not contain any DNS names. This behavior is consistent with RFC 2818 ("HTTP Over TLS").】

如果 '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.】