【发布时间】:2016-08-11 12:43:21
【问题描述】:
我使用SSL_CTX_use_certificate( SSL_CTX *ctx, X509 *x ) 将证书存储到SSL_CTX *ctx。
它被存储在ctx->cert->key->x509的SSL_CTX对象中
是否有任何 API 可以从 SSL_CTX 返回?
【问题讨论】:
我使用SSL_CTX_use_certificate( SSL_CTX *ctx, X509 *x ) 将证书存储到SSL_CTX *ctx。
它被存储在ctx->cert->key->x509的SSL_CTX对象中
是否有任何 API 可以从 SSL_CTX 返回?
【问题讨论】:
老问题,但在这里发布以供参考,因为我浪费了几个小时来解决这个问题。
以下是从 SSL_CTX* 获取证书并检查证书剩余有效期(和秒数)的示例:
X509 *x509 = SSL_CTX_get0_certificate(ssl_ctx);
const ASN1_TIME* notAfter = X509_getm_notAfter(x509);
int remaining_days=0, remaining_seconds = 0;
int result = ASN1_TIME_diff(&remaining_days, &remaining_seconds, NULL, notAfter);
std::cout << "remaining days: " << remaining_days << std::endl;
std::cout << "remaining seconds: " << remaining_seconds << std::endl;
它使用的是 OpenSSL 1.1
【讨论】:
X509 *SSL_get_peer_certificate(const SSL *ssl);SSL_get_peer_certificate() 返回指向对等方提供的 X509 证书的指针。
X509 *SSL_get_certificate(const SSL *ssl); 函数返回一个 X.509 类型的指针,指向 SSL 结构中加载的证书。
上面的定义和你在回答中提到的一样简单
X509 *SSL_get_certificate(const SSL *s)
{
if (s->cert != NULL)
return(s->cert->key->x509);
else
return(NULL);
}
以下是更多信息的参考链接 https://www.openssl.org/docs/manmaster/ssl/ssl.html
【讨论】:
SSL_ctx 对象和x509 * 证书所在的索引,为什么你需要一个API?另一方面,SSL 会话对象可以从SSl_ctx 对象获取证书