Skip to content

Commit df41bd9

Browse files
committed
change hex radio password validation; add password length doc
1 parent ec78a23 commit df41bd9

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

data/nvm.toml

locale/circuitpython.pot

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ msgstr ""
9898
#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
9999
#: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c
100100
#: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c
101+
#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c
102+
#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c
103+
#: shared-bindings/keypad/ShiftRegisterKeys.c
101104
msgid "%q"
102105
msgstr ""
103106

@@ -193,7 +196,7 @@ msgstr ""
193196
msgid "%q must be array of type 'H'"
194197
msgstr ""
195198

196-
#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c
199+
#: shared-module/synthio/__init__.c
197200
msgid "%q must be array of type 'h'"
198201
msgstr ""
199202

@@ -1117,10 +1120,6 @@ msgstr ""
11171120
msgid "I2C peripheral in use"
11181121
msgstr ""
11191122

1120-
#: shared-bindings/audiobusio/I2SOut.c
1121-
msgid "I2SOut not available"
1122-
msgstr ""
1123-
11241123
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
11251124
msgid "In-buffer elements must be <= 4 bytes long"
11261125
msgstr ""
@@ -1282,6 +1281,10 @@ msgstr ""
12821281
msgid "Invalid format chunk size"
12831282
msgstr ""
12841283

1284+
#: shared-bindings/wifi/Radio.c
1285+
msgid "Invalid hex password"
1286+
msgstr ""
1287+
12851288
#: ports/espressif/common-hal/wifi/Radio.c
12861289
msgid "Invalid multicast MAC address"
12871290
msgstr ""
@@ -1708,10 +1711,6 @@ msgstr ""
17081711
msgid "Oversample must be multiple of 8."
17091712
msgstr ""
17101713

1711-
#: shared-bindings/audiobusio/PDMIn.c
1712-
msgid "PDMIn not available"
1713-
msgstr ""
1714-
17151714
#: shared-bindings/pwmio/PWMOut.c
17161715
msgid ""
17171716
"PWM frequency not writable when variable_frequency is False on construction."

py/argcheck.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,6 @@ mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) {
268268
return an_int;
269269
}
270270

271-
mp_int_t mp_arg_validate_valid_hex_password(mp_uint_t length, uint8_t *buf) {
272-
unsigned int i=0;
273-
while (i<length) {
274-
if (!(('0' <= buf[i] && buf[i] <= '9') ||
275-
('a' <= buf[i] && buf[i] <= 'f') ||
276-
('A' <= buf[i] && buf[i] <= 'F'))) {
277-
mp_raise_ValueError_varg(translate("Invalid hex character in password."));
278-
}
279-
i++;
280-
}
281-
return 0;
282-
}
283-
284271
NORETURN void mp_arg_error_invalid(qstr arg_name) {
285272
mp_raise_ValueError_varg(translate("Invalid %q"), arg_name);
286273
}

py/runtime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ mp_obj_t mp_arg_validate_type_in(mp_obj_t obj, const mp_obj_type_t *type, qstr a
114114
mp_obj_t mp_arg_validate_type_or_none(mp_obj_t obj, const mp_obj_type_t *type, qstr arg_name);
115115
mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name);
116116
mp_obj_t mp_arg_validate_type_string(mp_obj_t obj, qstr arg_name);
117-
mp_int_t mp_arg_validate_valid_hex_password(mp_uint_t length, uint8_t *buf);
118117

119118
static MP_INLINE mp_obj_dict_t *mp_locals_get(void) {
120119
return MP_STATE_THREAD(dict_locals);

shared-bindings/wifi/Radio.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <string.h>
3131

32+
#include "py/unicode.h"
3233
#include "py/runtime.h"
3334
#include "py/objproperty.h"
3435

@@ -70,6 +71,14 @@ STATIC bool hostname_valid(const char *ptr, size_t len) {
7071
return !(partlen > 63);
7172
}
7273

74+
STATIC void validate_hex_password(const uint8_t *buf, size_t len) {
75+
for (size_t i = 0; i < len; i++) {
76+
if (!unichar_isxdigit(buf[i])) {
77+
mp_raise_ValueError_varg(translate("Invalid hex password"));
78+
}
79+
}
80+
}
81+
7382

7483
//| class Radio:
7584
//| """Native wifi radio.
@@ -321,6 +330,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station);
321330
//| ``OPEN`` will be used when the password is the empty string,
322331
//| otherwise ``authmode`` will be ``WPA_WPA2_PSK``.
323332
//|
333+
//| The length of ``password`` must be 8-63 characters if it is ASCII,
334+
//| or exactly 64 hexadecimal characters if it is the hex form of the 256-bit key.
335+
//|
324336
//| If ``max_connections`` is given, the access point will allow up to
325337
//| that number of stations to connect."""
326338
//| ...
@@ -368,8 +380,8 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
368380

369381
if (authmodes != AUTHMODE_OPEN) {
370382
mp_arg_validate_length_range(password.len, 8, 64, MP_QSTR_password);
371-
if (password.len==64) {
372-
mp_arg_validate_valid_hex_password(password.len, password.buf);
383+
if (password.len == 64) {
384+
validate_hex_password(password.buf, password.len);
373385
}
374386
}
375387

@@ -409,6 +421,9 @@ MP_PROPERTY_GETTER(wifi_radio_ap_active_obj,
409421
//| """Connects to the given ssid and waits for an ip address. Reconnections are handled
410422
//| automatically once one connection succeeds.
411423
//|
424+
//| The length of ``password`` must be 0 if there is no password, 8-63 characters if it is ASCII,
425+
//| or exactly 64 hexadecimal characters if it is the hex form of the 256-bit key.
426+
//|
412427
//| By default, this will scan all channels and connect to the access point (AP) with the
413428
//| given ``ssid`` and greatest signal strength (rssi).
414429
//|
@@ -449,8 +464,8 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
449464
mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ);
450465
if (password.len != 0) {
451466
mp_arg_validate_length_range(password.len, 8, 64, MP_QSTR_password);
452-
if (password.len==64) {
453-
mp_arg_validate_valid_hex_password(password.len, password.buf);
467+
if (password.len == 64) {
468+
validate_hex_password(password.buf, password.len);
454469
}
455470
}
456471
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy