2016-07-29 183 views
2

我正在嘗試使用openssl進行使用X509_verify_cert進行證書鏈驗證。我正在獲取所有證書 - 根證書,中間證書和實際需要驗證的子證書。 使用openssl我能夠轉換X509格式的證書。如何在X509_STORE_CTX_init中設置鏈參數?

X509_STORE_CTX *ctx; 
ctx = X509_STORE_CTX_new(); 
X509_STORE *store = X509_STORE_new(); 
X509_STORE_CTX_init(ctx, store, certificateX509, ?); 

int status = X509_verify_cert(ctx); 

一邊唸叨X509_STORE_CTX_init和X509_verify_cert文檔,我們需要通過證書鏈?在代碼中。在文檔中,X509_STORE_CTX_init方法的定義如下:

int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, 
         X509 *x509, STACK_OF(X509) *chain); 
# define STACK_OF(type) struct stack_st_##type 

如何通過證書鏈,如果我在X509格式的所有證書嗎? 任何代碼片段可能會幫助更多。

在此先感謝!

回答

0

這似乎工作: -

STACK_OF(X509) *chain = sk_X509_new_null(); 
sk_X509_push(chain, x509); 
X509_STORE_CTX_init(x509_ctx, x509_trusted, x509, chain); 
sk_X509_pop_free(obj->chain, X509_free);