Select one of the symbols to view example projects that use it.
 
Outline
#include "utils/includes.h"
#include "utils/common.h"
#include "hostapd.h"
#include "crypto/sha256.h"
#include "crypto/random.h"
#include "common/ieee802_11_defs.h"
#include "comeback_token.h"
comeback_token_hash(const u8 *, const u8 *, u8 *)
check_comeback_token(const u8 *, u16 *, const u8 *, const u8 *, size_t)
auth_build_token_req(struct os_time *, u8 *, u16, u16 *, size_t, int, const u8 *, int)
Files
ESP-IDF
components
app_trace
app_update
bootloader_support
bt
cmock
console
cxx
driver
efuse
esp_adc
esp_app_format
esp_bootloader_format
esp_coex
esp_common
esp_driver_ana_cmpr
esp_driver_cam
esp_driver_dac
esp_driver_gpio
esp_driver_gptimer
esp_driver_i2c
esp_driver_i2s
esp_driver_jpeg
esp_driver_ledc
esp_driver_mcpwm
esp_driver_parlio
esp_driver_pcnt
esp_driver_rmt
esp_driver_sdio
esp_driver_sdm
esp_driver_sdmmc
esp_driver_sdspi
esp_driver_spi
esp_driver_tsens
esp_driver_uart
esp_driver_usb_serial_jtag
esp_eth
esp_event
esp_gdbstub
esp_hid
esp_http_client
esp_http_server
esp_https_ota
esp_https_server
esp_hw_support
esp_lcd
esp_local_ctrl
esp_mm
esp_netif
esp_partition
esp_phy
esp_pm
esp_psram
esp_ringbuf
esp_rom
esp_security
esp_system
esp_timer
esp_vfs_console
esp_wifi
esp-tls
espcoredump
hal
heap
http_parser
ieee802154
log
mqtt
newlib
nvs_flash
nvs_sec_provider
openthread
perfmon
protobuf-c
protocomm
pthread
rt
sdmmc
soc
spi_flash
spiffs
tcp_transport
ulp
unity
vfs
wear_levelling
wifi_provisioning
wpa_supplicant
esp_supplicant
include
port
src
ap
common
crypto
drivers
eap_common
eap_peer
eap_server
eapol_auth
rsn_supp
tls
utils
wps
xtensa
examples
lwIP
FreeRTOS
cJSON
mbedTLS
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/wpa_supplicant/src/ap/comeback_token.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * hostapd / Comeback token mechanism for SAE * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi> * * This software may be distributed under the terms of the BSD license. * See README for more details. *//* ... */ #include "utils/includes.h" #include "utils/common.h" #include "hostapd.h" #include "crypto/sha256.h" #include "crypto/random.h" #include "common/ieee802_11_defs.h" #include "comeback_token.h"7 includes #ifdef CONFIG_SAE int comeback_token_hash(const u8 *comeback_key, const u8 *addr, u8 *idx) { u8 hash[SHA256_MAC_LEN]; if (hmac_sha256(comeback_key, COMEBACK_KEY_SIZE, addr, ETH_ALEN, hash) < 0) return -1; *idx = hash[0]; return 0; }{ ... } int check_comeback_token(const u8 *comeback_key, u16 *comeback_pending_idx, const u8 *addr, const u8 *token, size_t token_len) { u8 mac[SHA256_MAC_LEN]; const u8 *addrs[2]; size_t len[2]; u16 token_idx; u8 idx; if (token_len != SHA256_MAC_LEN || comeback_token_hash(comeback_key, addr, &idx) < 0) { return -1; }{...} token_idx = comeback_pending_idx[idx]; if (token_idx == 0 || token_idx != WPA_GET_BE16(token)) { wpa_printf(MSG_DEBUG, "Comeback: Invalid anti-clogging token from " MACSTR " - token_idx 0x%04x, expected 0x%04x", MAC2STR(addr), WPA_GET_BE16(token), token_idx); return -1; }{...} addrs[0] = addr; len[0] = ETH_ALEN; addrs[1] = token; len[1] = 2; if (hmac_sha256_vector(comeback_key, COMEBACK_KEY_SIZE, 2, addrs, len, mac) < 0 || os_memcmp_const(token + 2, &mac[2], SHA256_MAC_LEN - 2) != 0) { return -1; }{...} comeback_pending_idx[idx] = 0; /* invalidate used token */ return 0; }{ ... } struct wpabuf * auth_build_token_req(struct os_reltime *last_comeback_key_update, u8 *comeback_key, u16 comeback_idx, u16 *comeback_pending_idx, size_t idx_len, int group, const u8 *addr, int h2e) { struct wpabuf *buf; u8 *token; struct os_reltime now; u8 idx[2]; const u8 *addrs[2]; size_t len[2]; u8 p_idx; u16 token_idx; os_get_time(&now); if (!os_reltime_initialized(last_comeback_key_update) || os_reltime_expired(&now, last_comeback_key_update, 60) || comeback_idx == 0xffff) { if (random_get_bytes(comeback_key, COMEBACK_KEY_SIZE) < 0) { return NULL; }{...} wpa_hexdump(MSG_DEBUG, "Comeback: Updated token key", comeback_key, COMEBACK_KEY_SIZE); *last_comeback_key_update = now; comeback_idx = 0; os_memset(comeback_pending_idx, 0, idx_len); }{...} buf = wpabuf_alloc(sizeof(le16) + 3 + SHA256_MAC_LEN); if (buf == NULL) { return NULL; }{...} if (group) wpabuf_put_le16(buf, group); /* Finite Cyclic Group */ if (h2e) { /* Encapsulate Anti-clogging Token field in a container IE */ wpabuf_put_u8(buf, WLAN_EID_EXTENSION); wpabuf_put_u8(buf, 1 + SHA256_MAC_LEN); wpabuf_put_u8(buf, WLAN_EID_EXT_ANTI_CLOGGING_TOKEN); }{...} if (comeback_token_hash(comeback_key, addr, &p_idx) < 0) { wpabuf_free(buf); return NULL; }{...} token_idx = comeback_pending_idx[p_idx]; if (!token_idx) { comeback_idx++; token_idx = comeback_idx; comeback_pending_idx[p_idx] = token_idx; }{...} WPA_PUT_BE16(idx, token_idx); token = wpabuf_put(buf, SHA256_MAC_LEN); addrs[0] = addr; len[0] = ETH_ALEN; addrs[1] = idx; len[1] = sizeof(idx); if (hmac_sha256_vector(comeback_key, COMEBACK_KEY_SIZE, 2, addrs, len, token) < 0) { wpabuf_free(buf); return NULL; }{...} WPA_PUT_BE16(token, token_idx); return buf; }{ ... } /* ... */#endif /* CONFIG_SAE */
Details