/src/gnutls/fuzz/gnutls_srp_client_fuzzer.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2017 Nikos Mavrogiannopoulos |
3 | | * |
4 | | * Permission is hereby granted, free of charge, to any person obtaining a |
5 | | * copy of this software and associated documentation files (the "Software"), |
6 | | * to deal in the Software without restriction, including without limitation |
7 | | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8 | | * and/or sell copies of the Software, and to permit persons to whom the |
9 | | * Software is furnished to do so, subject to the following conditions: |
10 | | * |
11 | | * The above copyright notice and this permission notice shall be included in |
12 | | * all copies or substantial portions of the Software. |
13 | | * |
14 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17 | | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
19 | | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | | * DEALINGS IN THE SOFTWARE. |
21 | | * |
22 | | */ |
23 | | |
24 | | #include <assert.h> |
25 | | #include <fcntl.h> |
26 | | #include <stdint.h> |
27 | | #include <sys/types.h> |
28 | | #include <unistd.h> |
29 | | #include <string.h> |
30 | | #include <stdlib.h> |
31 | | |
32 | | #include <gnutls/gnutls.h> |
33 | | |
34 | | #include "srp.h" |
35 | | #include "mem.h" |
36 | | #include "fuzzer.h" |
37 | | |
38 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
39 | 10.3k | { |
40 | 10.3k | int res; |
41 | 10.3k | gnutls_session_t session; |
42 | 10.3k | gnutls_srp_client_credentials_t pcred; |
43 | 10.3k | struct mem_st memdata; |
44 | | |
45 | 10.3k | res = gnutls_init(&session, GNUTLS_CLIENT); |
46 | 10.3k | assert(res >= 0); |
47 | | |
48 | 10.3k | res = gnutls_srp_allocate_client_credentials(&pcred); |
49 | 10.3k | assert(res >= 0); |
50 | | |
51 | 10.3k | res = gnutls_srp_set_client_credentials(pcred, USERNAME, PASSWORD); |
52 | 10.3k | assert(res >= 0); |
53 | | |
54 | 10.3k | res = gnutls_credentials_set(session, GNUTLS_CRD_SRP, pcred); |
55 | 10.3k | assert(res >= 0); |
56 | | |
57 | 10.3k | res = gnutls_priority_set_direct( |
58 | 10.3k | session, "NORMAL:-KX-ALL:+SRP:+SRP-RSA:+SRP-DSS", NULL); |
59 | 10.3k | assert(res >= 0); |
60 | | |
61 | 10.3k | memdata.data = data; |
62 | 10.3k | memdata.size = size; |
63 | | |
64 | 10.3k | gnutls_transport_set_push_function(session, mem_push); |
65 | 10.3k | gnutls_transport_set_pull_function(session, mem_pull); |
66 | 10.3k | gnutls_transport_set_pull_timeout_function(session, mem_pull_timeout); |
67 | 10.3k | gnutls_transport_set_ptr(session, &memdata); |
68 | 10.3k | gnutls_srp_set_prime_bits(session, 1024); |
69 | | |
70 | 330k | do { |
71 | 330k | res = gnutls_handshake(session); |
72 | 330k | } while (res < 0 && gnutls_error_is_fatal(res) == 0); |
73 | 10.3k | if (res >= 0) { |
74 | 1 | for (;;) { |
75 | 1 | char buf[16384]; |
76 | 1 | res = gnutls_record_recv(session, buf, sizeof(buf)); |
77 | 1 | if (res <= 0) { |
78 | 1 | break; |
79 | 1 | } |
80 | 1 | } |
81 | 1 | } |
82 | | |
83 | 10.3k | gnutls_deinit(session); |
84 | 10.3k | gnutls_srp_free_client_credentials(pcred); |
85 | 10.3k | return 0; |
86 | 10.3k | } |