forked from espressif/esp-idf
components/openssl: add function to load certification or private key more than one time
This commit is contained in:
@@ -339,6 +339,16 @@ int x509_pm_new(X509 *x)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void x509_pm_unload(X509 *x)
|
||||||
|
{
|
||||||
|
struct x509_pm *x509_pm = (struct x509_pm *)x->x509_pm;
|
||||||
|
|
||||||
|
if (x509_pm->load)
|
||||||
|
mbedtls_x509_crt_free(&x509_pm->x509_crt);
|
||||||
|
|
||||||
|
x509_pm->load = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int x509_pm_load(X509 *x, const unsigned char *buffer, int len)
|
int x509_pm_load(X509 *x, const unsigned char *buffer, int len)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@@ -352,6 +362,8 @@ int x509_pm_load(X509 *x, const unsigned char *buffer, int len)
|
|||||||
ssl_memcpy(load_buf, buffer, len);
|
ssl_memcpy(load_buf, buffer, len);
|
||||||
load_buf[len] = '\0';
|
load_buf[len] = '\0';
|
||||||
|
|
||||||
|
x509_pm_unload(x);
|
||||||
|
|
||||||
mbedtls_x509_crt_init(&x509_pm->x509_crt);
|
mbedtls_x509_crt_init(&x509_pm->x509_crt);
|
||||||
ret = mbedtls_x509_crt_parse(&x509_pm->x509_crt, load_buf, len);
|
ret = mbedtls_x509_crt_parse(&x509_pm->x509_crt, load_buf, len);
|
||||||
ssl_free(load_buf);
|
ssl_free(load_buf);
|
||||||
@@ -367,15 +379,6 @@ failed1:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void x509_pm_unload(X509 *x)
|
|
||||||
{
|
|
||||||
struct x509_pm *x509_pm = (struct x509_pm *)x->x509_pm;
|
|
||||||
|
|
||||||
mbedtls_x509_crt_free(&x509_pm->x509_crt);
|
|
||||||
|
|
||||||
x509_pm->load = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void x509_pm_free(X509 *x)
|
void x509_pm_free(X509 *x)
|
||||||
{
|
{
|
||||||
x509_pm_unload(x);
|
x509_pm_unload(x);
|
||||||
@@ -396,6 +399,16 @@ int pkey_pm_new(EVP_PKEY *pkey)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pkey_pm_unload(EVP_PKEY *pkey)
|
||||||
|
{
|
||||||
|
struct pkey_pm *pkey_pm = (struct pkey_pm *)pkey->pkey_pm;
|
||||||
|
|
||||||
|
if (pkey_pm->load)
|
||||||
|
mbedtls_pk_free(&pkey_pm->pkey);
|
||||||
|
|
||||||
|
pkey_pm->load = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int pkey_pm_load(EVP_PKEY *pkey, const unsigned char *buffer, int len)
|
int pkey_pm_load(EVP_PKEY *pkey, const unsigned char *buffer, int len)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@@ -409,6 +422,8 @@ int pkey_pm_load(EVP_PKEY *pkey, const unsigned char *buffer, int len)
|
|||||||
ssl_memcpy(load_buf, buffer, len);
|
ssl_memcpy(load_buf, buffer, len);
|
||||||
load_buf[len] = '\0';
|
load_buf[len] = '\0';
|
||||||
|
|
||||||
|
pkey_pm_unload(pkey);
|
||||||
|
|
||||||
mbedtls_pk_init(&pkey_pm->pkey);
|
mbedtls_pk_init(&pkey_pm->pkey);
|
||||||
ret = mbedtls_pk_parse_key(&pkey_pm->pkey, load_buf, len, NULL, 0);
|
ret = mbedtls_pk_parse_key(&pkey_pm->pkey, load_buf, len, NULL, 0);
|
||||||
ssl_free(load_buf);
|
ssl_free(load_buf);
|
||||||
@@ -424,15 +439,6 @@ failed1:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pkey_pm_unload(EVP_PKEY *pkey)
|
|
||||||
{
|
|
||||||
struct pkey_pm *pkey_pm = (struct pkey_pm *)pkey->pkey_pm;
|
|
||||||
|
|
||||||
mbedtls_pk_free(&pkey_pm->pkey);
|
|
||||||
|
|
||||||
pkey_pm->load = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void pkey_pm_free(EVP_PKEY *pkey)
|
void pkey_pm_free(EVP_PKEY *pkey)
|
||||||
{
|
{
|
||||||
pkey_pm_unload(pkey);
|
pkey_pm_unload(pkey);
|
||||||
|
Reference in New Issue
Block a user