Removed broken peer id methods

standardizing on the one in libp2p/crypto/key.c
yamux
John Jones 2017-02-02 19:09:20 -05:00
parent 94566ade69
commit 5666a8a2ef
4 changed files with 26 additions and 19 deletions

View File

@ -36,23 +36,29 @@ int PrettyID(unsigned char * pointyaddr, size_t* rezbuflen,unsigned char * ID_BU
return 1; return 1;
} }
/**** /****
* Make a SHA256 hash of what is usually the DER formatted private key. * Make a SHA256 hash of what is usually the DER formatted private key.
* @param result where to store the result. Should be 32 chars long * @param result where to store the result. Should be 32 chars long
* @param texttohash the text to hash. A DER formatted public key * @param texttohash the text to hash. A DER formatted public key
* @param text_size the size of the text * @param text_size the size of the text
*/ */
/*
void ID_FromPK_non_null_terminated(char * result,unsigned char * texttohash, size_t text_size) void ID_FromPK_non_null_terminated(char * result,unsigned char * texttohash, size_t text_size)
{ {
libp2p_crypto_hashing_sha256(texttohash, text_size, (unsigned char*)result); libp2p_crypto_hashing_sha256(texttohash, text_size, (unsigned char*)result);
} }
*/
/**** /****
* Make a SHA256 hash of what is usually the DER formatted private key. * Make a SHA256 hash of what is usually the DER formatted private key.
* @param result where to store the result. Should be 32 chars long * @param result where to store the result. Should be 32 chars long
* @param texttohash a null terminated string of the text to hash * @param texttohash a null terminated string of the text to hash
*/ */
/*
void ID_FromPK(char * result,unsigned char * texttohash) void ID_FromPK(char * result,unsigned char * texttohash)
{ {
ID_FromPK_non_null_terminated(result,texttohash,strlen((char*)texttohash)); ID_FromPK_non_null_terminated(result,texttohash,strlen((char*)texttohash));
} }
*/

View File

@ -47,7 +47,9 @@ int libp2p_secio_generate_nonce(char* results, int length) {
/*** /***
* performs initial communication over an insecure channel to share * performs initial communication over an insecure channel to share
* keys, IDs, and initiate connection. This is a framed messaging system * keys, IDs, and initiate connection. This is a framed messaging system
* NOTE: session must contain a valid socket_descriptor that is a multistream.
* @param session the secure session to be filled * @param session the secure session to be filled
* @param private_key the private key to use
* @returns true(1) on success, false(0) otherwise * @returns true(1) on success, false(0) otherwise
*/ */
int libp2p_secio_handshake(struct SecureSession* session, struct RsaPrivateKey* private_key) { int libp2p_secio_handshake(struct SecureSession* session, struct RsaPrivateKey* private_key) {
@ -59,11 +61,6 @@ int libp2p_secio_handshake(struct SecureSession* session, struct RsaPrivateKey*
struct Propose* propose_in = NULL; struct Propose* propose_in = NULL;
struct PublicKey* public_key = NULL; struct PublicKey* public_key = NULL;
// connect to host
session->socket_descriptor = libp2p_net_multistream_connect(session->host, session->port);
if (session->socket_descriptor == -1)
goto exit;
const unsigned char* protocol = (unsigned char*)"/secio/1.0.0\n"; const unsigned char* protocol = (unsigned char*)"/secio/1.0.0\n";
bytes_written = libp2p_net_multistream_send(session->socket_descriptor, protocol, strlen((char*)protocol)); bytes_written = libp2p_net_multistream_send(session->socket_descriptor, protocol, strlen((char*)protocol));
@ -107,12 +104,10 @@ int libp2p_secio_handshake(struct SecureSession* session, struct RsaPrivateKey*
propose_out = libp2p_secio_propose_new(); propose_out = libp2p_secio_propose_new();
libp2p_secio_propose_set_property((void**)&propose_out->rand, &propose_out->rand_size, nonceOut, 16); libp2p_secio_propose_set_property((void**)&propose_out->rand, &propose_out->rand_size, nonceOut, 16);
// TODO: the Peer ID looks funny. I don't think it is right.
// we have their information, now we need to gather ours. // we have their information, now we need to gather ours.
// will need: // will need:
// TODO: public key //
// supported exchanges // supported exchanges
libp2p_secio_propose_set_property((void**)&propose_out->exchanges, &propose_out->exchanges_size, SupportedExchanges, strlen(SupportedExchanges)); libp2p_secio_propose_set_property((void**)&propose_out->exchanges, &propose_out->exchanges_size, SupportedExchanges, strlen(SupportedExchanges));
// supported ciphers // supported ciphers

View File

@ -9,6 +9,7 @@
#include "libp2p/crypto/encoding/base64.h" #include "libp2p/crypto/encoding/base64.h"
#include "libp2p/crypto/encoding/x509.h" #include "libp2p/crypto/encoding/x509.h"
#include "libp2p/crypto/peerutils.h" #include "libp2p/crypto/peerutils.h"
#include "libp2p/crypto/key.h"
/** /**
@ -159,20 +160,19 @@ int test_crypto_rsa_public_key_to_peer_id() {
return 0; return 0;
// 3) grab the public key, hash it, then base58 it // 3) grab the public key, hash it, then base58 it
unsigned char hashed[32]; struct PublicKey public_key;
ID_FromPK_non_null_terminated((char*)hashed, (unsigned char*)private_key.public_key_der, private_key.public_key_length); public_key.type = KEYTYPE_RSA;
size_t final_id_size = 1600; public_key.data_size = private_key.public_key_length;
unsigned char final_id[final_id_size]; public_key.data = private_key.public_key_der;
memset(final_id, 0, final_id_size); char* final_id;
retVal = PrettyID(final_id, &final_id_size, hashed, 32); if (!libp2p_crypto_public_key_to_peer_id(&public_key, &final_id ))
if (retVal == 0)
return 0; return 0;
// 4) compare results // 4) compare results
if (orig_peer_id_size != final_id_size) if (orig_peer_id_size != strlen(final_id))
return 0; return 0;
if (strncmp(orig_peer_id, (char*)final_id, final_id_size) != 0) if (strncmp(orig_peer_id, (char*)final_id, strlen(final_id)) != 0)
return 0; return 0;
return 1; return 1;

View File

@ -1,6 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "libp2p/secio/secio.h" #include "libp2p/secio/secio.h"
#include "libp2p/net/multistream.h"
int test_secio_handshake() { int test_secio_handshake() {
@ -10,14 +11,15 @@ int test_secio_handshake() {
// this is a base64 encoded private key. It makes it easier to test if it is in base64 form // this is a base64 encoded private key. It makes it easier to test if it is in base64 form
// these were pulled from the GO version of ipfs // these were pulled from the GO version of ipfs
char* orig_priv_key = "CAASqgkwggSmAgEAAoIBAQD0a4RI+bF/ov7IVOGSJ8dQfnK1DwM0gwVuJAd+3LXxIZEPZzsKIKia0TojDbTdLvOJ23wsaojTF/4bSzBK5otdAz8YSgez4vTRUV5pUqvCkK0dSJJ1DHTdrFUwvzlXuKbwNbvWyzjmKfeaE9a9YLzhrUIUTRvKyqhZXr++vMy3hw4fdtGUTJWeiqmoIuJWIZ1748Ff6LjcP7TdG7OvY4q+U9ilEJYdF4aM+TJY193zKp0GNWohunuVrtOUnL9VQaSSDbvGdFS1Mg9iCN6kRBQTHVQvFzvuEw/Y2LvoPH3yFG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Su5zqhB3Du8Tom+8bYZUxOL4zhzCGrFitRqiEIIjy1/c5qyRQZaZx8CgYEA+lf6tdO6kKiAOxm7sdZ3rEl4UGFY+tEqgivKwurLRIor0XDfhCKr1hCfsZggpR8SMLfjCuNEgKbceofcKMa8OtyDbMPRz0mYNkCELTUYA+r8Ib/LvleQApMcLn+TDNwEnGlglSrrF33RVAUK+i/WfSXUvZRVpLQpRmdAqHjJeBkCgYEA0+Zz/iFXOGW32slJFWxRWqYz8VeZk52saGY/l/I/9Yj1J2tgugo7VtUS3BiB0ZGNK3SNfaxYmBz9KYO/Sew5DYnQqTdz1SHboQ2FAMAcnznutlNBVFdJnKPvkX8g5yBV05gApFgoPECUFn2jOP2coMjZ0M97Bjgil9YNUWvDdS0CgYEA4beFs3+tzVRAGgl/tD7dNBgiRMchBTSmkSuO6+PrVmcGTxboUSk5qg7fDa9Ob9LuAcMrENwNHbpVPJ1WoeVePewpC14bxDxk4zWUd3ZRquaqYnud5obor4mYdUxNd+DAv447qQNDaLDmlkzdsuqDB9+eSzh9Z72RIYtjPwN5E7ECgYEAsbqkMZXfK1tTRfduX+7KOlPMfcSr29X6nuDglcna4dHec6FAOzp3xL2722nnFt6gygc7pErrm0m0Wd/6BMTb4T3+GYwkDiMjM2CsTZYjpzrUri/VfRR509rScxHVR0/1PTFWN0K0+VZbEAyXDbbs4opq40tW0dWtcKxaNlimMw8=";
struct PrivateKey* private_key = libp2p_crypto_private_key_new();
struct RsaPrivateKey rsa_private_key = {0};
char* orig_peer_id = "QmbTyKkUuv6yaSpTuCFq1Ft6Q3g4wTtFJk1BLGMPRdAEP8"; char* orig_peer_id = "QmbTyKkUuv6yaSpTuCFq1Ft6Q3g4wTtFJk1BLGMPRdAEP8";
size_t orig_peer_id_size = strlen(orig_peer_id); size_t orig_peer_id_size = strlen(orig_peer_id);
struct RsaPrivateKey rsa_private_key = {0};
unsigned char hashed[32]; unsigned char hashed[32];
size_t final_id_size = 1600; size_t final_id_size = 1600;
unsigned char final_id[final_id_size]; unsigned char final_id[final_id_size];
struct PrivateKey* private_key = libp2p_crypto_private_key_new();
// 1) take the private key and turn it back into bytes (decode base 64) // 1) take the private key and turn it back into bytes (decode base 64)
decode_base64_size = libp2p_crypto_encoding_base64_decode_size(strlen(orig_priv_key)); decode_base64_size = libp2p_crypto_encoding_base64_decode_size(strlen(orig_priv_key));
decode_base64 = (unsigned char*)malloc(decode_base64_size); decode_base64 = (unsigned char*)malloc(decode_base64_size);
@ -44,6 +46,10 @@ int test_secio_handshake() {
secure_session.host = "www.jmjatlanta.com"; secure_session.host = "www.jmjatlanta.com";
secure_session.port = 4001; secure_session.port = 4001;
secure_session.traffic_type = TCP; secure_session.traffic_type = TCP;
// connect to host
secure_session.socket_descriptor = libp2p_net_multistream_connect(secure_session.host, secure_session.port);
if (secure_session.socket_descriptor == -1)
goto exit;
if (!libp2p_secio_handshake(&secure_session, &rsa_private_key)) if (!libp2p_secio_handshake(&secure_session, &rsa_private_key))
goto exit; goto exit;