我正在尝试从客户端证书中检索使用者备用名称。通过运行此命令,我可以看到SAN:
openssl x509 -noout -text -in certname.cert.pem
...
X509v3 Subject Alternative Name:
IP Address:10.10.10.10
在C文件中,我尝试检索客户端SAN,以便可以使用服务器IP对其进行验证。这是我的尝试:
cert = X509_STORE_CTX_get_current_cert(x509Ctx);
int i;
int san_names_nb = -1;
STACK_OF(GENERAL_NAME) *san_names = NULL;
// Try to extract the names within the SAN extension from the certificate
san_names = (GENERAL_NAME*)X509_get_ext_d2i((X509 *) cert, NID_subject_alt_name, NULL, NULL);
if (san_names == NULL)
{
return Error;
}
现在,我的代码返回错误,因为san_names为空。任何指导都将不胜感激。谢谢!
发布于 2019-09-26 11:18:00
OpenSSL命令本身将SAN设置为空
X509v3 Subject Alternative Name: **<BLANK>**
IP Address:10.10.10.10
您能否只打开证书并查看其中是否包含SAN。如果没有,您将不得不要求团队添加SAN并再次创建新证书。
发布于 2019-09-26 17:40:00
您滥用了X509_get_ext_d2i()
。每个the OpenSSL documentation for X509_get_ext_d2i()
(加粗矿):
如果
idx
为NULL
,则只允许一个扩展出现一次,否则将返回索引*idx
之后的第一个扩展,并将*idx
更新到扩展的位置。
根据您使用的OpenSSL版本的不同,行为可能会略有不同。以上是记录在OpenSSL 1.1.0中的行为。
由于您将NULL
作为idx
传递,因此如果证书上有多个SAN,您将从X509_get_ext_d2i()
获得NULL
。
您可以使用ERR_get_error()
获取OpenSSL错误代码。
https://stackoverflow.com/questions/57928935
复制相似问题