Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: tls_get_issuer/subject return the info of the first loaded cert #80

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions src/tls/openssl/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,43 +1218,26 @@ static int convert_X509_NAME_to_mbuf(X509_NAME *field, struct mbuf *mb,
*
* @param tls TLS Object
* @param mb Memory buffer
* @param field_getter Functionpointer to the X509 getter functon
* @param field_getter Functionpointer to the X509 getter function
* @param flags X509_NAME_print_ex flags
*
* @return 0 if success, othewise errorcode
*/
static int tls_get_ca_chain_field(struct tls *tls, struct mbuf *mb,
tls_get_certfield_h *field_getter, unsigned long flags)
{
STACK_OF(X509) *certstack;
X509 *cert;
X509 *crt = NULL;
X509_NAME *field;
int err = EINVAL;

if (!field_getter)
crt = SSL_CTX_get0_certificate(tls->ctx);
if (!crt)
return EINVAL;

if (!SSL_CTX_get0_chain_certs(tls->ctx, &certstack) || !certstack)
goto out;

for (int i = 0; i < sk_X509_num(certstack); i++) {
cert = sk_X509_value(certstack, i);
if (!cert)
goto out;

field = field_getter(cert);
if (!field)
goto out;

err = convert_X509_NAME_to_mbuf(field, mb, flags);
if (err)
goto out;
}

err = 0;
field = field_getter(crt);
if (!field)
return EINVAL;

out:
return err;
return convert_X509_NAME_to_mbuf(field, mb, flags);
}


Expand Down