2017-09-19 04:34:08 -04:00
|
|
|
|
2014-04-24 15:34:45 -04:00
|
|
|
// X509Cert.cpp
|
|
|
|
|
2017-08-30 10:00:06 -04:00
|
|
|
// Implements the cX509Cert class representing a wrapper over X509 certs in mbedTLS
|
2014-04-24 15:34:45 -04:00
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "X509Cert.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cX509Cert::cX509Cert(void)
|
|
|
|
{
|
2017-08-30 10:00:06 -04:00
|
|
|
mbedtls_x509_crt_init(&m_Cert);
|
2014-04-24 15:34:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cX509Cert::~cX509Cert()
|
|
|
|
{
|
2017-08-30 10:00:06 -04:00
|
|
|
mbedtls_x509_crt_free(&m_Cert);
|
2014-04-24 15:34:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cX509Cert::Parse(const void * a_CertContents, size_t a_Size)
|
|
|
|
{
|
2017-09-19 12:28:51 -04:00
|
|
|
// mbedTLS requires that PEM-encoded data is passed including the terminating NUL byte,
|
|
|
|
// and DER-encoded data is decoded properly even with an extra trailing NUL byte, so we simply add one to everything:
|
2018-05-02 03:50:36 -04:00
|
|
|
AString certContents(static_cast<const char *>(a_CertContents), a_Size);
|
2017-09-19 12:28:51 -04:00
|
|
|
return mbedtls_x509_crt_parse(&m_Cert, reinterpret_cast<const unsigned char *>(certContents.data()), a_Size + 1);
|
2014-04-24 15:34:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|