Hi Grant,

> This fixes "raw" PSK support by first converting the "raw" PSK from
> a 64-character hexadecimal string to 32-byte array before appending
> it to the network dictionary.
> 
> ---
>  v1: Initial submission.
>  v2: Fixed white space.
> 
>  gsupplicant/supplicant.c |   42 ++++++++++++++++++++++++++++++++++++------
>  1 file changed, 36 insertions(+), 6 deletions(-)
> 
> diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
> index 977c0fb..3af1662 100644
> --- a/gsupplicant/supplicant.c
> +++ b/gsupplicant/supplicant.c
> @@ -2961,17 +2961,47 @@ static dbus_bool_t is_psk_raw_key(const char *psk)
>       return TRUE;
>  }
>  
> +static unsigned char hexchar2bin(char c)
> +{
> +     if ((c >= '0') && (c <= '9'))
> +             return (c - '0');
> +     else if ((c >= 'A') && (c <= 'F'))
> +             return (c - 'A' + 10);
> +     else if ((c >= 'a') && (c <= 'f'))
> +             return (c - 'a' + 10);
> +     else
> +             return (c);
> +}
> +
> +static void hexstring2bin(const char *string, unsigned char *data, size_t 
> data_len)
> +{
> +     size_t i;
> +
> +     if ((data != NULL) && (string != NULL))

Actually "if (data != NULL && string != NULL)" is enough. The extra ( )
are just useless and will clutter the code.

Also it seems this check is rather useless since it will never be NULL
in the first place. It is only called from on location.

> +             for (i = 0; i < data_len; i++)
> +                     data[i] = (hexchar2bin(string[i * 2 + 0]) << 4 |
> +                                hexchar2bin(string[i * 2 + 1]) << 0);
> +}
> +
>  static void add_network_security_psk(DBusMessageIter *dict,
>                                       GSupplicantSSID *ssid)
>  {
>       if (ssid->passphrase && strlen(ssid->passphrase) > 0) {
> -             if (is_psk_raw_key(ssid->passphrase) == TRUE)
> +             const char *key = "psk";
> +
> +             if (is_psk_raw_key(ssid->passphrase) == TRUE) {
> +                     const size_t size = 32;
> +                     unsigned char data[size];
> +                     unsigned char *datap = data;

What is this datap conversion for? Just use data in hexstring2bin. And
please use unsigned char data[32] and then sizeof(data). Sorry, but this
is way too complicated.

> +
> +                     hexstring2bin(ssid->passphrase, datap, size);
> +
>                       supplicant_dbus_dict_append_fixed_array(dict,
> -                                                     "psk", DBUS_TYPE_BYTE,
> -                                                     &ssid->passphrase, 64);
> -             else
> -                     supplicant_dbus_dict_append_basic(dict, "psk",
> -                                                     DBUS_TYPE_STRING,
> +                                                     key, DBUS_TYPE_BYTE,
> +                                                     &datap, size);
> +             } else
> +                     supplicant_dbus_dict_append_basic(dict,
> +                                                     key, DBUS_TYPE_STRING,
>                                                       &ssid->passphrase);
>       }
>  }

Regards

Marcel


_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to