kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/crt_bundle_bad_md' into 'master'
esp_crt_bundle: allow weak hash algorithm for trusted certificate Closes IDFGH-4266 See merge request espressif/esp-idf!11376pull/6275/head
commit
bf294fd1ae
|
@ -41,7 +41,6 @@ typedef struct crt_bundle_t {
|
||||||
|
|
||||||
static crt_bundle_t s_crt_bundle;
|
static crt_bundle_t s_crt_bundle;
|
||||||
|
|
||||||
static int esp_crt_verify_callback(void *buf, mbedtls_x509_crt *crt, int data, uint32_t *flags);
|
|
||||||
static int esp_crt_check_signature(mbedtls_x509_crt *child, const uint8_t *pub_key_buf, size_t pub_key_len);
|
static int esp_crt_check_signature(mbedtls_x509_crt *child, const uint8_t *pub_key_buf, size_t pub_key_len);
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,11 +92,15 @@ cleanup:
|
||||||
* only verify the first untrusted link in the chain is signed by the
|
* only verify the first untrusted link in the chain is signed by the
|
||||||
* root certificate in the trusted bundle
|
* root certificate in the trusted bundle
|
||||||
*/
|
*/
|
||||||
int esp_crt_verify_callback(void *buf, mbedtls_x509_crt *crt, int data, uint32_t *flags)
|
int esp_crt_verify_callback(void *buf, mbedtls_x509_crt *crt, int depth, uint32_t *flags)
|
||||||
{
|
{
|
||||||
mbedtls_x509_crt *child = crt;
|
mbedtls_x509_crt *child = crt;
|
||||||
|
|
||||||
if (*flags != MBEDTLS_X509_BADCERT_NOT_TRUSTED) {
|
/* It's OK for a trusted cert to have a weak signature hash alg.
|
||||||
|
as we already trust this certificate */
|
||||||
|
uint32_t flags_filtered = *flags & ~(MBEDTLS_X509_BADCERT_BAD_MD);
|
||||||
|
|
||||||
|
if (flags_filtered != MBEDTLS_X509_BADCERT_NOT_TRUSTED) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ void esp_crt_bundle_detach(mbedtls_ssl_config *conf);
|
||||||
*/
|
*/
|
||||||
void esp_crt_bundle_set(const uint8_t *x509_bundle);
|
void esp_crt_bundle_set(const uint8_t *x509_bundle);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
|
set(TEST_CRTS "crts/server_cert_chain.pem"
|
||||||
|
"crts/prvtkey.pem"
|
||||||
|
"crts/server_cert_bundle"
|
||||||
|
"crts/bad_md_crt.pem"
|
||||||
|
"crts/wrong_sig_crt_esp32_com.pem"
|
||||||
|
"crts/correct_sig_crt_esp32_com.pem")
|
||||||
|
|
||||||
idf_component_register(SRC_DIRS "."
|
idf_component_register(SRC_DIRS "."
|
||||||
PRIV_INCLUDE_DIRS "."
|
PRIV_INCLUDE_DIRS "."
|
||||||
PRIV_REQUIRES cmock test_utils mbedtls libsodium
|
PRIV_REQUIRES cmock test_utils mbedtls libsodium
|
||||||
EMBED_TXTFILES server_cert_chain.pem prvtkey.pem server_cert_bundle)
|
EMBED_TXTFILES ${TEST_CRTS})
|
||||||
|
|
||||||
|
|
||||||
idf_component_get_property(mbedtls mbedtls COMPONENT_LIB)
|
idf_component_get_property(mbedtls mbedtls COMPONENT_LIB)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIGijCCBXKgAwIBAgIQAfUXR/1IrnlbCX0+CKqtnDANBgkqhkiG9w0BAQsFADBeMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMR0wGwYDVQQDExRHZW9UcnVzdCBSU0EgQ0EgMjAxODAeFw0yMDA2MTgwMDAwMDBaFw0yMjA5MDExMjAwMDBaMG4xCzAJBgNVBAYTAlVTMREwDwYDVQQIEwhOZXcgWW9yazERMA8GA1UEBxMITmV3IFlvcmsxIDAeBgNVBAoTF0FkYWZydWl0IEluZHVzdHJpZXMgT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fZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6KOqkqm57TH2H3eDJAkSnh6/DNFu1Qg==
|
||||||
|
-----END CERTIFICATE-----
|
|
@ -51,6 +51,15 @@ extern const uint8_t server_pk_end[] asm("_binary_prvtkey_pem_end");
|
||||||
extern const uint8_t server_cert_bundle_start[] asm("_binary_server_cert_bundle_start");
|
extern const uint8_t server_cert_bundle_start[] asm("_binary_server_cert_bundle_start");
|
||||||
extern const uint8_t server_cert_bundle_end[] asm("_binary_server_cert_bundle_end");
|
extern const uint8_t server_cert_bundle_end[] asm("_binary_server_cert_bundle_end");
|
||||||
|
|
||||||
|
extern const uint8_t bad_md_crt_pem_start[] asm("_binary_bad_md_crt_pem_start");
|
||||||
|
extern const uint8_t bad_md_crt_pem_end[] asm("_binary_bad_md_crt_pem_end");
|
||||||
|
|
||||||
|
extern const uint8_t wrong_sig_crt_pem_start[] asm("_binary_wrong_sig_crt_esp32_com_pem_start");
|
||||||
|
extern const uint8_t wrong_sig_crt_pem_end[] asm("_binary_wrong_sig_crt_esp32_com_pem_end");
|
||||||
|
|
||||||
|
extern const uint8_t correct_sig_crt_pem_start[] asm("_binary_correct_sig_crt_esp32_com_pem_start");
|
||||||
|
extern const uint8_t correct_sig_crt_pem_end[] asm("_binary_correct_sig_crt_esp32_com_pem_end");
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mbedtls_ssl_context ssl;
|
mbedtls_ssl_context ssl;
|
||||||
mbedtls_net_context listen_fd;
|
mbedtls_net_context listen_fd;
|
||||||
|
@ -71,6 +80,8 @@ typedef enum {
|
||||||
ESP_CRT_VALIDATE_FAIL,
|
ESP_CRT_VALIDATE_FAIL,
|
||||||
}esp_crt_validate_res_t;
|
}esp_crt_validate_res_t;
|
||||||
|
|
||||||
|
int esp_crt_verify_callback(void *buf, mbedtls_x509_crt *crt, int data, uint32_t *flags);
|
||||||
|
|
||||||
static const char *TAG = "cert_bundle_test";
|
static const char *TAG = "cert_bundle_test";
|
||||||
|
|
||||||
static volatile bool exit_flag;
|
static volatile bool exit_flag;
|
||||||
|
@ -328,3 +339,49 @@ TEST_CASE("custom certificate bundle", "[mbedtls]")
|
||||||
|
|
||||||
vSemaphoreDelete(exit_sema);
|
vSemaphoreDelete(exit_sema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("custom certificate bundle - weak hash", "[mbedtls]")
|
||||||
|
{
|
||||||
|
/* A weak signature hash on the trusted certificate should not stop
|
||||||
|
us from verifying the chain, since we already trust it a weak signature hash is
|
||||||
|
not a security issue */
|
||||||
|
|
||||||
|
mbedtls_x509_crt crt;
|
||||||
|
uint32_t flags = 0;
|
||||||
|
|
||||||
|
esp_crt_bundle_attach(NULL);
|
||||||
|
|
||||||
|
mbedtls_x509_crt_init( &crt );
|
||||||
|
mbedtls_x509_crt_parse(&crt, bad_md_crt_pem_start, bad_md_crt_pem_end - bad_md_crt_pem_start);
|
||||||
|
TEST_ASSERT(mbedtls_x509_crt_verify(&crt, NULL, NULL, NULL, &flags, esp_crt_verify_callback, NULL) == 0);
|
||||||
|
|
||||||
|
mbedtls_x509_crt_free(&crt);
|
||||||
|
|
||||||
|
esp_crt_bundle_detach(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("custom certificate bundle - wrong signature", "[mbedtls]")
|
||||||
|
{
|
||||||
|
/* Check that the bundle will not verify a valid certificate from trusted root where the signature is wrong */
|
||||||
|
|
||||||
|
mbedtls_x509_crt crt;
|
||||||
|
uint32_t flags = 0;
|
||||||
|
|
||||||
|
esp_crt_bundle_attach(NULL);
|
||||||
|
|
||||||
|
mbedtls_x509_crt_init( &crt );
|
||||||
|
/* esp32.com cert chain where 1 byte in the signature is changed */
|
||||||
|
printf("Testing certificate with wrong signature\n");
|
||||||
|
mbedtls_x509_crt_parse(&crt, wrong_sig_crt_pem_start, wrong_sig_crt_pem_end - wrong_sig_crt_pem_start);
|
||||||
|
TEST_ASSERT(mbedtls_x509_crt_verify(&crt, NULL, NULL, NULL, &flags, esp_crt_verify_callback, NULL) != 0);
|
||||||
|
mbedtls_x509_crt_free(&crt);
|
||||||
|
|
||||||
|
mbedtls_x509_crt_init( &crt );
|
||||||
|
/* the correct esp32.com cert chain*/
|
||||||
|
printf("Testing certificate with correct signature\n");
|
||||||
|
mbedtls_x509_crt_parse(&crt, correct_sig_crt_pem_start, correct_sig_crt_pem_end - correct_sig_crt_pem_start);
|
||||||
|
TEST_ASSERT(mbedtls_x509_crt_verify(&crt, NULL, NULL, NULL, &flags, esp_crt_verify_callback, NULL) == 0);
|
||||||
|
mbedtls_x509_crt_free(&crt);
|
||||||
|
|
||||||
|
esp_crt_bundle_detach(NULL);
|
||||||
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue