gpt4 book ai didi

c++ - 将 SSL 证书字符串转换为有效的 X509_STORE_CTX

转载 作者:行者123 更新时间:2023-11-30 01:53:30 25 4
gpt4 key购买 nike

我试图将这两个证书都放入 X509_STORE_CTX,但是当我读出它们时,它们都是 NULL。有什么想法吗?

证书看起来像:

// Not the real certs. Just trying to illustrate that the certs are just a new line
// delimited string
const char *certA = "-----BEGIN CERTIFICATE-----\nMIIGWDCCBUCgAwI......\n.....\n"

SSL_library_init();
SSL_CTX * sslCtx = SSL_CTX_new(SSLv23_client_method());
X509_STORE *store = SSL_CTX_get_cert_store(sslCtx);
X509_STORE_CTX *store_ctx = X509_STORE_CTX_new();

BIO *bio;
X509 *certificate;

/*First cert*/
bio = BIO_new(BIO_s_mem());
BIO_write(bio,(const void*)certA ,sizeof(certA));
certificate = PEM_read_bio_X509(bio, NULL, NULL, NULL);
X509_STORE_add_cert(store, certificate);

/*second cert*/
bio = BIO_new(BIO_s_mem());
BIO_write(bio,(const void*)certB ,sizeof(certB));
certificate = PEM_read_bio_X509(bio, NULL, NULL, NULL);
X509_STORE_add_cert(store, certificate);

X509_STORE_CTX_init(store_ctx, store, NULL, NULL);

最佳答案

sizeof(certA) 此处将仅提供该 const char* 变量的大小,即指针的大小(主要是 4 或 8)。

尝试将证书内容声明为 static const char certA[]

同时使用 BIO_puts()并且完全避免 sizeof() 可能更容易。

关于c++ - 将 SSL 证书字符串转换为有效的 X509_STORE_CTX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23122376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com