Mateusz Starzyk | 6c2e9b6 | 2021-05-19 17:54:54 +0200 | [diff] [blame] | 1 | #define MBEDTLS_ALLOW_PRIVATE_ACCESS |
| 2 | |
Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 3 | #include <stdint.h> |
| 4 | #include "mbedtls/x509_crt.h" |
| 5 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 6 | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
| 7 | { |
Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 8 | #ifdef MBEDTLS_X509_CRT_PARSE_C |
| 9 | int ret; |
| 10 | mbedtls_x509_crt crt; |
| 11 | unsigned char buf[4096]; |
| 12 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 13 | mbedtls_x509_crt_init(&crt); |
Przemek Stekiel | 774f9de | 2023-04-19 11:47:01 +0200 | [diff] [blame^] | 14 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 15 | psa_status_t status = psa_crypto_init(); |
| 16 | if (status != PSA_SUCCESS) { |
| 17 | goto exit; |
| 18 | } |
| 19 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 20 | ret = mbedtls_x509_crt_parse(&crt, Data, Size); |
Hanno Becker | 54ac185 | 2020-10-09 09:45:29 +0100 | [diff] [blame] | 21 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 22 | if (ret == 0) { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 23 | ret = mbedtls_x509_crt_info((char *) buf, sizeof(buf) - 1, " ", &crt); |
Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 24 | } |
Hanno Becker | 54ac185 | 2020-10-09 09:45:29 +0100 | [diff] [blame] | 25 | #else |
| 26 | ((void) ret); |
Hanno Becker | eb2efb0 | 2020-10-16 06:54:39 +0100 | [diff] [blame] | 27 | ((void) buf); |
Hanno Becker | 54ac185 | 2020-10-09 09:45:29 +0100 | [diff] [blame] | 28 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ |
Przemek Stekiel | 774f9de | 2023-04-19 11:47:01 +0200 | [diff] [blame^] | 29 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 30 | mbedtls_x509_crt_free(&crt); |
Przemek Stekiel | 774f9de | 2023-04-19 11:47:01 +0200 | [diff] [blame^] | 31 | mbedtls_psa_crypto_free(); |
Philippe Antoine | 7233352 | 2018-05-03 16:40:24 +0200 | [diff] [blame] | 32 | #else |
| 33 | (void) Data; |
| 34 | (void) Size; |
| 35 | #endif |
| 36 | |
| 37 | return 0; |
| 38 | } |