DPP2: Add a helper function for building Presence Announcement frame

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
This commit is contained in:
Jouni Malinen 2020-03-26 23:41:27 +02:00 committed by Jouni Malinen
parent 7cba35b0ed
commit 1f0226770c
2 changed files with 50 additions and 23 deletions

View file

@ -1056,6 +1056,32 @@ static const struct dpp_curve_params * dpp_get_curve_nid(int nid)
} }
static int dpp_bi_pubkey_hash(struct dpp_bootstrap_info *bi,
const u8 *data, size_t data_len)
{
const u8 *addr[2];
size_t len[2];
addr[0] = data;
len[0] = data_len;
if (sha256_vector(1, addr, len, bi->pubkey_hash) < 0)
return -1;
wpa_hexdump(MSG_DEBUG, "DPP: Public key hash",
bi->pubkey_hash, SHA256_MAC_LEN);
addr[0] = (const u8 *) "chirp";
len[0] = 5;
addr[1] = data;
len[1] = data_len;
if (sha256_vector(2, addr, len, bi->pubkey_hash_chirp) < 0)
return -1;
wpa_hexdump(MSG_DEBUG, "DPP: Public key hash (chirp)",
bi->pubkey_hash_chirp, SHA256_MAC_LEN);
return 0;
}
static int dpp_parse_uri_pk(struct dpp_bootstrap_info *bi, const char *info) static int dpp_parse_uri_pk(struct dpp_bootstrap_info *bi, const char *info)
{ {
const char *end; const char *end;
@ -1094,14 +1120,11 @@ static int dpp_parse_uri_pk(struct dpp_bootstrap_info *bi, const char *info)
wpa_hexdump(MSG_DEBUG, "DPP: Base64 decoded URI public-key", wpa_hexdump(MSG_DEBUG, "DPP: Base64 decoded URI public-key",
data, data_len); data, data_len);
if (sha256_vector(1, (const u8 **) &data, &data_len, if (dpp_bi_pubkey_hash(bi, data, data_len) < 0) {
bi->pubkey_hash) < 0) {
wpa_printf(MSG_DEBUG, "DPP: Failed to hash public key"); wpa_printf(MSG_DEBUG, "DPP: Failed to hash public key");
os_free(data); os_free(data);
return -1; return -1;
} }
wpa_hexdump(MSG_DEBUG, "DPP: Public key hash",
bi->pubkey_hash, SHA256_MAC_LEN);
/* DER encoded ASN.1 SubjectPublicKeyInfo /* DER encoded ASN.1 SubjectPublicKeyInfo
* *
@ -1519,27 +1542,19 @@ fail:
} }
int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi) static int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi)
{ {
struct wpabuf *der; struct wpabuf *der;
int res; int res;
const u8 *addr[1];
size_t len[1];
der = dpp_bootstrap_key_der(bi->pubkey); der = dpp_bootstrap_key_der(bi->pubkey);
if (!der) if (!der)
return -1; return -1;
wpa_hexdump_buf(MSG_DEBUG, "DPP: Compressed public key (DER)", wpa_hexdump_buf(MSG_DEBUG, "DPP: Compressed public key (DER)",
der); der);
res = dpp_bi_pubkey_hash(bi, wpabuf_head(der), wpabuf_len(der));
addr[0] = wpabuf_head(der);
len[0] = wpabuf_len(der);
res = sha256_vector(1, addr, len, bi->pubkey_hash);
if (res < 0) if (res < 0)
wpa_printf(MSG_DEBUG, "DPP: Failed to hash public key"); wpa_printf(MSG_DEBUG, "DPP: Failed to hash public key");
else
wpa_hexdump(MSG_DEBUG, "DPP: Public key hash", bi->pubkey_hash,
SHA256_MAC_LEN);
wpabuf_free(der); wpabuf_free(der);
return res; return res;
} }
@ -1552,8 +1567,6 @@ static int dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
char *pos, *end; char *pos, *end;
size_t len; size_t len;
struct wpabuf *der = NULL; struct wpabuf *der = NULL;
const u8 *addr[1];
int res;
if (!curve) { if (!curve) {
bi->curve = &dpp_curves[0]; bi->curve = &dpp_curves[0];
@ -1579,15 +1592,10 @@ static int dpp_keygen(struct dpp_bootstrap_info *bi, const char *curve,
wpa_hexdump_buf(MSG_DEBUG, "DPP: Compressed public key (DER)", wpa_hexdump_buf(MSG_DEBUG, "DPP: Compressed public key (DER)",
der); der);
addr[0] = wpabuf_head(der); if (dpp_bi_pubkey_hash(bi, wpabuf_head(der), wpabuf_len(der)) < 0) {
len = wpabuf_len(der);
res = sha256_vector(1, addr, &len, bi->pubkey_hash);
if (res < 0) {
wpa_printf(MSG_DEBUG, "DPP: Failed to hash public key"); wpa_printf(MSG_DEBUG, "DPP: Failed to hash public key");
goto fail; goto fail;
} }
wpa_hexdump(MSG_DEBUG, "DPP: Public key hash", bi->pubkey_hash,
SHA256_MAC_LEN);
base64 = base64_encode(wpabuf_head(der), wpabuf_len(der), &len); base64 = base64_encode(wpabuf_head(der), wpabuf_len(der), &len);
wpabuf_free(der); wpabuf_free(der);
@ -12211,4 +12219,22 @@ void dpp_controller_stop(struct dpp_global *dpp)
} }
} }
struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi)
{
struct wpabuf *msg;
wpa_printf(MSG_DEBUG, "DPP: Build Presence Announcement frame");
msg = dpp_alloc_msg(DPP_PA_PRESENCE_ANNOUNCEMENT, 4 + SHA256_MAC_LEN);
if (!msg)
return NULL;
/* Responder Bootstrapping Key Hash */
dpp_build_attr_r_bootstrap_key_hash(msg, bi->pubkey_hash_chirp);
wpa_hexdump_buf(MSG_DEBUG,
"DPP: Presence Announcement frame attributes", msg);
return msg;
}
#endif /* CONFIG_DPP2 */ #endif /* CONFIG_DPP2 */

View file

@ -134,6 +134,7 @@ struct dpp_bootstrap_info {
int own; int own;
EVP_PKEY *pubkey; EVP_PKEY *pubkey;
u8 pubkey_hash[SHA256_MAC_LEN]; u8 pubkey_hash[SHA256_MAC_LEN];
u8 pubkey_hash_chirp[SHA256_MAC_LEN];
const struct dpp_curve_params *curve; const struct dpp_curve_params *curve;
unsigned int pkex_t; /* number of failures before dpp_pkex unsigned int pkex_t; /* number of failures before dpp_pkex
* instantiation */ * instantiation */
@ -436,7 +437,6 @@ extern size_t dpp_nonce_override_len;
void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info); void dpp_bootstrap_info_free(struct dpp_bootstrap_info *info);
const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type); const char * dpp_bootstrap_type_txt(enum dpp_bootstrap_type type);
int dpp_bootstrap_key_hash(struct dpp_bootstrap_info *bi);
int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi, int dpp_parse_uri_chan_list(struct dpp_bootstrap_info *bi,
const char *chan_list); const char *chan_list);
int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac); int dpp_parse_uri_mac(struct dpp_bootstrap_info *bi, const char *mac);
@ -596,6 +596,7 @@ int dpp_controller_start(struct dpp_global *dpp,
void dpp_controller_stop(struct dpp_global *dpp); void dpp_controller_stop(struct dpp_global *dpp);
int dpp_tcp_init(struct dpp_global *dpp, struct dpp_authentication *auth, int dpp_tcp_init(struct dpp_global *dpp, struct dpp_authentication *auth,
const struct hostapd_ip_addr *addr, int port); const struct hostapd_ip_addr *addr, int port);
struct wpabuf * dpp_build_presence_announcement(struct dpp_bootstrap_info *bi);
struct dpp_global_config { struct dpp_global_config {
void *msg_ctx; void *msg_ctx;