/src/gnutls/fuzz/gnutls_pkcs8_key_parser_fuzzer.c
Line | Count | Source |
1 | | /* |
2 | | # Copyright 2016 Nikos Mavrogiannopoulos |
3 | | # |
4 | | # Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | # you may not use this file except in compliance with the License. |
6 | | # You may obtain a copy of the License at |
7 | | # |
8 | | # https://www.apache.org/licenses/LICENSE-2.0 |
9 | | # |
10 | | # Unless required by applicable law or agreed to in writing, software |
11 | | # distributed under the License is distributed on an "AS IS" BASIS, |
12 | | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | # See the License for the specific language governing permissions and |
14 | | # limitations under the License. |
15 | | # |
16 | | ################################################################################ |
17 | | */ |
18 | | |
19 | | #include <assert.h> |
20 | | #include <stdint.h> |
21 | | |
22 | | #include <gnutls/gnutls.h> |
23 | | #include <gnutls/x509.h> |
24 | | |
25 | | #include "fuzzer.h" |
26 | | |
27 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
28 | 11.5k | { |
29 | 11.5k | gnutls_datum_t raw; |
30 | 11.5k | gnutls_x509_privkey_t key; |
31 | 11.5k | gnutls_datum_t out; |
32 | 11.5k | int ret; |
33 | | |
34 | 11.5k | raw.data = (unsigned char *)data; |
35 | 11.5k | raw.size = size; |
36 | | |
37 | 11.5k | ret = gnutls_x509_privkey_init(&key); |
38 | 11.5k | assert(ret >= 0); |
39 | | |
40 | 11.5k | ret = gnutls_x509_privkey_import_pkcs8(key, &raw, GNUTLS_X509_FMT_DER, |
41 | 11.5k | "password", 0); |
42 | 11.5k | if (ret < 0) { |
43 | 8.06k | goto cleanup; |
44 | 8.06k | } |
45 | | |
46 | | /* If properly loaded, try to re-export */ |
47 | 3.47k | ret = gnutls_x509_privkey_export2(key, GNUTLS_X509_FMT_DER, &out); |
48 | 3.47k | if (ret < 0) { |
49 | 69 | goto cleanup; |
50 | 69 | } |
51 | | |
52 | 3.40k | gnutls_free(out.data); |
53 | | |
54 | 11.5k | cleanup: |
55 | 11.5k | gnutls_x509_privkey_deinit(key); |
56 | 11.5k | return 0; |
57 | 3.40k | } |