change hex radio password validation; add password length doc
This commit is contained in:
parent
ec78a23a56
commit
df41bd9ead
|
@ -1 +1 @@
|
|||
Subproject commit 73fafcbe4c66b23df63be31e9227353b695abb08
|
||||
Subproject commit 427cc923976229bcb981ca6f218ebe8efd636df6
|
|
@ -98,6 +98,9 @@ msgstr ""
|
|||
#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
|
||||
#: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c
|
||||
#: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c
|
||||
#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c
|
||||
#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c
|
||||
#: shared-bindings/keypad/ShiftRegisterKeys.c
|
||||
msgid "%q"
|
||||
msgstr ""
|
||||
|
||||
|
@ -193,7 +196,7 @@ msgstr ""
|
|||
msgid "%q must be array of type 'H'"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c
|
||||
#: shared-module/synthio/__init__.c
|
||||
msgid "%q must be array of type 'h'"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1117,10 +1120,6 @@ msgstr ""
|
|||
msgid "I2C peripheral in use"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/audiobusio/I2SOut.c
|
||||
msgid "I2SOut not available"
|
||||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
|
||||
msgid "In-buffer elements must be <= 4 bytes long"
|
||||
msgstr ""
|
||||
|
@ -1282,6 +1281,10 @@ msgstr ""
|
|||
msgid "Invalid format chunk size"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/wifi/Radio.c
|
||||
msgid "Invalid hex password"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/wifi/Radio.c
|
||||
msgid "Invalid multicast MAC address"
|
||||
msgstr ""
|
||||
|
@ -1708,10 +1711,6 @@ msgstr ""
|
|||
msgid "Oversample must be multiple of 8."
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/audiobusio/PDMIn.c
|
||||
msgid "PDMIn not available"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/pwmio/PWMOut.c
|
||||
msgid ""
|
||||
"PWM frequency not writable when variable_frequency is False on construction."
|
||||
|
|
|
@ -268,19 +268,6 @@ mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
|
|||
return an_int;
|
||||
}
|
||||
|
||||
mp_int_t mp_arg_validate_valid_hex_password(mp_uint_t length, uint8_t *buf) {
|
||||
unsigned int i=0;
|
||||
while (i<length) {
|
||||
if (!(('0' <= buf[i] && buf[i] <= '9') ||
|
||||
('a' <= buf[i] && buf[i] <= 'f') ||
|
||||
('A' <= buf[i] && buf[i] <= 'F'))) {
|
||||
mp_raise_ValueError_varg(translate("Invalid hex character in password."));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NORETURN void mp_arg_error_invalid(qstr arg_name) {
|
||||
mp_raise_ValueError_varg(translate("Invalid %q"), arg_name);
|
||||
}
|
||||
|
|
|
@ -114,7 +114,6 @@ mp_obj_t mp_arg_validate_type_in(mp_obj_t obj, const mp_obj_type_t *type, qstr a
|
|||
mp_obj_t mp_arg_validate_type_or_none(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name);
|
||||
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name);
|
||||
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name);
|
||||
mp_int_t mp_arg_validate_valid_hex_password(mp_uint_t length, uint8_t *buf);
|
||||
|
||||
static MP_INLINE mp_obj_dict_t *mp_locals_get(void) {
|
||||
return MP_STATE_THREAD(dict_locals);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include "py/unicode.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/objproperty.h"
|
||||
|
||||
|
@ -70,6 +71,14 @@ STATIC bool hostname_valid(const char *ptr, size_t len) {
|
|||
return !(partlen > 63);
|
||||
}
|
||||
|
||||
STATIC void validate_hex_password(const uint8_t *buf, size_t len) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (!unichar_isxdigit(buf[i])) {
|
||||
mp_raise_ValueError_varg(translate("Invalid hex password"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//| class Radio:
|
||||
//| """Native wifi radio.
|
||||
|
@ -321,6 +330,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
|
|||
//| ``OPEN`` will be used when the password is the empty string,
|
||||
//| otherwise ``authmode`` will be ``WPA_WPA2_PSK``.
|
||||
//|
|
||||
//| The length of ``password`` must be 8-63 characters if it is ASCII,
|
||||
//| or exactly 64 hexadecimal characters if it is the hex form of the 256-bit key.
|
||||
//|
|
||||
//| If ``max_connections`` is given, the access point will allow up to
|
||||
//| that number of stations to connect."""
|
||||
//| ...
|
||||
|
@ -369,7 +381,7 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||
if (authmodes != AUTHMODE_OPEN) {
|
||||
mp_arg_validate_length_range(password.len, 8, 64, MP_QSTR_password);
|
||||
if (password.len == 64) {
|
||||
mp_arg_validate_valid_hex_password(password.len, password.buf);
|
||||
validate_hex_password(password.buf, password.len);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,6 +421,9 @@ MP_PROPERTY_GETTER(wifi_radio_ap_active_obj,
|
|||
//| """Connects to the given ssid and waits for an ip address. Reconnections are handled
|
||||
//| automatically once one connection succeeds.
|
||||
//|
|
||||
//| The length of ``password`` must be 0 if there is no password, 8-63 characters if it is ASCII,
|
||||
//| or exactly 64 hexadecimal characters if it is the hex form of the 256-bit key.
|
||||
//|
|
||||
//| By default, this will scan all channels and connect to the access point (AP) with the
|
||||
//| given ``ssid`` and greatest signal strength (rssi).
|
||||
//|
|
||||
|
@ -450,7 +465,7 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
if (password.len != 0) {
|
||||
mp_arg_validate_length_range(password.len, 8, 64, MP_QSTR_password);
|
||||
if (password.len == 64) {
|
||||
mp_arg_validate_valid_hex_password(password.len, password.buf);
|
||||
validate_hex_password(password.buf, password.len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue