Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * EAP-SIM peer fuzzer |
| 3 | * Copyright (c) 2019, Jouni Malinen <j@w1.fi> |
| 4 | * |
| 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
| 7 | */ |
| 8 | |
| 9 | #include "utils/includes.h" |
| 10 | |
| 11 | #include "utils/common.h" |
| 12 | #include "eap_peer/eap_methods.h" |
| 13 | #include "eap_peer/eap_config.h" |
| 14 | #include "eap_peer/eap_i.h" |
| 15 | #include "../fuzzer-common.h" |
| 16 | |
| 17 | int eap_peer_sim_register(void); |
| 18 | |
| 19 | struct eap_method * registered_eap_method = NULL; |
| 20 | |
| 21 | |
| 22 | struct eap_method * eap_peer_method_alloc(int version, int vendor, |
| 23 | EapType method, const char *name) |
| 24 | { |
| 25 | struct eap_method *eap; |
| 26 | eap = os_zalloc(sizeof(*eap)); |
| 27 | if (!eap) |
| 28 | return NULL; |
| 29 | eap->version = version; |
| 30 | eap->vendor = vendor; |
| 31 | eap->method = method; |
| 32 | eap->name = name; |
| 33 | return eap; |
| 34 | } |
| 35 | |
| 36 | |
| 37 | int eap_peer_method_register(struct eap_method *method) |
| 38 | { |
| 39 | registered_eap_method = method; |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | |
| 44 | static struct eap_peer_config eap_sim_config = { |
| 45 | .identity = (u8 *) "1232010000000000", |
| 46 | .identity_len = 16, |
| 47 | .password = (u8 *) "90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581", |
| 48 | .password_len = 65, |
| 49 | }; |
| 50 | |
| 51 | struct eap_peer_config * eap_get_config(struct eap_sm *sm) |
| 52 | { |
| 53 | return &eap_sim_config; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len) |
| 58 | { |
| 59 | static const char *id = "1232010000000000"; |
| 60 | |
| 61 | *len = os_strlen(id); |
| 62 | return (const u8 *) id; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | void eap_set_anon_id(struct eap_sm *sm, const u8 *id, size_t len) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | |
| 71 | void eap_sm_request_identity(struct eap_sm *sm) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | |
| 76 | void eap_sm_request_sim(struct eap_sm *sm, const char *req) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | |
| 81 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 82 | { |
| 83 | const u8 *pos, *end; |
| 84 | struct eap_sm *sm; |
| 85 | void *priv; |
| 86 | struct eap_method_ret ret; |
| 87 | |
| 88 | wpa_fuzzer_set_debug_level(); |
| 89 | |
| 90 | eap_peer_sim_register(); |
| 91 | sm = os_zalloc(sizeof(*sm)); |
| 92 | if (!sm) |
| 93 | return 0; |
| 94 | priv = registered_eap_method->init(sm); |
| 95 | os_memset(&ret, 0, sizeof(ret)); |
| 96 | |
| 97 | pos = data; |
| 98 | end = pos + size; |
| 99 | |
| 100 | while (end - pos > 2) { |
| 101 | u16 flen; |
| 102 | struct wpabuf *buf, *req; |
| 103 | |
| 104 | flen = WPA_GET_BE16(pos); |
| 105 | pos += 2; |
| 106 | if (end - pos < flen) |
| 107 | break; |
| 108 | req = wpabuf_alloc_copy(pos, flen); |
| 109 | if (!req) |
| 110 | break; |
| 111 | wpa_hexdump_buf(MSG_MSGDUMP, "fuzzer - request", req); |
| 112 | buf = registered_eap_method->process(sm, priv, &ret, req); |
| 113 | wpa_hexdump_buf(MSG_MSGDUMP, "fuzzer - local response", buf); |
| 114 | wpabuf_free(req); |
| 115 | wpabuf_free(buf); |
| 116 | pos += flen; |
| 117 | } |
| 118 | |
| 119 | registered_eap_method->deinit(sm, priv); |
| 120 | os_free(registered_eap_method); |
| 121 | os_free(sm); |
| 122 | |
| 123 | return 0; |
| 124 | } |