dpp-util: fix dpp_point_from_asn1
James Prestwood
PATCH v3 1/10 dpp-util: fix dpp_point_from_asn1
This got merged without a few additional fixes, in particular an over 80 character line and incorrect length check.
--- src/dpp-util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
src/dpp-util.c +3 -2
@@ -828,7 +828,8 @@ struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len)return NULL ;/* SEQUENCE */ - inner_seq =asn1_der_find_elem (outer_seq, outer_len,0 , &tag, &inner_len); + inner_seq =asn1_der_find_elem (outer_seq, outer_len,0 , &tag, + &inner_len);if (!inner_seq || tag !=ASN1_ID_SEQUENCE )return NULL ;
@@ -859,7 +860,7 @@ struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len)/* BITSTRING */ key_data =asn1_der_find_elem (outer_seq, outer_len,1 , &tag, &elen); -if (!key_data || tag !=ASN1_ID_BIT_STRING || elen >2 ) +if (!key_data || tag !=ASN1_ID_BIT_STRING || elen <2 )return NULL ; return l_ecc_point_from_data(curve, key_data[1],
Signature · 1 line
2.34.1
James Prestwood
PATCH v3 2/10 dpp-util: add URI parsing
Parses K (key), M (mac), C (class/channels), and V (version) tokens into a new structure dpp_uri_info. H/I are not parsed since there currently isn't any use for them.
--- src/dpp-util.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++++ src/dpp-util.h | 13 +++ 2 files changed, 230 insertions(+)
src/dpp-util.c +217 -0
@@ -866,3 +866,220 @@ struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len)return l_ecc_point_from_data (curve, key_data[1 ], key_data +2 , elen -2 ); } + +/* +* Advances 'p' to the next character 'sep' plus one. strchr can be trusted to +* find the next character, but we do need to check that the next character + 1 +* isn't the NULL terminator, i.e. that data actually exists past this point. +*/ +#define TOKEN_NEXT (p, sep) \ +({ \ + const char *_next = strchr((p), (sep)); \ + if (_next) { \ + if (*(_next + 1) == '\0') \ + _next = NULL; \ + else \ + _next++; \ + } \ + _next; \ +}) + +/* +* Finds the length of the current token (characters until next 'sep'). If no +* 'sep' is found zero is returned. +*/ +#define TOKEN_LEN (p, sep) \ +({ \ + const char *_next = strchr((p), (sep)); \ + if (!_next) \ + _next = (p); \ + (_next - (p)); \ +}) + +/* +* Ensures 'p' points to something resembling a single character followed by +* ':' followed by at least one non-null byte of data. This allows the parse +* loop to safely advance the pointer to each tokens data (pos + 2) +*/ +#define TOKEN_OK (p) \ + ((p) && (p)[0] != '\0' && (p)[1] == ':' && (p)[2] != '\0') \ + +static struct scan_freq_set *dpp_parse_class_and_channel (const char *token) +{ +const char *pos = token; +char *end; +struct scan_freq_set *freqs =scan_freq_set_new (); + +/* Checking for <operclass>/<channel>,<operclass>/<channel>,... */ +for (; pos; pos =TOKEN_NEXT (pos,',' )) { +uint8_t channel; +uint8_t oper_class =strtol (pos, &end,10 ); + +if (!end || end == pos || (end && *end !='/' )) + goto free_set; + + pos = end +1 ; + channel =strtol (pos, &end,10 ); + +/* Either another pair (,) or end of this token (;) */ +if (!end || end == pos || (*end !=',' && *end !=';' )) + goto free_set; + +scan_freq_set_add (freqs,oci_to_frequency (oper_class, channel)); + } + +if (scan_freq_set_isempty (freqs)) { +free_set: +scan_freq_set_free (freqs); +return NULL ; + } + +return freqs; +} + +static int dpp_parse_mac (const char *str,uint8_t *mac_out) +{ +uint8_t mac[6 ]; +unsigned int i; + +for (i =0 ; i <12 ; i +=2 ) { +if (!l_ascii_isxdigit (str[i])) +return -EINVAL ; + +if (!l_ascii_isxdigit (str[i +1 ])) +return -EINVAL ; + } + +if (sscanf (str,"%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx" , + &mac[0 ], &mac[1 ], &mac[2 ], + &mac[3 ], &mac[4 ], &mac[5 ]) !=6 ) +return -EINVAL ; + +if (!util_is_valid_sta_address (mac)) +return -EINVAL ; + +memcpy (mac_out, mac,6 ); + +return 0 ; +} + +static int dpp_parse_version (const char *str,uint8_t *version_out) +{ +char *end; +uint8_t version; +size_t len =TOKEN_LEN (str,';' ); + +if (len !=1 ) +return -EINVAL ; + + version =strtol (str, &end,10 ); + +if (version !=1 && version !=2 ) +return -EINVAL ; + + *version_out = version; + +return 0 ; +} + +static struct l_ecc_point *dpp_parse_key (const char *str) +{ + _auto_(l_free) uint8_t *decoded = NULL; +size_t decoded_len; +size_t len =TOKEN_LEN (str,';' ); + +if (!len) +return NULL ; + + decoded =l_base64_decode (str, len, &decoded_len); +if (!decoded) +return NULL ; + +return dpp_point_from_asn1 (decoded, decoded_len); +} + +/* +* Parse a bootstrapping URI. This parses the tokens defined in the Easy Connect +* spec, and verifies they are the correct syntax. Some values have extra +* verification: +* - The bootstrapping key is base64 decoded and converted to an l_ecc_point +* - The operating class and channels are checked against the OCI table. +* - The version is checked to be either 1 or 2, as defined by the spec. +* - The MAC is verified to be a valid station address. +*/ +struct dpp_uri_info *dpp_parse_uri (const char *uri) +{ +struct dpp_uri_info *info; +const char *pos = uri; +const char *end = uri +strlen (uri) -1 ; +int ret =0 ; + +if (strncmp (pos,"DPP:" ,4 )) +return NULL ; + + info = l_new(struct dpp_uri_info, 1); + + pos +=4 ; + +/* EasyConnect 5.2.1 - Bootstrapping information format */ +for (;TOKEN_OK (pos); pos =TOKEN_NEXT (pos,';' )) { +switch (*pos) { +case 'C' : + info->freqs =dpp_parse_class_and_channel (pos +2 ); +if (!info->freqs) + goto free_info; +break ; +case 'M' : + ret =dpp_parse_mac (pos +2 , info->mac); +if (ret <0 ) + goto free_info; +break ; +case 'V' : + ret =dpp_parse_version (pos +2 , &info->version); +if (ret <0 ) + goto free_info; +break ; +case 'K' : + info->boot_public =dpp_parse_key (pos +2 ); +if (!info->boot_public) + goto free_info; +break ; +case 'H' : +case 'I' : +break ; +default : + goto free_info; + } + } + +/* Extra data found after last token */ +if (pos != end) + goto free_info; + +/* The public bootstrapping key is the only required token */ +if (!info->boot_public) + goto free_info; + +return info; + +free_info: +dpp_free_uri_info (info); +return NULL ; +} + +void dpp_free_uri_info (struct dpp_uri_info *info) +{ +if (info->freqs) +scan_freq_set_free (info->freqs); + +if (info->boot_public) +l_ecc_point_free (info->boot_public); + +if (info->information) +l_free (info->information); + +if (info->host) +l_free (info->host); + +l_free (info); +}
src/dpp-util.h +13 -0
@@ -22,6 +22,16 @@struct l_ecc_point ;struct l_ecc_scalar ;enum ie_rsn_akm_suite ; +struct scan_freq_set ; + +struct dpp_uri_info { +struct scan_freq_set *freqs; +struct l_ecc_point *boot_public; +uint8_t mac[6 ]; +char *information; +uint8_t version; +char *host; +};enum dpp_frame_type {DPP_FRAME_AUTHENTICATION_REQUEST =0 ,
@@ -168,3 +178,6 @@ bool dpp_derive_ke(const uint8_t *i_nonce, const uint8_t *r_nonce,uint8_t *dpp_point_to_asn1 (const struct l_ecc_point *p,size_t *len_out);struct l_ecc_point *dpp_point_from_asn1 (const uint8_t *asn1,size_t len); + +struct dpp_uri_info *dpp_parse_uri (const char *uri); +void dpp_free_uri_info (struct dpp_uri_info *info);
Signature · 1 line
2.34.1
Denis Kenzior
Re: [PATCH v3 02/10] dpp-util: add URI parsing
Hi James,
Quoted 54 lines · James Prestwood
Parses K (key), M (mac), C (class/channels), and V (version) tokens into a new structure
dpp_uri_info. H/I are not parsed since there currently isn't any use for them.--- src/dpp-util.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++++ src/dpp-util.h | 13 +++ 2 files changed, 230 insertions(+)src/dpp-util.c +38
-0@@ -866,3 +866,220 @@ struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len)return l_ecc_point_from_data (curve, key_data[1 ], key_data +2 , elen -2 ); } + +/* +* Advances 'p' to the next character 'sep' plus one. strchr can be trusted to +* find the next character, but we do need to check that the next character + 1 +* isn't the NULL terminator, i.e. that data actually exists past this point. +*/ +#define TOKEN_NEXT (p, sep) \ +({ \ + const char *_next = strchr((p), (sep)); \ + if (_next) { \ + if (*(_next + 1) == '\0') \ + _next = NULL; \ + else \ + _next++; \ + } \ + _next; \ +}) + +/* +* Finds the length of the current token (characters until next 'sep'). If no +* 'sep' is found zero is returned. +*/ +#define TOKEN_LEN (p, sep) \ +({ \ + const char *_next = strchr((p), (sep)); \ + if (!_next) \ + _next = (p); \ + (_next - (p)); \ +}) + +/* +* Ensures 'p' points to something resembling a single character followed by +* ':' followed by at least one non-null byte of data. This allows the parse +* loop to safely advance the pointer to each tokens data (pos + 2) +*/ +#define TOKEN_OK (p) \ + ((p) && (p)[0] != '\0' && (p)[1] == ':' && (p)[2] != '\0') \ +
src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 916
Quoted 10 lines
src/dpp-util.c +10
-0+static struct scan_freq_set *dpp_parse_class_and_channel (const char *token) +{ +const char *pos = token; +char *end; +struct scan_freq_set *freqs =scan_freq_set_new (); + +/* Checking for <operclass>/<channel>,<operclass>/<channel>,... */ +for (; pos; pos =TOKEN_NEXT (pos,',' )) { +uint8_t channel; +uint8_t oper_class =strtol (pos, &end,10 );
strtoul? Also, might want to check for the minus sign and make sure that strtol isn't returning something larger > 255.
Quoted 92 lines
src/dpp-util.c +92
-0+ +if (!end || end == pos || (end && *end !='/' )) + goto free_set; + + pos = end +1 ; + channel =strtol (pos, &end,10 ); + +/* Either another pair (,) or end of this token (;) */ +if (!end || end == pos || (*end !=',' && *end !=';' )) + goto free_set; + +scan_freq_set_add (freqs,oci_to_frequency (oper_class, channel)); + } + +if (scan_freq_set_isempty (freqs)) { +free_set: +scan_freq_set_free (freqs); +return NULL ; + } + +return freqs; +} + +static int dpp_parse_mac (const char *str,uint8_t *mac_out) +{ +uint8_t mac[6 ]; +unsigned int i; + +for (i =0 ; i <12 ; i +=2 ) { +if (!l_ascii_isxdigit (str[i])) +return -EINVAL ; + +if (!l_ascii_isxdigit (str[i +1 ])) +return -EINVAL ; + } + +if (sscanf (str,"%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx" , + &mac[0 ], &mac[1 ], &mac[2 ], + &mac[3 ], &mac[4 ], &mac[5 ]) !=6 ) +return -EINVAL ; + +if (!util_is_valid_sta_address (mac)) +return -EINVAL ; + +memcpy (mac_out, mac,6 ); + +return 0 ; +} + +static int dpp_parse_version (const char *str,uint8_t *version_out) +{ +char *end; +uint8_t version; +size_t len =TOKEN_LEN (str,';' ); + +if (len !=1 ) +return -EINVAL ; + + version =strtol (str, &end,10 ); + +if (version !=1 && version !=2 ) +return -EINVAL ; + + *version_out = version; + +return 0 ; +} + +static struct l_ecc_point *dpp_parse_key (const char *str) +{ + _auto_(l_free) uint8_t *decoded = NULL; +size_t decoded_len; +size_t len =TOKEN_LEN (str,';' ); + +if (!len) +return NULL ; + + decoded =l_base64_decode (str, len, &decoded_len); +if (!decoded) +return NULL ; + +return dpp_point_from_asn1 (decoded, decoded_len); +} + +/* +* Parse a bootstrapping URI. This parses the tokens defined in the Easy Connect +* spec, and verifies they are the correct syntax. Some values have extra +* verification: +* - The bootstrapping key is base64 decoded and converted to an l_ecc_point +* - The operating class and channels are checked against the OCI table. +* - The version is checked to be either 1 or 2, as defined by the spec. +* - The MAC is verified to be a valid station address.
src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 1018
Quoted 10 lines
src/dpp-util.c +10
-0+*/ +struct dpp_uri_info *dpp_parse_uri (const char *uri) +{ +struct dpp_uri_info *info; +const char *pos = uri; +const char *end = uri +strlen (uri) -1 ; +int ret =0 ; + +if (strncmp (pos,"DPP:" ,4 )) +return NULL ;
strncmp? If the string has already been validated to be a valid string, then strcmp is probably just fine.
src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 1025
Quoted 7 lines
src/dpp-util.c +7
-0+ + info = l_new(struct dpp_uri_info, 1); + + pos +=4 ; + +/* EasyConnect 5.2.1 - Bootstrapping information format */ +for (;TOKEN_OK (pos); pos =TOKEN_NEXT (pos,';' )) {
You don't seem to be validating that the token is terminated by ';'?
src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 1035
Quoted 10 lines
src/dpp-util.c +10
-0+switch (*pos) { +case 'C' : + info->freqs =dpp_parse_class_and_channel (pos +2 ); +if (!info->freqs) + goto free_info; +break ; +case 'M' : + ret =dpp_parse_mac (pos +2 , info->mac); +if (ret <0 ) + goto free_info;
This doesn't seem to be checking that parse_mac consumes the entire token?
src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 1040
Quoted 5 lines
src/dpp-util.c +5
-0+break ; +case 'V' : + ret =dpp_parse_version (pos +2 , &info->version); +if (ret <0 ) + goto free_info;
This does...
src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 1045
Quoted 5 lines
src/dpp-util.c +5
-0+break ; +case 'K' : + info->boot_public =dpp_parse_key (pos +2 ); +if (!info->boot_public) + goto free_info;
Unclear here?
Quoted 14 lines
src/dpp-util.c +14
-0+break ; +case 'H' : +case 'I' : +break ; +default : + goto free_info; + } + } + +/* Extra data found after last token */ +if (pos != end) + goto free_info; + +/* The public bootstrapping key is the only required token */
src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 1069
Quoted 10 lines
src/dpp-util.c +10
-0+if (!info->boot_public) + goto free_info; + +return info; + +free_info: +dpp_free_uri_info (info); +return NULL ; +} +
Regards,
-Denis
James Prestwood
Re: [PATCH v3 02/10] dpp-util: add URI parsing
Hi Denis,
<snip>
Quoted 6 lines
Quoted 6 lines
+ */
src/dpp-util.c +5
-0+struct dpp_uri_info *dpp_parse_uri (const char *uri) +{ + struct dpp_uri_info *info; + const char *pos = uri; + const char *end = uri + strlen(uri) - 1;
Quoted 8 lines
Quoted 4 lines
+ int ret = 0;
+
+ if (strncmp(pos, "DPP:", 4))
+ return NULL;strncmp? If the string has already been validated to be a valid string, then
strcmp is probably just fine.
Since we're only checking a substring of 'pos' (that the first 4 characters are DPP:) strncmp is needed.
Quoted 10 lines
src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 1025
Quoted 8 lines
src/dpp-util.c +7
-0+ + info = l_new(struct dpp_uri_info, 1); + + pos += 4; + + /* EasyConnect 5.2.1 - Bootstrapping information format */ + for (; TOKEN_OK(pos); pos = TOKEN_NEXT(pos, ';')) {You don't seem to be validating that the token is terminated by ';'?
Yeah, I'll get the length here and pass that to each parse function to verify the entire token was consumed.
Quoted 25 lines
Quoted 12 lines
+ switch (*pos) {
+ case 'C':
+ info->freqs =dpp_parse_class_and_channel(pos + 2);
+ if (!info->freqs)
+ gotofree_info;
+ break;
+ case 'M':
+ ret =dpp_parse_mac(pos + 2, info->mac); + if (ret < 0)
+ gotofree_info;This doesn't seem to be checking that
parse_macconsumes the entire token?Quoted 6 lines
+ break;
+ case 'V':
+ ret = dpp_parse_version(pos + 2, &info-Quoted 1 line
version);
+ if (ret < 0)
+ gotofree_info;This does...
Quoted 7 lines
Quoted 5 lines
+ break;
+ case 'K':
+ info->boot_public =dpp_parse_key(pos + 2); + if (!info->boot_public)
+ gotofree_info;Unclear here?
This one is tricky because l_base64_decode doesn't give back the number of characters consumed... Maybe l_base64_decode should fail if the bytes consumed != length? I don't see any such checks in there.
Quoted 29 lines
Quoted 18 lines
+ break;
+ case 'H':
+ case 'I':
+ break;
+ default:
+ gotofree_info;
+ }
+ }src/dpp-util.c +6
-0+ + /* Extra data found after last token */ + if (pos != end) + goto free_info; + + /* The public bootstrapping key is the only required token*/
+ if (!info->boot_public)
+ gotofree_info;src/dpp-util.c struct l_ecc_point *dpp_point_from_asn1(const uint8_t *asn1, size_t len) · line 1069
Quoted 8 lines
src/dpp-util.c +8
-0+ + return info; + +free_info: + dpp_free_uri_info(info); + return NULL; +} +Regards,
-Denis
Denis Kenzior
Re: [PATCH v3 02/10] dpp-util: add URI parsing
Hi James,
Quoted 18 lines · James Prestwood
Hi Denis,
<snip>
Quoted 6 lines
Quoted 6 lines
+ */
src/dpp-util.c +5
-0+struct dpp_uri_info *dpp_parse_uri (const char *uri) +{ + struct dpp_uri_info *info; + const char *pos = uri; + const char *end = uri + strlen(uri) - 1;Quoted 8 lines
Quoted 4 lines
+ int ret = 0;
+
+ if (strncmp(pos, "DPP:", 4))
+ return NULL;strncmp? If the string has already been validated to be a valid string, then
strcmp is probably just fine.
Quoted 2 lines
Since we're only checking a substring of 'pos' (that the first 4 characters are DPP:) strncmp is needed.
Ah yes, ignore that comment.
Do note that l_str_has_prefix() exists, so that might be even nicer to use here.
Quoted 7 lines
Quoted 2 lines
Unclear here?
This one is tricky because
l_base64_decodedoesn't give back the number of characters consumed... Maybel_base64_decodeshould fail if the bytes consumed != length? I don't see any such checks in there.
Yes, we probably should.
Regards,
-Denis
James Prestwood
PATCH v3 3/10 unit: add DPP unit tests for URI parsing
In reply to James Prestwood--- unit/test-dpp.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+)
unit/test-dpp.c +142 -0
@@ -33,6 +33,134 @@#include "src/util.h" #include "ell/useful.h" +struct dpp_test_info { +const char *uri; +bool expect_fail; +uint32_t expected_freqs[10 ]; +struct dpp_uri_info result; +}; + +struct dpp_test_info all_values = { + .uri ="DPP:C:81/1,115/36;I:SN=4774LH2b4044;M:5254005828e5;V:2;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .result = { + .mac = {0x52 ,0x54 ,0x00 ,0x58 ,0x28 ,0xe5 }, + .version =2 , + }, + .expected_freqs = {2412 ,5180 ,0 } +}; + +struct dpp_test_info no_type = { + .uri ="C:81/1;K:shouldnotmatter;;" , + .expect_fail = true +}; + +struct dpp_test_info empty = { + .uri ="DPP:" , + .expect_fail = true +}; + +struct dpp_test_info no_key = { + .uri ="DPP:C:81/1,115/36;I:SN=4774LH2b4044;M:5254005828e5;V:2;;" , + .expect_fail = true +}; + +struct dpp_test_info data_after_terminator = { + .uri ="DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;C:81/1;;" , + .expect_fail = true +}; + +struct dpp_test_info single_terminator = { + .uri ="DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;" , + .expect_fail = true +}; + +struct dpp_test_info no_terminator = { + .uri ="DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=" , + .expect_fail = true +}; + +struct dpp_test_info bad_key = { + .uri ="DPP:K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0;;" , + .expect_fail = true +}; + +struct dpp_test_info unexpected_id = { + .uri ="DPP:Z:somedata;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true +}; + +struct dpp_test_info bad_channels[] = { + { + .uri ="DPP:C:;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81/1,;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81/1,81/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, + { + .uri ="DPP:C:81/1,/;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;" , + .expect_fail = true + }, +}; + +static bool verify_info (const struct dpp_uri_info *parsed, +const struct dpp_test_info *result) +{ +const struct dpp_uri_info *expected = &result->result; +uint32_t i; + +assert (!memcmp (parsed->mac, expected->mac,6 )); +assert (parsed->version == expected->version); +assert (parsed->boot_public !=NULL ); + +for (i =0 ; result->expected_freqs[i]; i++) +assert (scan_freq_set_contains (parsed->freqs, + result->expected_freqs[i])); + +return true; +} + +static void test_uri_parse (const void *data) +{ +const struct dpp_test_info *test_info = data; +struct dpp_uri_info *info; +int ret; + + info =dpp_parse_uri (test_info->uri); +if (test_info->expect_fail) { +assert (info ==NULL ); +return ; + } + +assert (ret ==0 ); + +assert (verify_info (info, test_info)); + +dpp_free_uri_info (info); +} + + +static void test_bad_channels (const void *data) +{ +unsigned int i; + +for (i =0 ; i <L_ARRAY_SIZE (bad_channels); i++) +test_uri_parse (&bad_channels[i]); +} +/* * B.2 Test Vectors for DPP Authentication Using P-256 for * Responder-only Authentication
@@ -148,5 +276,19 @@ int main(int argc, char *argv[])l_test_add ("DPP test key derivation" , test_key_derivation,NULL ); +l_test_add ("DPP URI parse" , test_uri_parse, &all_values); +l_test_add ("DPP URI no type" , test_uri_parse, &no_type); +l_test_add ("DPP URI empty" , test_uri_parse, &empty); +l_test_add ("DPP URI no key" , test_uri_parse, &no_key); +l_test_add ("DPP URI data after terminator" , test_uri_parse, + &data_after_terminator); +l_test_add ("DPP URI single terminator" , test_uri_parse, + &single_terminator); +l_test_add ("DPP URI no terminator" , test_uri_parse, + &no_terminator); +l_test_add ("DPP URI bad key" , test_uri_parse, &bad_key); +l_test_add ("DPP URI bad channels" , test_bad_channels, &bad_channels); +l_test_add ("DPP URI unexpected ID" , test_uri_parse, &unexpected_id); +return l_test_run (); }
Signature · 1 line
2.34.1
James Prestwood
PATCH v3 4/10 frame-xchg: allow multicast frame watches
In reply to James PrestwoodThis adds a new boolean argument to frame_watch_add which when true will set the frame watch to forward multicast frames.
--- src/ap.c | 12 ++++++------ src/dpp.c | 10 +++++----- src/frame-xchg.c | 15 ++++++++++----- src/frame-xchg.h | 8 ++++---- src/netdev.c | 10 +++++----- src/p2p.c | 4 ++-- src/rrm.c | 4 ++-- src/station.c | 2 +- 8 files changed, 35 insertions(+), 30 deletions(-)
src/ap.c +6 -6
@@ -3228,32 +3228,32 @@ struct ap_state *ap_start(struct netdev *netdev, struct l_settings *config,l_uintset_put (ap->rates,22 );/* 11 Mbps*/ } -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_ASSOCIATION_REQUEST <<4 ),NULL ,0 , ap_assoc_req_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_REASSOCIATION_REQUEST <<4 ),NULL ,0 , ap_reassoc_req_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_PROBE_REQUEST <<4 ),NULL ,0 , ap_probe_req_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_DISASSOCIATION <<4 ),NULL ,0 , ap_disassoc_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_AUTHENTICATION <<4 ),NULL ,0 , ap_auth_cb, ap,NULL )) goto error; -if (!frame_watch_add (wdev_id,0 ,0x0000 | +if (!frame_watch_add (wdev_id,0 , false,0x0000 | (MPDU_MANAGEMENT_SUBTYPE_DEAUTHENTICATION <<4 ),NULL ,0 , ap_deauth_cb, ap,NULL )) goto error;
src/dpp.c +5 -5
@@ -1687,14 +1687,14 @@ static void dpp_create(struct netdev *netdev)l_dbus_object_add_interface (dbus,netdev_get_path (netdev),IWD_DPP_INTERFACE , dpp); -frame_watch_add (netdev_get_wdev_id (netdev),0 ,0x00d0 , dpp_prefix, -sizeof (dpp_prefix), dpp_handle_frame, - dpp,NULL ); -frame_watch_add (netdev_get_wdev_id (netdev),0 ,0x00d0 , +frame_watch_add (netdev_get_wdev_id (netdev),0 , false,0x00d0 , + dpp_prefix,sizeof (dpp_prefix), + dpp_handle_frame, dpp,NULL ); +frame_watch_add (netdev_get_wdev_id (netdev),0 , false,0x00d0 , dpp_conf_response_prefix,sizeof (dpp_conf_response_prefix), dpp_handle_config_response_frame, dpp,NULL ); -frame_watch_add (netdev_get_wdev_id (netdev),0 ,0x00d0 , +frame_watch_add (netdev_get_wdev_id (netdev),0 , false,0x00d0 , dpp_conf_request_prefix,sizeof (dpp_conf_request_prefix), dpp_handle_config_request_frame, dpp,NULL );
src/frame-xchg.c +10 -5
@@ -573,10 +573,10 @@ drop:return true; } -bool frame_watch_add (uint64_t wdev_id,uint32_t group_id,uint16_t frame_type, -const uint8_t *prefix,size_t prefix_len, -frame_watch_cb_t handler,void *user_data, -frame_xchg_destroy_func_t destroy) +bool frame_watch_add (uint64_t wdev_id,uint32_t group_id,bool mcast, +uint16_t frame_type,const uint8_t *prefix, +size_t prefix_len,frame_watch_cb_t handler, +void *user_data,frame_xchg_destroy_func_t destroy) {struct watch_group *group =frame_watch_group_get (wdev_id, group_id);struct frame_watch *watch;
@@ -611,6 +611,11 @@ bool frame_watch_add(uint64_t wdev_id, uint32_t group_id, uint16_t frame_type,l_genl_msg_append_attr (msg,NL80211_ATTR_WDEV ,8 , &wdev_id);l_genl_msg_append_attr (msg,NL80211_ATTR_FRAME_TYPE ,2 , &frame_type); + +if (mcast) +l_genl_msg_append_attr (msg,NL80211_ATTR_RECEIVE_MULTICAST , +0 ,NULL ); +l_genl_msg_append_attr (msg,NL80211_ATTR_FRAME_MATCH , prefix_len, prefix);
@@ -1193,7 +1198,7 @@ uint32_t frame_xchg_startv(uint64_t wdev_id, struct iovec *frame, uint32_t freq, watch = l_new(struct frame_xchg_watch_data, 1); watch->prefix = prefix; watch->cb = va_arg(resp_args, void *); -frame_watch_add (wdev_id, group_id,0x00d0 , +frame_watch_add (wdev_id, group_id, false,0x00d0 , prefix->data, prefix->len, frame_xchg_resp_cb, fx,NULL );
src/frame-xchg.h +4 -4
@@ -36,10 +36,10 @@ struct frame_xchg_prefix {size_t len; }; -bool frame_watch_add (uint64_t wdev_id,uint32_t group,uint16_t frame_type, -const uint8_t *prefix,size_t prefix_len, -frame_watch_cb_t handler,void *user_data, -frame_xchg_destroy_func_t destroy); +bool frame_watch_add (uint64_t wdev_id,uint32_t group,bool mcast, +uint16_t frame_type,const uint8_t *prefix, +size_t prefix_len,frame_watch_cb_t handler, +void *user_data,frame_xchg_destroy_func_t destroy);bool frame_watch_group_remove (uint64_t wdev_id,uint32_t group);bool frame_watch_wdev_remove (uint64_t wdev_id);
src/netdev.c +5 -5
@@ -5783,24 +5783,24 @@ static void netdev_add_station_frame_watches(struct netdev *netdev)uint64_t wdev = netdev->wdev_id;/* Subscribe to Management -> Action -> RM -> Neighbor Report frames */ -frame_watch_add (wdev,0 ,0x00d0 , action_neighbor_report_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_neighbor_report_prefix,sizeof (action_neighbor_report_prefix), netdev_neighbor_report_frame_event, netdev,NULL ); -frame_watch_add (wdev,0 ,0x00d0 , action_sa_query_resp_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_sa_query_resp_prefix,sizeof (action_sa_query_resp_prefix), netdev_sa_query_resp_frame_event, netdev,NULL ); -frame_watch_add (wdev,0 ,0x00d0 , action_sa_query_req_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_sa_query_req_prefix,sizeof (action_sa_query_req_prefix), netdev_sa_query_req_frame_event, netdev,NULL ); -frame_watch_add (wdev,0 ,0x00d0 , action_ft_response_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_ft_response_prefix,sizeof (action_ft_response_prefix), netdev_ft_response_frame_event, netdev,NULL );if (wiphy_supports_qos_set_map (netdev->wiphy)) -frame_watch_add (wdev,0 ,0x00d0 , action_qos_map_prefix, +frame_watch_add (wdev,0 ,0x00d0 , false, action_qos_map_prefix,sizeof (action_qos_map_prefix), netdev_qos_map_frame_event, netdev,NULL ); }
src/p2p.c +2 -2
@@ -4154,9 +4154,9 @@ static void p2p_device_discovery_start(struct p2p_device *dev) dev->listen_channel = channels_social[l_getrandom_uint32 () %L_ARRAY_SIZE (channels_social)]; -frame_watch_add (dev->wdev_id,FRAME_GROUP_LISTEN ,0x0040 , +frame_watch_add (dev->wdev_id,FRAME_GROUP_LISTEN , false,0x0040 , (uint8_t *)"" ,0 , p2p_device_probe_cb, dev,NULL ); -frame_watch_add (dev->wdev_id,FRAME_GROUP_LISTEN ,0x00d0 , +frame_watch_add (dev->wdev_id,FRAME_GROUP_LISTEN , false,0x00d0 , p2p_frame_go_neg_req.data, p2p_frame_go_neg_req.len, p2p_device_go_negotiation_req_cb, dev,NULL );
src/rrm.c +2 -2
@@ -793,8 +793,8 @@ static void rrm_add_frame_watches(struct rrm_state *rrm)l_debug ("" ); -frame_watch_add (rrm->wdev_id,0 , frame_type, prefix,sizeof (prefix), - rrm_frame_watch_cb, rrm,NULL ); +frame_watch_add (rrm->wdev_id,0 , false, frame_type, prefix, +sizeof (prefix), rrm_frame_watch_cb, rrm,NULL ); }static struct rrm_state *rrm_new_state (struct netdev *netdev)
src/station.c +1 -1
@@ -4462,7 +4462,7 @@ static void add_frame_watches(struct netdev *netdev)/* * register for AP roam transition watch */ -frame_watch_add (netdev_get_wdev_id (netdev),0 ,0x00d0 , +frame_watch_add (netdev_get_wdev_id (netdev),0 , false,0x00d0 , action_ap_roam_prefix,sizeof (action_ap_roam_prefix), ap_roam_frame_event,L_UINT_TO_PTR (netdev_get_ifindex (netdev)),NULL );
Signature · 1 line
2.34.1
Denis Kenzior
Re: [PATCH v3 04/10] frame-xchg: allow multicast frame watches
Hi James,
src/frame-xchg.h struct frame_xchg_prefix { · line 42
Quoted 9 lines
src/frame-xchg.h +4
-4-bool frame_watch_add (uint64_t wdev_id,uint32_t group,uint16_t frame_type, -const uint8_t *prefix,size_t prefix_len, -frame_watch_cb_t handler,void *user_data, -frame_xchg_destroy_func_t destroy); +bool frame_watch_add (uint64_t wdev_id,uint32_t group,bool mcast, +uint16_t frame_type,const uint8_t *prefix, +size_t prefix_len,frame_watch_cb_t handler, +void *user_data,frame_xchg_destroy_func_t destroy);
Can we just add frame_watch_add_multicast_allowed instead? The number of arguments in frame_watch_add is already too much.
Quoted 3 lines
bool frame_watch_group_remove(uint64_t wdev_id, uint32_t group); bool frame_watch_wdev_remove(uint64_t wdev_id);
Regards,
-Denis
Andrew Zaborowski
Re: [PATCH v3 04/10] frame-xchg: allow multicast frame watches
Hi,
Quoted 11 lines · Denis Kenzior
src/frame-xchg.h struct frame_xchg_prefix { · line 42
Quoted 8 lines
src/frame-xchg.h +4
-4-bool frame_watch_add (uint64_t wdev_id,uint32_t group,uint16_t frame_type, -const uint8_t *prefix,size_t prefix_len, -frame_watch_cb_t handler,void *user_data, -frame_xchg_destroy_func_t destroy); +bool frame_watch_add (uint64_t wdev_id,uint32_t group,bool mcast, +uint16_t frame_type,const uint8_t *prefix, +size_t prefix_len,frame_watch_cb_t handler, +void *user_data,frame_xchg_destroy_func_t destroy);Can we just add
frame_watch_add_multicast_allowedinstead? The number of arguments inframe_watch_addis already too much.
The NL80211_ATTR_RECEIVE_MULTICAST flag needs to be set when we send the REGISTER_FRAME but since we have this logic to track duplicate and/or more general prefix watches, in some situations the logic may decide that there's no need to register a new longer prefix. In other situations it will register a new, shorter prefix and the MULTICAST flag will affect existing watches set for more specific prefixes.
It may be easier to always set the flag in the REGISTER_FRAMEs and check whether the received frame was multicast before calling the frame callback. In that case the multicast flag can be set on a watch in a separate call, after frame_watch_add.
Best regards
James Prestwood
Re: [PATCH v3 04/10] frame-xchg: allow multicast frame watches
Quoted 29 lines · Andrew Zaborowski
Hi,
Quoted 8 lines · Denis Kenzior
Quoted 8 lines
-bool frame_watch_add(uint64_t
wdev_id,uint32_tgroup,uint16_tframe_type,
- constuint8_t*prefix,size_tprefix_len, -frame_watch_cb_thandler, void*user_data, -frame_xchg_destroy_func_tdestroy); +bool frame_watch_add(uint64_twdev_id,uint32_tgroup, bool mcast,
+uint16_tframe_type, constuint8_t*prefix,Quoted 8 lines
Quoted 4 lines
+
size_tprefix_len,frame_watch_cb_thandler,
+ void*user_data,frame_xchg_destroy_func_tdestroy);Can we just add
frame_watch_add_multicast_allowedinstead? The number of
arguments inframe_watch_addis already too much.The
NL80211_ATTR_RECEIVE_MULTICASTflag needs to be set when we send theREGISTER_FRAMEbut since we have this logic to track duplicate and/or more general prefix watches, in some situations the logic may decide that there's no need to register a new longer prefix. In other
situations it will register a new, shorter prefix and the MULTICAST flag will affect existing watches set for more specific prefixes.
Quoted 5 lines
It may be easier to always set the flag in the
REGISTER_FRAMEsand check whether the received frame was multicast before calling the frame callback. In that case the multicast flag can be set on a watch
in a separate call, afterframe_watch_add.
So have frame_watch_set_multicast_allowed() act on entire groups rather than individual watches? I don't see any other way for it to work at least. And I'm not sure we want to do this for group 0 since it could impact other modules.
Maybe also we should start using non-zero groups, i.e. each module (DPP, P2P, ANQP etc.) use their own group number? Just an idea. Maybe this is what was intended all along but at least I haven't been doing that :)
Quoted 2 lines
Best regards
Andrew Zaborowski
Re: [PATCH v3 04/10] frame-xchg: allow multicast frame watches
Hi James,
Quoted 10 lines · James Prestwood
Quoted 5 lines · Andrew Zaborowski
It may be easier to always set the flag in the
REGISTER_FRAMEsand check whether the received frame was multicast before calling the frame callback. In that case the multicast flag can be set on a watch
in a separate call, afterframe_watch_add.So have
frame_watch_set_multicast_allowed()act on entire groups rather than individual watches? I don't see any other way for it to work at least.
That's a good idea too. I was thinking, since frame_watch_add() returns no watch ID, that you'd either pass the same set of arguments to frame_watch_set_multicast_allowed() that you passed to frame_watch_add() to identify the watch, or do frame_watch_set_multicast_by_handler (similar to frame_watch_remove_by_handler).
Quoted 2 lines
And I'm not sure we want to do this for group 0 since it could impact other modules.
Right.
Quoted 5 lines
Maybe also we should start using non-zero groups, i.e. each module (DPP, P2P, ANQP etc.) use their own group number? Just an idea. Maybe this is what was intended all along but at least I haven't been doing that :)
So the idea was to create groups for watches that may need to be removed before the interface is removed or has its iftype changed (those events implicitly discard watches) but it might also be useful to do for this multicast feature.
Best regards
James Prestwood
Re: [PATCH v3 04/10] frame-xchg: allow multicast frame watches
Hi Andrew,
Quoted 18 lines · Andrew Zaborowski
Hi James,
Quoted 8 lines · James Prestwood
Quoted 6 lines · Andrew Zaborowski
It may be easier to always set the flag in the
REGISTER_FRAMEsand
check whether the received frame was multicast before calling the frame callback. In that case the multicast flag can be set on a watch
in a separate call, afterframe_watch_add.Quoted 5 lines
So have
frame_watch_set_multicast_allowed()act on entire groups rather
than individual watches? I don't see any other way for it to work at
least.
Quoted 6 lines
That's a good idea too. I was thinking, since
frame_watch_add()returns no watch ID, that you'd either pass the same set of arguments toframe_watch_set_multicast_allowed()that you passed toframe_watch_add()to identify the watch, or doframe_watch_set_multicast_by_handler(similar toframe_watch_remove_by_handler).
Doing it by handler seems kinda weird for an exposed API, I would rather do it by group for simplicity. And for any module that needs multicast we just use a unique group.
Another option could be to return the watchlist ID from frame_watch_add, and something like watchlist_item_find(). Besides the few places that check the return I don't think this would be too intrusive.
Quoted 20 lines
Quoted 3 lines
And I'm not sure we want to do this for group 0 since it could impact other modules.
Right.
Quoted 7 lines
Maybe also we should start using non-zero groups, i.e. each module (DPP, P2P, ANQP etc.) use their own group number? Just an idea. Maybe
this is what was intended all along but at least I haven't been doing
that :)So the idea was to create groups for watches that may need to be removed before the interface is removed or has its iftype changed (those events implicitly discard watches) but it might also be useful to do for this multicast feature.
Best regards
James Prestwood
PATCH v3 5/10 dpp: add support for initiating as a configurator
In reply to James PrestwoodThe difference between the existing code is that IWD will send the authentication request, making it the initiator.
This handles the use case where IWD is provided a peers URI containing its bootstrapping key rather than IWD always providing its own URI. A new DBus API was added, ConfigureEnrollee().
Using ConfigureEnrollee() IWD will act as a configurator but begin by traversing a channel list (URI provided or default) and waiting for presence announcements. When an announcement is received IWD will send an authentication request to the peer, receive its reply, and send an authentication confirm.
As with being a responder, IWD only supports configuration to the currently connected BSS and will request the enrollee switch to this BSS's frequency to preserve network performance.
--- src/dpp.c | 451 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 448 insertions(+), 3 deletions(-)
v3:
* Fixed a few cleanup problems
src/dpp.c +448 -3
@@ -83,20 +83,33 @@ struct dpp_sm {uint8_t *own_asn1;size_t own_asn1_len; +uint8_t *peer_asn1; +size_t peer_asn1_len;uint8_t own_boot_hash[32 ]; +uint8_t peer_boot_hash[32 ];const struct l_ecc_curve *curve;size_t key_len;size_t nonce_len;struct l_ecc_scalar *boot_private;struct l_ecc_point *boot_public; +struct l_ecc_point *peer_boot_public;enum dpp_state state; +/* +* List of frequencies to jump between. The presence of this list is +* also used to signify that a configurator is an initiator vs responder +*/ uint32_t *freqs;size_t freqs_len;size_t freqs_idx;uint32_t dwell;uint32_t current_freq; +/* +* Frequency the remainder of the auth/config protocol will run on. +* For an initiating configurator this is the frequency of the currently +* connected BSS. +*/ uint32_t new_freq;struct scan_freq_set *presence_list;
@@ -107,7 +120,9 @@ struct dpp_sm {uint8_t i_nonce[32 ];uint8_t e_nonce[32 ]; +struct l_ecc_scalar *m;uint64_t ke[L_ECC_MAX_DIGITS ]; +uint64_t k1[L_ECC_MAX_DIGITS ];uint64_t k2[L_ECC_MAX_DIGITS ];uint64_t auth_tag[L_ECC_MAX_DIGITS ];
@@ -145,6 +160,16 @@ static void dpp_free_auth_data(struct dpp_sm *dpp)l_ecc_point_free (dpp->peer_proto_public); dpp->peer_proto_public =NULL ; } + +if (dpp->peer_boot_public) { +l_ecc_point_free (dpp->peer_boot_public); + dpp->peer_boot_public =NULL ; + } + +if (dpp->m) { +l_ecc_scalar_free (dpp->m); + dpp->m =NULL ; + } }static void dpp_reset (struct dpp_sm *dpp)
@@ -179,6 +204,11 @@ static void dpp_reset(struct dpp_sm *dpp) dpp->connect_scan_id =0 ; } +if (dpp->peer_asn1) { +l_free (dpp->peer_asn1); + dpp->peer_asn1 =NULL ; + } + dpp->state =DPP_STATE_NOTHING ; dpp->new_freq =0 ; dpp->frame_retry =0 ;
@@ -188,6 +218,7 @@ static void dpp_reset(struct dpp_sm *dpp)explicit_bzero (dpp->i_nonce, dpp->nonce_len);explicit_bzero (dpp->e_nonce, dpp->nonce_len);explicit_bzero (dpp->ke, dpp->key_len); +explicit_bzero (dpp->k1, dpp->key_len);explicit_bzero (dpp->k2, dpp->key_len);explicit_bzero (dpp->auth_tag, dpp->key_len);
@@ -1260,6 +1291,49 @@ static void dpp_presence_announce(struct dpp_sm *dpp)dpp_send_frame (dpp, iov,2 , dpp->current_freq); } +static void dpp_send_authenticate_request (struct dpp_sm *dpp) +{ +uint8_t hdr[32 ]; +uint8_t attrs[256 ]; +uint8_t *ptr = attrs; +uint64_t i_proto_key[L_ECC_MAX_DIGITS *2 ]; +uint8_t version =2 ; +struct iovec iov[2 ]; + +l_ecc_point_get_data (dpp->own_proto_public, i_proto_key, +sizeof (i_proto_key)); + + iov[0 ].iov_len =dpp_build_header (netdev_get_address (dpp->netdev), + dpp->auth_addr, +DPP_FRAME_AUTHENTICATION_REQUEST , hdr); + iov[0 ].iov_base = hdr; + + ptr +=dpp_append_attr (ptr,DPP_ATTR_RESPONDER_BOOT_KEY_HASH , + dpp->peer_boot_hash,32 ); + ptr +=dpp_append_attr (ptr,DPP_ATTR_INITIATOR_BOOT_KEY_HASH , + dpp->own_boot_hash,32 ); + ptr +=dpp_append_attr (ptr,DPP_ATTR_INITIATOR_PROTOCOL_KEY , + i_proto_key, dpp->key_len *2 ); + ptr +=dpp_append_attr (ptr,DPP_ATTR_PROTOCOL_VERSION , &version,1 ); + +if (dpp->current_freq != dpp->new_freq) { +uint8_t pair[2 ] = {81 , +band_freq_to_channel (dpp->new_freq,NULL ) }; + + ptr +=dpp_append_attr (ptr,DPP_ATTR_CHANNEL , pair,2 ); + } + + ptr +=dpp_append_wrapped_data (hdr +26 ,6 , attrs, ptr - attrs, + ptr,sizeof (attrs), dpp->k1, dpp->key_len,2 , +DPP_ATTR_INITIATOR_NONCE , dpp->nonce_len, dpp->i_nonce, +DPP_ATTR_INITIATOR_CAPABILITIES ,1 , &dpp->role); + + iov[1 ].iov_base = attrs; + iov[1 ].iov_len = ptr - attrs; + +dpp_send_frame (dpp, iov,2 , dpp->current_freq); +} +static void dpp_roc_started (void *user_data) {struct dpp_sm *dpp = user_data;
@@ -1574,6 +1648,301 @@ auth_request_failed:dpp_free_auth_data (dpp); } +static void dpp_send_authenticate_confirm (struct dpp_sm *dpp) +{ +uint8_t hdr[32 ]; +struct iovec iov[2 ]; +uint8_t attrs[256 ]; +uint8_t *ptr = attrs; +uint8_t zero =0 ; + + iov[0 ].iov_len =dpp_build_header (netdev_get_address (dpp->netdev), + dpp->auth_addr, +DPP_FRAME_AUTHENTICATION_CONFIRM , hdr); + iov[0 ].iov_base = hdr; + + ptr +=dpp_append_attr (ptr,DPP_ATTR_STATUS , &zero,1 ); + ptr +=dpp_append_attr (ptr,DPP_ATTR_RESPONDER_BOOT_KEY_HASH , + dpp->peer_boot_hash,32 ); + + ptr +=dpp_append_wrapped_data (hdr +26 ,6 , attrs, ptr - attrs, ptr, +sizeof (attrs), dpp->ke, dpp->key_len,1 , +DPP_ATTR_INITIATOR_AUTH_TAG , dpp->key_len, + dpp->auth_tag); + + iov[1 ].iov_base = attrs; + iov[1 ].iov_len = ptr - attrs; + +dpp_send_frame (dpp, iov,2 , dpp->current_freq); +} + +static void authenticate_response (struct dpp_sm *dpp,const uint8_t *from, +const uint8_t *body,size_t body_len) +{ +struct dpp_attr_iter iter; +enum dpp_attribute_type type; +size_t len; +const uint8_t *data; +int status =-1 ; +const void *r_boot_hash =NULL ; +const void *r_proto =NULL ; +size_t r_proto_len =0 ; +const void *wrapped =NULL ; +size_t wrapped_len; + _auto_(l_free) uint8_t *unwrapped1 = NULL; + _auto_(l_free) uint8_t *unwrapped2 = NULL; +const void *r_nonce =NULL ; +const void *i_nonce =NULL ; +const void *r_auth =NULL ; + _auto_(l_ecc_point_free) struct l_ecc_point *r_proto_key = NULL; + _auto_(l_ecc_scalar_free) struct l_ecc_scalar *n = NULL; +const void *ad0 = body +2 ; +const void *ad1 = body +8 ; +uint64_t r_auth_derived[L_ECC_MAX_DIGITS ]; + +l_debug ("Authenticate response" ); + +if (dpp->state !=DPP_STATE_AUTHENTICATING ) +return ; + +if (dpp->role !=DPP_CAPABILITY_CONFIGURATOR ) +return ; + +if (!dpp->freqs) +return ; + +if (memcmp (from, dpp->auth_addr,6 )) +return ; + +dpp_attr_iter_init (&iter, body +8 , body_len -8 ); + +while (dpp_attr_iter_next (&iter, &type, &len, &data)) { +switch (type) { +case DPP_ATTR_STATUS : +if (len !=1 ) +return ; + + status =l_get_u8 (data); +break ; +case DPP_ATTR_RESPONDER_BOOT_KEY_HASH : + r_boot_hash = data; +break ; +case DPP_ATTR_RESPONDER_PROTOCOL_KEY : + r_proto = data; + r_proto_len = len; +break ; +case DPP_ATTR_PROTOCOL_VERSION : +if (len !=1 ||l_get_u8 (data) !=2 ) +return ; +break ; +case DPP_ATTR_WRAPPED_DATA : + wrapped = data; + wrapped_len = len; +break ; +default : +break ; + } + } + +if (status !=DPP_STATUS_OK || !r_boot_hash || !r_proto ) { +l_debug ("Auth response bad status or missing attributes" ); +return ; + } + + r_proto_key =l_ecc_point_from_data (dpp->curve,L_ECC_POINT_TYPE_FULL , + r_proto, r_proto_len); +if (!r_proto_key) { +l_debug ("Peers protocol key was invalid" ); +return ; + } + + n =dpp_derive_k2 (r_proto_key, dpp->proto_private, dpp->k2); + + unwrapped1 =dpp_unwrap_attr (ad0,6 , ad1, wrapped -4 - ad1, dpp->k2, + dpp->key_len, wrapped, wrapped_len, + &wrapped_len); +if (!unwrapped1) { +l_debug ("Failed to unwrap primary data" ); +return ; + } + + wrapped =NULL ; + +dpp_attr_iter_init (&iter, unwrapped1, wrapped_len); + +while (dpp_attr_iter_next (&iter, &type, &len, &data)) { +switch (type) { +case DPP_ATTR_RESPONDER_NONCE : +if (len != dpp->nonce_len) +return ; + + r_nonce = data; +break ; +case DPP_ATTR_INITIATOR_NONCE : +if (len != dpp->nonce_len) +return ; + + i_nonce = data; +break ; +case DPP_ATTR_RESPONDER_CAPABILITIES : +break ; +case DPP_ATTR_WRAPPED_DATA : + wrapped = data; + wrapped_len = len; +break ; +default : +break ; + } + } + +if (!r_nonce || !i_nonce || !wrapped) { +l_debug ("Wrapped data missing attributes" ); +return ; + } + +if (!dpp_derive_ke (i_nonce, r_nonce, dpp->m, n, dpp->ke)) { +l_debug ("Failed to derive ke" ); +return ; + } + + unwrapped2 =dpp_unwrap_attr (NULL ,0 ,NULL ,0 , dpp->ke, dpp->key_len, + wrapped, wrapped_len, &wrapped_len); +if (!unwrapped2) { +l_debug ("Failed to unwrap secondary data" ); +return ; + } + +dpp_attr_iter_init (&iter, unwrapped2, wrapped_len); + +while (dpp_attr_iter_next (&iter, &type, &len, &data)) { +switch (type) { +case DPP_ATTR_RESPONDER_AUTH_TAG : +if (len != dpp->key_len) +return ; + + r_auth = data; +break ; +default : +break ; + } + } + +if (!r_auth) { +l_debug ("R-Auth was not in secondary wrapped data" ); +return ; + } + +if (!dpp_derive_r_auth (i_nonce, r_nonce, dpp->nonce_len, + dpp->own_proto_public, r_proto_key, + dpp->peer_boot_public, r_auth_derived)) { +l_debug ("Failed to derive r_auth" ); +return ; + } + +if (memcmp (r_auth, r_auth_derived, dpp->key_len)) { +l_debug ("R-Auth did not verify" ); +return ; + } + +if (!dpp_derive_i_auth (r_nonce, i_nonce, dpp->nonce_len, + r_proto_key, dpp->own_proto_public, + dpp->peer_boot_public, dpp->auth_tag)) { +l_debug ("Could not derive I-Auth" ); +return ; + } + + dpp->current_freq = dpp->new_freq; + +dpp_send_authenticate_confirm (dpp); +} + +static void dpp_handle_presence_announcement (struct dpp_sm *dpp, +const uint8_t *from, +const uint8_t *body, +size_t body_len) +{ +struct dpp_attr_iter iter; +enum dpp_attribute_type type; +size_t len; +const uint8_t *data; +const void *r_boot =NULL ; +size_t r_boot_len =0 ; +uint8_t hash[32 ]; + +l_debug ("Presence announcement " MAC ,MAC_STR (from)); + +/* Must be a configurator, in an initiator role, in PRESENCE state */ +if (dpp->state !=DPP_STATE_PRESENCE ) +return ; + +if (dpp->role !=DPP_CAPABILITY_CONFIGURATOR ) +return ; + +if (!dpp->freqs) +return ; + +/* +* The URI may not have contained a MAC address, if this announcement +* verifies set auth_addr then. +*/ +if (!l_memeqzero (dpp->auth_addr,6 ) && +memcmp (from, dpp->auth_addr,6 )) { +l_debug ("Unexpected source " MAC " expected " MAC ,MAC_STR (from), +MAC_STR (dpp->auth_addr)); +return ; + } + +dpp_attr_iter_init (&iter, body +8 , body_len -8 ); + +while (dpp_attr_iter_next (&iter, &type, &len, &data)) { +switch (type) { +case DPP_ATTR_RESPONDER_BOOT_KEY_HASH : + r_boot = data; + r_boot_len = len; +break ; +default : +break ; + } + } + +if (!r_boot || r_boot_len !=32 ) { +l_debug ("No responder boot hash" ); +return ; + } + +/* Hash what we have for the peer and check its our enrollee */ +dpp_hash (L_CHECKSUM_SHA256 , hash,2 ,"chirp" ,strlen ("chirp" ), + dpp->peer_asn1, dpp->peer_asn1_len); + +if (memcmp (hash, r_boot,sizeof (hash))) { +l_debug ("Peers boot hash did not match" ); +return ; + } + +/* +* This is the peer we expected, save away the address and derive the +* initial keys. +*/ +memcpy (dpp->auth_addr, from,6 ); + +l_ecdh_generate_key_pair (dpp->curve, &dpp->proto_private, + &dpp->own_proto_public); +l_getrandom (dpp->i_nonce, dpp->nonce_len); + + dpp->m =dpp_derive_k1 (dpp->peer_boot_public, dpp->proto_private, + dpp->k1); + + dpp->state =DPP_STATE_AUTHENTICATING ; + +dpp_send_authenticate_request (dpp); + +/* +* Should we wait for an ACK then go offchannel? +*/ +if (dpp->current_freq != dpp->new_freq) +dpp_start_offchannel (dpp, dpp->new_freq); +} +static void dpp_handle_frame (const struct mmpdu_header *frame,const void *body,size_t body_len,int rssi,void *user_data)
@@ -1595,6 +1964,9 @@ static void dpp_handle_frame(const struct mmpdu_header *frame,case DPP_FRAME_AUTHENTICATION_REQUEST :authenticate_request (dpp, frame->address_2, body, body_len);break ; +case DPP_FRAME_AUTHENTICATION_RESPONSE : +authenticate_response (dpp, frame->address_2, body, body_len); +break ;case DPP_FRAME_AUTHENTICATION_CONFIRM :authenticate_confirm (dpp, frame->address_2, body, body_len);break ;
@@ -1602,6 +1974,10 @@ static void dpp_handle_frame(const struct mmpdu_header *frame,dpp_handle_config_result_frame (dpp, frame->address_2, body, body_len);break ; +case DPP_FRAME_PRESENCE_ANNOUNCEMENT : +dpp_handle_presence_announcement (dpp, frame->address_2, + body, body_len); +break ;default :l_debug ("Unhandled DPP frame %u" , *ptr);break ;
@@ -1829,9 +2205,51 @@ static struct l_dbus_message *dpp_dbus_start_enrollee(struct l_dbus *dbus,return NULL ; } -static struct l_dbus_message *dpp_dbus_start_configurator (struct l_dbus *dbus, +/* +* Set up the configurator for an initiator role. The configurator +* will go offchannel to frequencies advertised by the enrollees URI or, +* if no channels are provided, use a default channel list. +*/ +static bool dpp_configurator_start_presence (struct dpp_sm *dpp,const char *uri) +{ + _auto_(l_free) uint32_t *freqs = NULL; +size_t freqs_len =0 ; +struct dpp_uri_info *info; + + info =dpp_parse_uri (uri); +if (!info) +return false; + +if (!l_memeqzero (info->mac,6 )) +memcpy (dpp->auth_addr, info->mac,6 ); + +if (info->freqs) + freqs =scan_freq_set_to_fixed_array (info->freqs, &freqs_len); + + dpp->peer_boot_public =l_ecc_point_clone (info->boot_public); + dpp->peer_asn1 =dpp_point_to_asn1 (info->boot_public, + &dpp->peer_asn1_len); + +dpp_free_uri_info (info); + +if (!dpp->peer_asn1) { +l_debug ("Peer boot key did not convert to asn1" ); +return false; + } + +dpp_hash (L_CHECKSUM_SHA256 , dpp->peer_boot_hash,1 , dpp->peer_asn1, + dpp->peer_asn1_len); + +dpp_start_presence (dpp, freqs, freqs_len); + +return true; +} + +static struct l_dbus_message *dpp_start_configurator_common ( +struct l_dbus *dbus,struct l_dbus_message *message, -void *user_data) +void *user_data, +bool responder) {struct dpp_sm *dpp = user_data;struct l_dbus_message *reply;
@@ -1840,6 +2258,7 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,struct network *network;struct l_settings *settings;struct handshake_state *hs =netdev_get_handshake (dpp->netdev); +const char *uri;/* * For now limit the configurator to only configuring enrollees to the
@@ -1863,13 +2282,23 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,if (dpp->state !=DPP_STATE_NOTHING )return dbus_error_busy (message); +if (!responder) { +if (!l_dbus_message_get_arguments (message,"s" , &uri)) +return dbus_error_invalid_args (message); + +if (!dpp_configurator_start_presence (dpp, uri)) +return dbus_error_invalid_args (message); + + dpp->new_freq = bss->frequency; + }else + dpp->current_freq = bss->frequency; + dpp->uri =dpp_generate_uri (dpp->own_asn1, dpp->own_asn1_len,2 ,netdev_get_address (dpp->netdev), &bss->frequency,1 ,NULL ,NULL ); dpp->state =DPP_STATE_PRESENCE ; dpp->role =DPP_CAPABILITY_CONFIGURATOR ; - dpp->current_freq = bss->frequency; dpp->config =dpp_configuration_new (settings,network_get_ssid (network), hs->akm_suite);
@@ -1885,6 +2314,20 @@ static struct l_dbus_message *dpp_dbus_start_configurator(struct l_dbus *dbus,return reply; } +static struct l_dbus_message *dpp_dbus_start_configurator (struct l_dbus *dbus, +struct l_dbus_message *message, +void *user_data) +{ +return dpp_start_configurator_common (dbus, message, user_data, true); +} + +static struct l_dbus_message *dpp_dbus_configure_enrollee (struct l_dbus *dbus, +struct l_dbus_message *message, +void *user_data) +{ +return dpp_start_configurator_common (dbus, message, user_data, false); +} +static struct l_dbus_message *dpp_dbus_stop (struct l_dbus *dbus,struct l_dbus_message *message,void *user_data)
@@ -1902,6 +2345,8 @@ static void dpp_setup_interface(struct l_dbus_interface *interface) dpp_dbus_start_enrollee, "s", "", "uri");l_dbus_interface_method (interface,"StartConfigurator" ,0 , dpp_dbus_start_configurator,"s" ,"" ,"uri" ); +l_dbus_interface_method (interface,"ConfigureEnrollee" ,0 , + dpp_dbus_configure_enrollee,"" ,"s" ,"uri" );l_dbus_interface_method (interface,"Stop" ,0 , dpp_dbus_stop,"" ,"" ); }
Signature · 1 line
2.34.1
James Prestwood
PATCH v3 6/10 auto-t: iwd.py: allow passing uri to start_configurator
In reply to James PrestwoodIf a URI is passed this will envoke ConfigureEnrollee()
--- autotests/util/iwd.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
autotests/util/iwd.py +7 -4
@@ -280,8 +280,11 @@ class DeviceProvisioning(IWDDBusAbstract): def start_enrollee(self): return self._iface.StartEnrollee() - def start_configurator(self): - return self._iface.StartConfigurator() + def start_configurator(self, uri=None): + if uri: + return self._iface.ConfigureEnrollee(uri) + else: + return self._iface.StartConfigurator() def stop(self): self._iface.Stop()
@@ -668,8 +671,8 @@ class Device(IWDDBusAbstract): def dpp_start_enrollee(self): return self._device_provisioning.start_enrollee() - def dpp_start_configurator(self): - return self._device_provisioning.start_configurator() + def dpp_start_configurator(self, uri=None): + return self._device_provisioning.start_configurator(uri) def dpp_stop(self): return self._device_provisioning.stop()
Signature · 1 line
2.34.1
James Prestwood
PATCH v3 7/10 auto-t: wpas.py: allow arbitrary events to be handled
In reply to James PrestwoodIf an event is in response to some command which is returning an unexpected value (unexpected with respect to wpas.py) handle_eow would raise an exception.
Specifically with DPP this was being hit when the URI was being returned.
--- autotests/util/wpas.py | 2 -- 1 file changed, 2 deletions(-)
autotests/util/wpas.py +0 -2
@@ -88,8 +88,6 @@ class Wpas: def handle_eow(): nonlocal key, value, count, event if count == 0: - if key is not None or not value: - raise Exception('Bad event name') key = 'event' elif key is None: if not value:
Signature · 1 line
2.34.1
James Prestwood
PATCH v3 8/10 auto-t: wpas.py: handle enrollee as responder
In reply to James PrestwoodThis adds support for wpa_supplicant to generate its own URI and start presence announcements (DPP_CHIRP).
--- autotests/util/wpas.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
autotests/util/wpas.py +14 -3
@@ -239,10 +239,17 @@ class Wpas: def set(self, key, value, **kwargs): self._ctrl_request('SET ' + key + ' ' + value, **kwargs) - def dpp_enrollee_start(self, uri=None): + def dpp_enrollee_start(self, uri=None, oper_and_channel=None): + if not oper_and_channel: + oper_and_channel = '81/1' + self._rx_data = [] - self._ctrl_request('DPP_BOOTSTRAP_GEN type=qrcode') - self.wait_for_result() + self._ctrl_request('DPP_BOOTSTRAP_GEN type=qrcode chan=%s' % oper_and_channel) + self._dpp_qr_id = self.wait_for_result() + self._ctrl_request('DPP_BOOTSTRAP_GET_URI %s' % self._dpp_qr_id) + self._dpp_uri = self.wait_for_result() + + print("DPP Enrollee QR: %s" % self._dpp_uri) if uri: self._rx_data = []
@@ -250,6 +257,10 @@ class Wpas: self._dpp_qr_id = self.wait_for_result() self._rx_data = [] self._ctrl_request('DPP_AUTH_INIT peer=%s role=enrollee' % self._dpp_qr_id) + else: + self._ctrl_request('DPP_CHIRP own=%s iter=100' % self._dpp_qr_id) + + return self._dpp_uri def dpp_configurator_create(self, uri): self._rx_data = []
Signature · 1 line
2.34.1
James Prestwood
PATCH v3 9/10 auto-t: add test for IWD as configurator + initiator
In reply to James Prestwood--- autotests/testDPP/connection_test.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
autotests/testDPP/connection_test.py +16 -0
@@ -82,6 +82,22 @@ class Test(unittest.TestCase): self.wpas.wait_for_event('DPP-CONF-RECEIVED') + def test_iwd_as_configurator_initiator(self): + self.hapd.reload() + self.hapd.wait_for_event('AP-ENABLED') + + IWD.copy_to_storage('ssidCCMP.psk') + self.device.autoconnect = True + + condition = 'obj.state == DeviceState.connected' + self.wd.wait_for_object_condition(self.device, condition) + + uri = self.wpas.dpp_enrollee_start(oper_and_channel='81/2') + + self.device.dpp_start_configurator(uri) + + self.hapd.wait_for_event('AP-STA-CONNECTED 42:00:00:00:00:00') + def setUp(self): self.wd = IWD(True) self.device = self.wd.list_devices(1)[0]
Signature · 1 line
2.34.1
James Prestwood
PATCH v3 10/10 doc: document DPP ConfigureEnrollee()
In reply to James Prestwood--- doc/device-provisioning-api.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
doc/device-provisioning-api.txt +16 -0
@@ -37,3 +37,19 @@ Methods string StartEnrollee() net.connman.iwd.NotConfigured net.connman.iwd.NotSupported net.connman.iwd.Busy + + string ConfigureEnrollee(string uri) + + Start a DPP configurator with an enrollees URI. + Ultimately the configuration itself remains the same as + StartConfigurator(). This API is to handle the use case + where the enrollee has shared its URI to IWD. + + The URI for IWD is also returned which could be used + in the same way as it is with StartConfigurator(). + + Possible errors: net.connman.iwd.NotAvailable + net.connman.iwd.NotConnected + net.connman.iwd.NotConfigured + net.connman.iwd.NotSupported + net.connman.iwd.Busy
Signature · 1 line
2.34.1
Denis Kenzior
AppliedHi James,
Quoted 5 lines · James Prestwood
This got merged without a few additional fixes, in particular an over 80 character line and incorrect length check.
--- src/dpp-util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Applied, thanks.
Regards,
-Denis