compare peer id from file with the one generated from the private key

This commit is contained in:
John Jones 2017-07-31 15:16:54 -05:00
parent ac5a622400
commit 835b70c97f

View file

@ -397,16 +397,15 @@ int fs_repo_open_config(struct FSRepo* repo) {
// the next should be the array, then string "PeerID"
//NOTE: the code below compares the peer id of the file with the peer id generated
// by the key. If they don't match, we fail.
repo->config->identity->peer = libp2p_peer_new();
_get_json_string_value(data, tokens, num_tokens, curr_pos, "PeerID", &repo->config->identity->peer->id);
// build the Libp2pPeer object
repo->config->identity->peer->id_size = strlen(repo->config->identity->peer->id);
repo->config->identity->peer->is_local = 1;
unsigned char* test_peer_id = NULL;
_get_json_string_value(data, tokens, num_tokens, curr_pos, "PeerID", &test_peer_id);
char* priv_key_base64;
// then PrivKey
_get_json_string_value(data, tokens, num_tokens, curr_pos, "PrivKey", &priv_key_base64);
retVal = repo_config_identity_build_private_key(repo->config->identity, priv_key_base64);
if (retVal == 0) {
if (retVal == 0
|| strlen(test_peer_id) != repo->config->identity->peer->id_size
|| strcmp(test_peer_id, repo->config->identity->peer->id) != 0) {
free(data);
free(priv_key_base64);
return 0;