2013-04-12 135 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