Code changes to allow 64 character hex WiFi passwords to be used with

wifi.radio.connect.

Fixes adafruit/circuitpython#7677.
This commit is contained in:
Richard Ellis 2023-04-15 22:54:57 -04:00
parent 15f1bcaa90
commit ec78a23a56
3 changed files with 22 additions and 2 deletions

View File

@ -268,6 +268,19 @@ 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);
}

View File

@ -114,6 +114,7 @@ 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);

View File

@ -367,7 +367,10 @@ 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, 63, MP_QSTR_password);
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);
}
}
common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmodes, args[ARG_max_connections].u_int);
@ -445,7 +448,10 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
if (args[ARG_password].u_obj != mp_const_none) {
mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ);
if (password.len != 0) {
mp_arg_validate_length_range(password.len, 8, 63, MP_QSTR_password);
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);
}
}
}