Skip to content
Snippets Groups Projects
Commit f5905943 authored by Anjan Chanda's avatar Anjan Chanda
Browse files

map: cntlrsync: fix build

parent 3646db99
No related branches found
No related tags found
No related merge requests found
Pipeline #108471 passed
...@@ -26,50 +26,37 @@ ...@@ -26,50 +26,37 @@
int build_sync_config_request(uint8_t *aladdr, uint8_t **m1, uint16_t *m1_size, int build_sync_config_request(uint8_t *aladdr, uint8_t **m1, uint16_t *m1_size,
void **key) void **key)
{ {
struct wsc_key *private_key; struct wsc_key *localkey;
uint8_t nonce_e[16]; uint8_t nonce_e[16];
uint8_t *buf; uint8_t *buf;
uint8_t *p; uint8_t *p;
size_t rem; size_t rem;
uint8_t *priv, *pub;
uint16_t priv_len = 0, pub_len = 0;
buf = calloc(1000, sizeof(uint8_t)); buf = calloc(1000, sizeof(uint8_t));
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
localkey = calloc(1, sizeof(*localkey));
/* generate key-pair */ if (!localkey) {
PLATFORM_GENERATE_DH_KEY_PAIR(&priv, &priv_len, &pub, &pub_len);
fprintf(stderr, "privlen = %d publen = %d\n", priv_len, pub_len);
private_key = calloc(1, sizeof(*private_key));
if (!private_key) {
free(buf); free(buf);
free(priv);
free(pub);
fprintf(stderr, "-ENOMEM\n"); fprintf(stderr, "-ENOMEM\n");
return -ENOMEM; return -ENOMEM;
} }
private_key->key = calloc(priv_len, sizeof(uint8_t)); /* generate key-pair */
if (!private_key->key) { if (PLATFORM_GENERATE_DH_KEY_PAIR(&localkey->key,
free(private_key); &localkey->keylen,
&localkey->pub,
&localkey->publen) != 0) {
free(localkey);
free(buf); free(buf);
free(priv); return -1;
free(pub);
fprintf(stderr, "-ENOMEM\n");
return -ENOMEM;
} }
private_key->keylen = priv_len;
if (priv_len > 0)
memcpy(private_key->key, priv, priv_len);
memcpy(private_key->macaddr, aladdr, 6); memcpy(localkey->macaddr, aladdr, 6);
get_random_bytes(16, nonce_e); get_random_bytes(16, nonce_e);
memcpy(private_key->nonce, nonce_e, 16); memcpy(localkey->nonce, nonce_e, 16);
p = buf; p = buf;
rem = 1000; rem = 1000;
...@@ -77,22 +64,17 @@ int build_sync_config_request(uint8_t *aladdr, uint8_t **m1, uint16_t *m1_size, ...@@ -77,22 +64,17 @@ int build_sync_config_request(uint8_t *aladdr, uint8_t **m1, uint16_t *m1_size,
if (wsc_put(&p, &rem, ATTR_MAC_ADDR, aladdr, 6) || if (wsc_put(&p, &rem, ATTR_MAC_ADDR, aladdr, 6) ||
wsc_put(&p, &rem, ATTR_ENROLLEE_NONCE, nonce_e, 16) || wsc_put(&p, &rem, ATTR_ENROLLEE_NONCE, nonce_e, 16) ||
wsc_put(&p, &rem, ATTR_PUBLIC_KEY, pub, pub_len)) { wsc_put(&p, &rem, ATTR_PUBLIC_KEY, localkey->pub, localkey->publen)) {
free(private_key->key); free(localkey->key);
free(private_key); free(localkey);
free(buf); free(buf);
free(priv);
free(pub);
fprintf(stderr, "Error adding wsc attributes\n"); fprintf(stderr, "Error adding wsc attributes\n");
return -1; return -1;
} }
*m1 = buf; *m1 = buf;
*m1_size = abs(p - buf); *m1_size = labs(p - buf);
*key = private_key; *key = localkey;
free(pub);
free(priv);
return 0; return 0;
} }
...@@ -116,8 +98,8 @@ int build_sync_config_response(uint8_t *m1, uint16_t m1_size, ...@@ -116,8 +98,8 @@ int build_sync_config_response(uint8_t *m1, uint16_t m1_size,
uint16_t local_privkey_len; uint16_t local_privkey_len;
uint8_t *local_privkey; uint8_t *local_privkey;
uint16_t priv_len = 0; size_t priv_len = 0;
uint16_t pub_len = 0; size_t pub_len = 0;
uint8_t nonce_r[16]; uint8_t nonce_r[16];
uint8_t *priv; uint8_t *priv;
uint8_t *pub; uint8_t *pub;
...@@ -189,14 +171,13 @@ int build_sync_config_response(uint8_t *m1, uint16_t m1_size, ...@@ -189,14 +171,13 @@ int build_sync_config_response(uint8_t *m1, uint16_t m1_size,
if (ret) if (ret)
return -1; return -1;
fprintf(stderr, "plen|%d|, publen|%d|\n", priv_len, pub_len);
local_privkey = priv; local_privkey = priv;
local_privkey_len = priv_len; local_privkey_len = priv_len;
{ {
uint8_t keys[WPS_AUTHKEY_LEN + WPS_KEYWRAPKEY_LEN + WPS_EMSK_LEN]; uint8_t keys[WPS_AUTHKEY_LEN + WPS_KEYWRAPKEY_LEN + WPS_EMSK_LEN];
uint8_t dhkey[SHA256_MAC_LEN]; uint8_t dhkey[SHA256_MAC_LEN];
uint8_t kdk[SHA256_MAC_LEN]; uint8_t kdk[SHA256_MAC_LEN];
uint16_t shared_secret_len; size_t shared_secret_len;
uint8_t *shared_secret; uint8_t *shared_secret;
const uint8_t *addr[3]; const uint8_t *addr[3];
size_t len[3]; size_t len[3];
...@@ -212,7 +193,8 @@ int build_sync_config_response(uint8_t *m1, uint16_t m1_size, ...@@ -212,7 +193,8 @@ int build_sync_config_response(uint8_t *m1, uint16_t m1_size,
m1_pubkey, m1_pubkey,
m1_pubkey_len, m1_pubkey_len,
local_privkey, local_privkey,
local_privkey_len); local_privkey_len,
pub, pub_len);
if (ret) if (ret)
goto out; goto out;
...@@ -452,8 +434,6 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key, ...@@ -452,8 +434,6 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key,
uint16_t m2_encrypted_settings_len = 0; uint16_t m2_encrypted_settings_len = 0;
uint8_t *m2_authenticator = NULL; uint8_t *m2_authenticator = NULL;
uint8_t m2_authenticator_present = 0; uint8_t m2_authenticator_present = 0;
uint8_t *m1_privkey;
uint16_t m1_privkey_len;
uint8_t *m1_macaddr; uint8_t *m1_macaddr;
uint8_t *m1_nonce; uint8_t *m1_nonce;
...@@ -479,8 +459,6 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key, ...@@ -479,8 +459,6 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key,
k = (struct wsc_key *)key; k = (struct wsc_key *)key;
m1_privkey = k->key;
m1_privkey_len = k->keylen;
m1_macaddr = k->macaddr; m1_macaddr = k->macaddr;
m1_nonce = k->nonce; m1_nonce = k->nonce;
...@@ -549,7 +527,7 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key, ...@@ -549,7 +527,7 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key,
/* derive keys - authkey, keywrapkey and emsk */ /* derive keys - authkey, keywrapkey and emsk */
{ {
uint8_t *shared_secret; uint8_t *shared_secret;
uint16_t shared_secret_len; size_t shared_secret_len;
const uint8_t *addr[3]; const uint8_t *addr[3];
size_t len[3]; size_t len[3];
uint8_t dhkey[SHA256_MAC_LEN]; uint8_t dhkey[SHA256_MAC_LEN];
...@@ -561,8 +539,8 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key, ...@@ -561,8 +539,8 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key,
&shared_secret_len, &shared_secret_len,
m2_pubkey, m2_pubkey,
m2_pubkey_len, m2_pubkey_len,
m1_privkey, k->key, k->keylen,
m1_privkey_len); k->pub, k->publen);
if (ret) if (ret)
return -1; return -1;
...@@ -603,7 +581,6 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key, ...@@ -603,7 +581,6 @@ int process_sync_config_response(uint8_t *m1, uint16_t m1_size, void *key,
fprintf(stderr, "WPS keys: \n"); fprintf(stderr, "WPS keys: \n");
bufprintf(m2_pubkey, m2_pubkey_len, "Registrar public key"); bufprintf(m2_pubkey, m2_pubkey_len, "Registrar public key");
/* bufprintf(m1_privkey, m1_privkey_len, "Enrollee private key"); */
bufprintf(shared_secret, shared_secret_len, "DH Shared secret"); bufprintf(shared_secret, shared_secret_len, "DH Shared secret");
//bufprintf(dhkey, 32, "DH Key"); //bufprintf(dhkey, 32, "DH Key");
//bufprintf(m1_nonce, 16, "Nonce-E"); //bufprintf(m1_nonce, 16, "Nonce-E");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment