1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

x509: support DER recovery

This commit is contained in:
Andreas Weigel 2021-03-13 07:18:56 +00:00 committed by Andy Green
parent 108b4608f4
commit 12d535f839
3 changed files with 34 additions and 0 deletions

View file

@ -42,6 +42,11 @@ enum lws_tls_cert_info {
* same tls backend, ie, OpenSSL or mbedTLS. The different backends
* produce different, incompatible representations for the same cert.
*/
LWS_TLS_CERT_INFO_DER_RAW,
/**< the certificate's raw DER representation. If it's too big,
* -1 is returned and the size will be returned in buf->ns.len.
* If the certificate cannot be found -1 is returned and 0 in
* buf->ns.len. */
};
union lws_tls_cert_info_results {

View file

@ -166,6 +166,19 @@ lws_tls_mbedtls_cert_info(mbedtls_x509_crt *x509, enum lws_tls_cert_info type,
}
break;
}
case LWS_TLS_CERT_INFO_DER_RAW:
buf->ns.len = (int)x509->raw.len;
if (len < x509->raw.len)
/*
* The buffer is too small and the attempt failed, but
* the required object length is in buf->ns.len
*/
return -1;
memcpy(buf->ns.name, x509->raw.p, x509->raw.len);
break;
default:
return -1;

View file

@ -164,6 +164,22 @@ lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type,
#endif
return 0;
}
case LWS_TLS_CERT_INFO_DER_RAW:
{
int der_len = i2d_X509(x509, NULL);
uint8_t *tmp = (uint8_t *)buf->ns.name;
buf->ns.len = der_len < 0 ? 0 : der_len;
if (der_len < 0 || (size_t)der_len > len)
return -1;
der_len = i2d_X509(x509, &tmp);
if (der_len < 0)
return -1;
return 0;
}
default:
return -1;
}