Skip to content

Commit

Permalink
Use X509View
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Jan 16, 2025
1 parent 42d41cf commit 9cb41b0
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,32 @@ std::string getX509Name(X509_NAME* x509_name) {
return strResult;
}

char* bioToCString(BIOPointer* bio) {
const int len = BIO_pending(bio->get());
char* result = reinterpret_cast<char *>(calloc(len + 1, 1));
BIO_read(bio->get(), result, len);

return result;
}

char* getIssuer(ncrypto::X509View x509_view) {
auto bio = x509_view.getIssuer();

return bioToCString(&bio);
}

char* getSubject(ncrypto::X509View x509_view) {
auto bio = x509_view.getSubject();

return bioToCString(&bio);
}

bool IsSelfSigned(X509* cert) {
auto issuerName = getX509Name(X509_get_issuer_name(cert));
auto subjectName = getX509Name(X509_get_subject_name(cert));
ncrypto::X509View x509_view(cert);
auto subject = getSubject(x509_view);
auto issuer = getIssuer(x509_view);

if (issuerName == subjectName) {
if (strcmp(subject, issuer) == 0) {
return true;
} else {
return false;
Expand Down

0 comments on commit 9cb41b0

Please sign in to comment.