提交 d628885e 编写于 作者: D Dr. Stephen Henson

Simplify ssl_add_cert_chain logic.

上级 ab0f8804
...@@ -1113,50 +1113,40 @@ static int ssl_add_cert_to_buf(BUF_MEM *buf, unsigned long *l, X509 *x) ...@@ -1113,50 +1113,40 @@ static int ssl_add_cert_to_buf(BUF_MEM *buf, unsigned long *l, X509 *x)
int ssl_add_cert_chain(SSL *s, CERT_PKEY *cpk, unsigned long *l) int ssl_add_cert_chain(SSL *s, CERT_PKEY *cpk, unsigned long *l)
{ {
BUF_MEM *buf = s->init_buf; BUF_MEM *buf = s->init_buf;
int no_chain;
int i; int i;
X509 *x; X509 *x;
STACK_OF(X509) *extra_certs; STACK_OF(X509) *extra_certs;
X509_STORE *chain_store; X509_STORE *chain_store;
if (cpk) /* TLSv1 sends a chain with nothing in it, instead of an alert */
x = cpk->x509; if (!BUF_MEM_grow_clean(buf,10))
else {
x = NULL; SSLerr(SSL_F_SSL_ADD_CERT_CHAIN,ERR_R_BUF_LIB);
return 0;
}
if (s->cert->chain_store) if (!cpk || !cpk->x509)
chain_store = s->cert->chain_store; return 1;
else
chain_store = s->ctx->cert_store; x = cpk->x509;
/* If we have a certificate specific chain use it, else use /* If we have a certificate specific chain use it, else use
* parent ctx. * parent ctx.
*/ */
if (cpk && cpk->chain) if (cpk->chain)
extra_certs = cpk->chain; extra_certs = cpk->chain;
else else
extra_certs = s->ctx->extra_certs; extra_certs = s->ctx->extra_certs;
if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs) if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs)
no_chain = 1; chain_store = NULL;
else if (s->cert->chain_store)
chain_store = s->cert->chain_store;
else else
no_chain = 0; chain_store = s->ctx->cert_store;
/* TLSv1 sends a chain with nothing in it, instead of an alert */ if (chain_store)
if (!BUF_MEM_grow_clean(buf,10))
{
SSLerr(SSL_F_SSL_ADD_CERT_CHAIN,ERR_R_BUF_LIB);
return 0;
}
if (x != NULL)
{
if (no_chain)
{
if (!ssl_add_cert_to_buf(buf, l, x))
return 0;
}
else
{ {
X509_STORE_CTX xs_ctx; X509_STORE_CTX xs_ctx;
...@@ -1180,14 +1170,17 @@ int ssl_add_cert_chain(SSL *s, CERT_PKEY *cpk, unsigned long *l) ...@@ -1180,14 +1170,17 @@ int ssl_add_cert_chain(SSL *s, CERT_PKEY *cpk, unsigned long *l)
} }
X509_STORE_CTX_cleanup(&xs_ctx); X509_STORE_CTX_cleanup(&xs_ctx);
} }
} else
{
if (!ssl_add_cert_to_buf(buf, l, x))
return 0;
for (i=0; i<sk_X509_num(extra_certs); i++) for (i=0; i<sk_X509_num(extra_certs); i++)
{ {
x=sk_X509_value(extra_certs,i); x=sk_X509_value(extra_certs,i);
if (!ssl_add_cert_to_buf(buf, l, x)) if (!ssl_add_cert_to_buf(buf, l, x))
return 0; return 0;
} }
}
return 1; return 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册