WPS: Add a standalone tool for building NFC password tokens
nfc_pw_token can be used to build random NFC password token for WPS. This tool prints out the wpa_supplicant.conf (or hostapd.conf) parameters and the hexdump of the WPS password token (with and without NDEF encapsulation) so that it can be written to a NFC tag with an external program. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
72df0cd28c
commit
40a5e3bfde
2 changed files with 92 additions and 0 deletions
|
@ -1366,6 +1366,10 @@ ifndef CONFIG_AP
|
||||||
OBJS_t += ../src/utils/ip_addr.o
|
OBJS_t += ../src/utils/ip_addr.o
|
||||||
endif
|
endif
|
||||||
OBJS_t2 := $(OBJS) $(OBJS_l2) preauth_test.o
|
OBJS_t2 := $(OBJS) $(OBJS_l2) preauth_test.o
|
||||||
|
|
||||||
|
OBJS_nfc := $(OBJS) $(OBJS_l2) nfc_pw_token.o
|
||||||
|
OBJS_nfc += $(OBJS_d) ../src/drivers/drivers.o
|
||||||
|
|
||||||
OBJS += $(CONFIG_MAIN).o
|
OBJS += $(CONFIG_MAIN).o
|
||||||
|
|
||||||
ifdef CONFIG_PRIVSEP
|
ifdef CONFIG_PRIVSEP
|
||||||
|
@ -1474,6 +1478,10 @@ test_wpa: $(OBJS_wpa) $(OBJS_h)
|
||||||
$(Q)$(LDO) $(LDFLAGS) -o test_wpa $(OBJS_wpa) $(LIBS)
|
$(Q)$(LDO) $(LDFLAGS) -o test_wpa $(OBJS_wpa) $(LIBS)
|
||||||
@$(E) " LD " $@
|
@$(E) " LD " $@
|
||||||
|
|
||||||
|
nfc_pw_token: $(OBJS_nfc)
|
||||||
|
$(Q)$(LDO) $(LDFLAGS) -o nfc_pw_token $(OBJS_nfc) $(LIBS)
|
||||||
|
@$(E) " LD " $@
|
||||||
|
|
||||||
win_if_list: win_if_list.c
|
win_if_list: win_if_list.c
|
||||||
$(Q)$(LDO) $(LDFLAGS) -o $@ win_if_list.c $(CFLAGS) $(LIBS_w)
|
$(Q)$(LDO) $(LDFLAGS) -o $@ win_if_list.c $(CFLAGS) $(LIBS_w)
|
||||||
@$(E) " LD " $@
|
@$(E) " LD " $@
|
||||||
|
@ -1556,5 +1564,6 @@ clean:
|
||||||
$(MAKE) -C dbus clean
|
$(MAKE) -C dbus clean
|
||||||
rm -f core *~ *.o *.d eap_*.so $(ALL) $(WINALL) eapol_test preauth_test
|
rm -f core *~ *.o *.d eap_*.so $(ALL) $(WINALL) eapol_test preauth_test
|
||||||
rm -f wpa_priv
|
rm -f wpa_priv
|
||||||
|
rm -f nfc_pw_token
|
||||||
|
|
||||||
-include $(OBJS:%.o=%.d)
|
-include $(OBJS:%.o=%.d)
|
||||||
|
|
83
wpa_supplicant/nfc_pw_token.c
Normal file
83
wpa_supplicant/nfc_pw_token.c
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* nfc_pw_token - Tool for building NFC password tokens for WPS
|
||||||
|
* Copyright (c) 2012, Jouni Malinen <j@w1.fi>
|
||||||
|
*
|
||||||
|
* This software may be distributed under the terms of the BSD license.
|
||||||
|
* See README for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "includes.h"
|
||||||
|
|
||||||
|
#include "utils/common.h"
|
||||||
|
#include "crypto/random.h"
|
||||||
|
#include "wpa_supplicant_i.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "wps_supplicant.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void print_bin(const char *title, const struct wpabuf *buf)
|
||||||
|
{
|
||||||
|
size_t i, len;
|
||||||
|
const u8 *pos;
|
||||||
|
|
||||||
|
if (buf == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
printf("%s=", title);
|
||||||
|
|
||||||
|
pos = wpabuf_head(buf);
|
||||||
|
len = wpabuf_len(buf);
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
printf("%02X", *pos++);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
struct wpa_supplicant wpa_s;
|
||||||
|
int ret = -1;
|
||||||
|
struct wpabuf *buf = NULL, *ndef = NULL;
|
||||||
|
char txt[1000];
|
||||||
|
|
||||||
|
if (os_program_init())
|
||||||
|
return -1;
|
||||||
|
random_init(NULL);
|
||||||
|
|
||||||
|
os_memset(&wpa_s, 0, sizeof(wpa_s));
|
||||||
|
wpa_s.conf = os_zalloc(sizeof(*wpa_s.conf));
|
||||||
|
if (wpa_s.conf == NULL)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
buf = wpas_wps_nfc_token(&wpa_s, 0);
|
||||||
|
if (buf == NULL)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
ndef = ndef_build_wifi(buf);
|
||||||
|
if (ndef == NULL)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
wpa_snprintf_hex_uppercase(txt, sizeof(txt), wpabuf_head(buf),
|
||||||
|
wpabuf_len(buf));
|
||||||
|
printf("#WPS=%s\n", txt);
|
||||||
|
|
||||||
|
wpa_snprintf_hex_uppercase(txt, sizeof(txt), wpabuf_head(ndef),
|
||||||
|
wpabuf_len(ndef));
|
||||||
|
printf("#NDEF=%s\n", txt);
|
||||||
|
|
||||||
|
printf("wps_nfc_dev_pw_id=%d\n", wpa_s.conf->wps_nfc_dev_pw_id);
|
||||||
|
print_bin("wps_nfc_dh_pubkey", wpa_s.conf->wps_nfc_dh_pubkey);
|
||||||
|
print_bin("wps_nfc_dh_privkey", wpa_s.conf->wps_nfc_dh_privkey);
|
||||||
|
print_bin("wps_nfc_dev_pw", wpa_s.conf->wps_nfc_dev_pw);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
fail:
|
||||||
|
wpabuf_free(ndef);
|
||||||
|
wpabuf_free(buf);
|
||||||
|
wpa_config_free(wpa_s.conf);
|
||||||
|
random_deinit();
|
||||||
|
os_program_deinit();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Reference in a new issue