Skip to contentSkip to conversation

dpp-util: Introduce dpp-util, and add crypto operations

PATCH Applied James Prestwood 2 participants 6 messages Dec 6, 2021 Kbuild

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/4 dpp-util: Introduce dpp-util, and add crypto operations

---
 Makefile.am    |   1 +
 src/dpp-util.c | 260 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/dpp-util.h |  46 +++++++++
 3 files changed, 307 insertions(+)
 create mode 100644 src/dpp-util.c
 create mode 100644 src/dpp-util.h
Makefile.am +1 -0
index d93dd2c9..25269a0d 100644
@@ -248,6 +248,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
 					src/band.h src/band.c \
 					src/sysfs.h src/sysfs.c \
 					src/offchannel.h src/offchannel.c \
+					src/dpp-util.h src/dpp-util.c \
 					$(eap_sources) \
 					$(builtin_sources)
 
src/dpp-util.c new file +260 -0

260 lines not on this page · raw message

src/dpp-util.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 2/4 dpp-util: add URI generation API

---
 src/dpp-util.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/dpp-util.h |  4 ++++
 2 files changed, 64 insertions(+)
src/dpp-util.c +60 -0
index 8482b1ff..ca641311 100644
@@ -33,6 +33,66 @@
 #include "src/dpp-util.h"
 #include "src/util.h"
 #include "src/crypto.h"
+#include "src/scan.h"
+
+static void append_freqs(struct l_string *uri, const uint32_t *freqs, size_t len)
+{
+	size_t i;
+	enum band_freq band;
+
+	l_string_append_printf(uri, "C:");
+
+	for (i = 0; i < len; i++) {
+		uint8_t oper_class;
+		uint8_t channel = band_freq_to_channel(freqs[i], &band);
+
+		/* For now use global operating classes */
+		if (band == BAND_FREQ_2_4_GHZ)
+			oper_class = 81;
+		else
+			oper_class = 115;
+
+		l_string_append_printf(uri, "%u/%u", oper_class, channel);
+
+		if (i != len - 1)
+			l_string_append_c(uri, ',');
+	}
+
+	l_string_append_c(uri, ';');
+}
+
+char *dpp_generate_uri(const uint8_t *asn1, size_t asn1_len, uint8_t version,
+			const uint8_t *mac, const uint32_t *freqs,
+			size_t freqs_len, const char *info, const char *host)
+{
+	struct l_string *uri = l_string_new(256);
+	char *base64;
+
+	base64 = l_base64_encode(asn1, asn1_len, 0);
+
+	l_string_append_printf(uri, "DPP:K:%s;", base64);
+	l_free(base64);
+
+	if (mac)
+		l_string_append_printf(uri, "M:%02x%02x%02x%02x%02x%02x;",
+					MAC_STR(mac));
+
+	if (freqs)
+		append_freqs(uri, freqs, freqs_len);
+
+	if (info)
+		l_string_append_printf(uri, "I:%s;", info);
+
+	if (host)
+		l_string_append_printf(uri, "H:%s;", host);
+
+	if (version)
+		l_string_append_printf(uri, "V:%u;", version);
+
+	l_string_append_c(uri, ';');
+
+	return l_string_unwrap(uri);
+}
 
 /*
  * EasyConnect 2.0 Table 3. Key and Nonce Length Dependency on Prime Length
src/dpp-util.h +4 -0
index 92fc38e3..971c0ce4 100644
@@ -22,6 +22,10 @@
 struct l_ecc_point;
 struct l_ecc_scalar;
 
+char *dpp_generate_uri(const uint8_t *asn1, size_t asn1_len, uint8_t version,
+			const uint8_t *mac, const uint32_t *freqs,
+			size_t freqs_len, const char *info, const char *host);
+
 size_t dpp_nonce_len_from_key_len(size_t len);
 
 bool dpp_hash(enum l_checksum_type type, uint8_t *out, unsigned int num, ...);
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH 2/4] dpp-util: add URI generation API

Quoted 10 lines · James Prestwood
---
  src/dpp-util.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
  src/dpp-util.h |  4 ++++
  2 files changed, 64 insertions(+)
src/dpp-util.c +0 -0
index 8482b1ff..ca641311 100644

src/dpp-util.c line 37

Quoted 5 lines
src/dpp-util.c +2 -0
@@ -33,6 +33,66 @@
  #include "src/dpp-util.h"
  #include "src/util.h"
  #include "src/crypto.h"
+#include "src/scan.h"
+

I switched this to include src/band.h instead of scan.h, which is what seems to be intended.

Also a whitespace fix for a line > 80 chars.

Patches 1-3 applied, thanks.

Regards,
-Denis

author
#3 lore raw

PATCH 3/4 dpp-util: add DPP attribute iteration APIs

In reply to James Prestwood
---
 src/dpp-util.c | 34 ++++++++++++++++++++++++++++++++++
 src/dpp-util.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)
src/dpp-util.c +34 -0
index ca641311..b7122de6 100644
@@ -94,6 +94,40 @@ char *dpp_generate_uri(const uint8_t *asn1, size_t asn1_len, uint8_t version,
 	return l_string_unwrap(uri);
 }
 
+void dpp_attr_iter_init(struct dpp_attr_iter *iter, const uint8_t *pdu,
+			size_t len)
+{
+	iter->pos = pdu;
+	iter->end = pdu + len;
+}
+
+bool dpp_attr_iter_next(struct dpp_attr_iter *iter,
+			enum dpp_attribute_type *type_out, size_t *len_out,
+			const uint8_t **data_out)
+{
+	enum dpp_attribute_type type;
+	size_t len;
+
+	if (iter->pos + 4 > iter->end)
+		return false;
+
+	type = l_get_le16(iter->pos);
+	len = l_get_le16(iter->pos + 2);
+
+	iter->pos += 4;
+
+	if (iter->pos + len > iter->end)
+		return false;
+
+	*type_out = type;
+	*len_out = len;
+	*data_out = iter->pos;
+
+	iter->pos += len;
+
+	return true;
+}
+
 /*
  * EasyConnect 2.0 Table 3. Key and Nonce Length Dependency on Prime Length
  */
src/dpp-util.h +49 -0

55 lines not on this page · raw message

Signature · 1 line
2.31.1
author
#4 lore raw

PATCH 4/4 unit: add unit test for DPP crypto operations

In reply to James Prestwood
---
 Makefile.am     |   7 ++-
 unit/test-dpp.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 1 deletion(-)
 create mode 100644 unit/test-dpp.c
Makefile.am +6 -1
index 25269a0d..5e33a48f 100644
@@ -394,7 +394,8 @@ unit_tests = unit/test-cmac-aes \
 		unit/test-crypto unit/test-eapol unit/test-mpdu \
 		unit/test-ie unit/test-util unit/test-ssid-security \
 		unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \
-		unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band
+		unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band \
+		unit/test-dpp
 
 if CLIENT
 unit_tests += unit/test-client
@@ -547,6 +548,10 @@ unit_test_p2p_SOURCES = unit/test-p2p.c src/wscutil.h src/wscutil.c \
 				src/band.h src/band.c
 unit_test_p2p_LDADD = $(ell_ldadd)
 
+unit_test_dpp_SOURCES = unit/test-dpp.c src/dpp-util.h src/dpp-util.c \
+				src/util.h src/util.c src/crypto.h src/crypto.c
+unit_test_dpp_LDADD = $(ell_ldadd)
+
 TESTS = $(unit_tests)
 
 EXTRA_DIST = src/genbuiltin src/iwd.service.in src/net.connman.iwd.service \
unit/test-dpp.c new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.31.1
Applied
#5 lore raw

Re: [PATCH 4/4] unit: add unit test for DPP crypto operations

Hi James,

Quoted 6 lines · James Prestwood
---
  Makefile.am     |   7 ++-
  unit/test-dpp.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 153 insertions(+), 1 deletion(-)

create mode 100644 unit/test-dpp.c

<snip>

Makefile.am unit_test_p2p_SOURCES = unit/test-p2p.c src/wscutil.h src/wscutil.c \ · line 552

Quoted 6 lines
Makefile.am +2 -0
@@ -547,6 +548,10 @@ unit_test_p2p_SOURCES = unit/test-p2p.c src/wscutil.h src/wscutil.c \
  				src/band.h src/band.c
  unit_test_p2p_LDADD = $(ell_ldadd)
 
+unit_test_dpp_SOURCES = unit/test-dpp.c src/dpp-util.h src/dpp-util.c \
+				src/util.h src/util.c src/crypto.h src/crypto.c

I had to add src/band.[ch] here

Quoted 5 lines
Makefile.am +2 -0
+unit_test_dpp_LDADD = $(ell_ldadd)
+
  TESTS = $(unit_tests)
 
  EXTRA_DIST = src/genbuiltin src/iwd.service.in src/net.connman.iwd.service \

<snip>

Quoted 1 line

+const char *i_proto_public_bytes = "50a532ae2a07207276418d2fa630295d45569be425aa634f02014d00a7d1f61a";

I changed some of these data lines to be 80 char / line compliant.

Applied, but I'm seeing this:

TEST: DPP test key derivation

=================================================================
==17289==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 536 byte(s) in 7 object(s) allocated from:

     #0 0x7f88cc96d0f8 in __interceptor_malloc 
(/usr/lib/gcc/x86_64-pc-linux-gnu/9.4.0/libasan.so.5+0x10c0f8)
     #1 0x4199d2 in l_malloc ell/util.c:62

SUMMARY: AddressSanitizer: 536 byte(s) leaked in 7 allocation(s).

Regards,
-Denis