I need to test if a ECC certificate in PEM format is of good shape in C using the wolfssl library. I do not want to test any further information only if it is a certificate and not any random Base64 encoded bytes between the
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
lines. What is the easiest way to do so?
You can use the wolfSSL_X509_load_certificate_file
to check if it's a valid certificate, as shown in the example bellow.
You can find the function documentation here.
#include <wolfssl/openssl/x509.h>
int is_x509_cert(const char* pem_cert_file_path) {
WOLFSSL_X509 *cert = wolfSSL_X509_load_certificate_file(pem_cert_file_path, SSL_FILETYPE_PEM);
if (cert != NULL) {
wolfSSL_X509_free(cert);
return 1;
} else {
return 0;
}
}