添加x509v3扩展会导致Mozilla pkix不信任

Adding x509v3 extension causes Mozilla pkix not to trust

本文关键字:Mozilla pkix 不信任 x509v3 扩展 添加      更新时间:2023-10-16

我正在通过NSS/NSPR c++ API添加自签名根证书。

这需要一个x509v3扩展,主题alt名称。但是,添加此扩展或任何x509v3扩展都会导致firefox无法使用Error code: sec_error_extension_value_invalid

// Add subjectAltName x509v3 extension containing our localhost IPv4
// address of 127.0.0.1.  The subjectAltName entry takes precedence over
// the CommonName (CN) entry, thus we are allowed to have a more
// descriptive name there. In addition, this is needed by Safari on Mac in
// order to properly trust the certificate.
X509V3_CTX ctx;
X509V3_set_ctx_nodb(&ctx);
X509V3_set_ctx(&ctx, m_x509, m_x509, nullptr, nullptr, 0);
// Removing this line causes the cert to be accepted by firefox:
X509_EXTENSION* ext = X509V3_EXT_conf_nid(nullptr, &ctx, NID_subject_alt_name, (char*)"DNS:127.0.0.1,IP:127.0.0.1");
if (ext) {
  X509_add_ext(m_x509, ext , -1);
  X509_EXTENSION_free(ext);
}
// Sign the certificate
X509_sign(m_x509, m_key->m_pkey, EVP_sha1());

这似乎是一个pkix错误,因为在about:config中设置use_mozillapkix_verification = false,或者使用ff <31、导致证书被接受

这是一个pkix错误吗?还是我们忽略了什么?

via https://bugzilla.mozilla.org/show_bug.cgi?id=1045973

NSS接受带有v3扩展名的v1/v2证书,mozilla::pkix不接受

解决办法:

X509_set_version(m_x509, 2L);

这个bug是在bugzilla上提交的,所以寻找答案的人可能想要检查这个bug的注释。