diff --git a/modules/crypto.c b/modules/crypto.c index c4bffbb..1193fb1 100644 --- a/modules/crypto.c +++ b/modules/crypto.c @@ -39,7 +39,6 @@ RSA *createRSAfromFile(char *file, int pub) { if(fp == NULL) { - printf("Unable to open file %s \n",file); return NULL; } RSA *rsa= RSA_new() ; @@ -72,6 +71,7 @@ RSA *generate_key() { BIO_free_all(bp_private); RSA_free(r); BN_free(bne); + return NULL; } r = RSA_new(); @@ -81,15 +81,16 @@ RSA *generate_key() { BIO_free_all(bp_private); RSA_free(r); BN_free(bne); + return NULL; } - bp_public = BIO_new_file("public.pem", "w+"); - ret = PEM_write_bio_RSAPublicKey(bp_public, r); + ret = PEM_write_bio_RSA_PUBKEY(bp_public, r); if(ret != 1){ BIO_free_all(bp_public); BIO_free_all(bp_private); RSA_free(r); BN_free(bne); + return NULL; } bp_private = BIO_new_file("private.pem", "w+"); @@ -187,4 +188,12 @@ int base64Decode(const char* input, unsigned char**buffer,size_t* len) { //Decod return (0); //success } +void printOpenSSLError(char *msg) { + char * err = malloc(130);; + ERR_load_crypto_strings(); + ERR_error_string(ERR_get_error(), err); + logger_log("%s ERROR: %s\n",msg, err); + free(err); +} + diff --git a/modules/crypto.h b/modules/crypto.h index 03d7ec5..e8a0087 100644 --- a/modules/crypto.h +++ b/modules/crypto.h @@ -14,6 +14,7 @@ #include #include #include +#include "../utility.h" @@ -29,4 +30,4 @@ int private_decrypt(unsigned char * enc_data,int data_len,unsigned char * key, u int base64Encode(const unsigned char* input ,size_t len, char** outpub); size_t calcDecodeLength(const char* b64input); int base64Decode(const char* input, unsigned char**buffer,size_t* len); -void printLastError(char *msg); \ No newline at end of file +void printOpenSSLError(char *msg); \ No newline at end of file diff --git a/modules/peer.c b/modules/peer.c index 1edf232..2fcddc9 100644 --- a/modules/peer.c +++ b/modules/peer.c @@ -24,7 +24,6 @@ int peer_ConnetctTo(char* ip,int port,peerList* peerList, node_data my,fd_set* f char handshake[DEFAULT_BUFLEN],*base64Key; base64Encode((unsigned char*)my.pubkey_str,strlen(my.pubkey_str),&base64Key); sprintf(handshake,"@id=%s&port=%d&pubkey=%s",my.id,my.port,base64Key); - logger_log("%s",handshake); if(strlen(my.nick) != 0) { char buf[DEFAULT_BUFLEN]; ZeroMemory(buf,DEFAULT_BUFLEN); @@ -51,6 +50,7 @@ int peer_ConnetctTo(char* ip,int port,peerList* peerList, node_data my,fd_set* f return -1; } map m = getHandshakeData(buf); + map_dump(m); node_data node; strcpy(node.ip,ip); @@ -278,7 +278,7 @@ void peer_addTolist(peerList *list, struct peer p){ list->array[list->length++] = p; } void peer_removeFromList(struct peerList* list, int i){ - + closesocket(list->array[i].socket); for (int k=i; k < list->length-1; ++k) list->array[k] =list->array[k+1]; list->length--;