x509.checkHost(name[, options])


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

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

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

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

如果 'subject' 选项设置为 'default',则仅当主题替代名称扩展不存在或不包含任何 DNS 名称时才考虑证书主题。 此行为与 RFC 2818 ("HTTP Over TLS") 一致。

如果 'subject' 选项设置为 'never',则从不考虑证书主题,即使证书不包含主题替代名称。

Checks whether the certificate matches the given host 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.

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.

If the 'subject' option is 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").

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