2013-04-12 115 views

回答

2

您可以使用此功能X509_NAME_delete_entry()

X509_NAME_delete_entry()删除名称在位置LOC的条目。 已删除的条目被返回并且必须被释放。

手册页:http://linux.die.net/man/3/x509_name_delete_entry

编辑:

实际得到和删除扩展,可以使用以下功能:

X509_EXTENSION *X509_delete_ext(X509 *x, int loc); 

例子:

int idx = X509_get_ext_by_NID(cert, nid, -1); //get the index 
X509_EXTENSION *ext = X509_get_ext(cert, idx); //get the extension 
if (ext != NULL){ //check that the extension was found 
    X509_delete_ext(cert, idx); //delete the extension 
    X509_EXTENSION_free(ext); //free the memory 
} 
+0

这就是专有名称,不是吗? subjectNameAlt不是可分辨名称的一部分,它是x509v3扩展的一部分。 – chacham15

+0

是的,你是对的。 X509_NAME_delete_entry()仅适用于证书信息字段。 – Paul

+0

用示例说明如何使用证书扩展来更新我的评论。希望能帮助到你 ! – Paul

0

chacham15的回答是不正确的。如上所述通过the documentation

X509v3_get_ext() [和X509_get_ext()]从x检索扩展同上。 索引loc可以取0到X509_get_ext_count(x) - 1之间的任何值。 返回的扩展名是一个内部指针,其一定不能是 由应用程序释放。

释放扩展名的正确方法如下。

int idx = X509_get_ext_by_NID(cert, nid, -1); //get the index 
X509_EXTENSION *ext = X509_get_ext(cert, idx); //get the extension 
if (ext != NULL){ //check that the extension was found 
    X509_EXTENSION *tmp = X509_delete_ext(cert, idx); //delete the extension 
    X509_EXTENSION_free(tmp); //free the memory 
} 
+0

chacham的回答在4年前正确吗? –

+0

我很困惑...你写的'正确'的方式看起来与标记答案中的例子完全相同。 – chacham15