Skip to content

Commit

Permalink
get0 was introduced in 3.0.0 so we can't use it
Browse files Browse the repository at this point in the history
  • Loading branch information
dormando committed Jul 25, 2024
1 parent 6568d38 commit 5194205
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,30 @@ const unsigned char *ssl_get_peer_cn(conn *c, int *len) {
return NULL;
}

// get0 to avoid getting a reference.
X509 *cert = SSL_get0_peer_certificate(c->ssl);
// can't use get0 to avoid getting a reference since that requires 3.0.0+
X509 *cert = SSL_get_peer_certificate(c->ssl);
if (cert == NULL) {
return NULL;
}
X509_NAME *name = X509_get_subject_name(cert);
if (name == NULL) {
X509_free(cert);
return NULL;
}

int r = X509_NAME_get_index_by_NID(name, NID_commonName, -1);
if (r == -1) {
X509_free(cert);
return NULL;
}
ASN1_STRING *asn1 = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, r));

if (asn1 == NULL) {
X509_free(cert);
return NULL;
}
*len = ASN1_STRING_length(asn1);
X509_free(cert);
return ASN1_STRING_get0_data(asn1);
}

Expand Down

0 comments on commit 5194205

Please sign in to comment.