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