Pki: Extend GetCertificateInformation() with version, serial, signature algorithm, SANs

This commit is contained in:
Michael Friedrich 2020-02-17 17:44:10 +01:00
parent 24397fbee8
commit a91b9f2ddf
1 changed files with 23 additions and 6 deletions

View File

@ -13,6 +13,7 @@
#include "base/tcpsocket.hpp" #include "base/tcpsocket.hpp"
#include "base/json.hpp" #include "base/json.hpp"
#include "base/utility.hpp" #include "base/utility.hpp"
#include "base/convert.hpp"
#include "base/exception.hpp" #include "base/exception.hpp"
#include "remote/jsonrpc.hpp" #include "remote/jsonrpc.hpp"
#include <fstream> #include <fstream>
@ -321,6 +322,9 @@ String PkiUtility::GetCertificateInformation(const std::shared_ptr<X509>& cert)
BIO *out = BIO_new(BIO_s_mem()); BIO *out = BIO_new(BIO_s_mem());
String pre; String pre;
pre = "\n Version: " + Convert::ToString(GetCertificateVersion(cert));
BIO_write(out, pre.CStr(), pre.GetLength());
pre = "\n Subject: "; pre = "\n Subject: ";
BIO_write(out, pre.CStr(), pre.GetLength()); BIO_write(out, pre.CStr(), pre.GetLength());
X509_NAME_print_ex(out, X509_get_subject_name(cert.get()), 0, XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB); X509_NAME_print_ex(out, X509_get_subject_name(cert.get()), 0, XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB);
@ -337,11 +341,24 @@ String PkiUtility::GetCertificateInformation(const std::shared_ptr<X509>& cert)
BIO_write(out, pre.CStr(), pre.GetLength()); BIO_write(out, pre.CStr(), pre.GetLength());
ASN1_TIME_print(out, X509_get_notAfter(cert.get())); ASN1_TIME_print(out, X509_get_notAfter(cert.get()));
pre = "\n Serial: ";
BIO_write(out, pre.CStr(), pre.GetLength());
ASN1_INTEGER *asn1_serial = X509_get_serialNumber(cert.get());
for (int i = 0; i < asn1_serial->length; i++) {
BIO_printf(out, "%02x%c", asn1_serial->data[i], ((i + 1 == asn1_serial->length) ? '\n' : ':'));
}
pre = "\n Signature Algorithm: " + GetSignatureAlgorithm(cert);
BIO_write(out, pre.CStr(), pre.GetLength());
pre = "\n Subject Alt Names: " + GetSubjectAltNames(cert)->Join(" ");
BIO_write(out, pre.CStr(), pre.GetLength());
pre = "\n Fingerprint: "; pre = "\n Fingerprint: ";
BIO_write(out, pre.CStr(), pre.GetLength()); BIO_write(out, pre.CStr(), pre.GetLength());
unsigned char md[EVP_MAX_MD_SIZE]; unsigned char md[EVP_MAX_MD_SIZE];
unsigned int diglen; unsigned int diglen;
X509_digest(cert.get(), EVP_sha1(), md, &diglen); X509_digest(cert.get(), EVP_sha256(), md, &diglen);
char *data; char *data;
long length = BIO_get_mem_data(out, &data); long length = BIO_get_mem_data(out, &data);