X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fopenssl%2Frsa.c;h=efd63d53bb1d02d72b2fb0e71f9f92b229ef9ce0;hb=6dfdb323612184529b4b83c1be914dda8262de47;hp=c3ea692d6235e14662b716e88670aa19c6cdcb2d;hpb=483c5dcfb43719e5fd50902641252e28a04fd74e;p=tinc diff --git a/src/openssl/rsa.c b/src/openssl/rsa.c index c3ea692d..efd63d53 100644 --- a/src/openssl/rsa.c +++ b/src/openssl/rsa.c @@ -29,16 +29,21 @@ bool rsa_set_hex_public_key(rsa_t *rsa, char *n, char *e) { *rsa = RSA_new(); - BN_hex2bn(&(*rsa)->n, n); - BN_hex2bn(&(*rsa)->e, e); + if(BN_hex2bn(&(*rsa)->n, n) != strlen(n)) + return false; + if(BN_hex2bn(&(*rsa)->e, e) != strlen(e)) + return false; return true; } bool rsa_set_hex_private_key(rsa_t *rsa, char *n, char *e, char *d) { *rsa = RSA_new(); - BN_hex2bn(&(*rsa)->n, n); - BN_hex2bn(&(*rsa)->e, e); - BN_hex2bn(&(*rsa)->d, d); + if(BN_hex2bn(&(*rsa)->n, n) != strlen(n)) + return false; + if(BN_hex2bn(&(*rsa)->e, e) != strlen(e)) + return false; + if(BN_hex2bn(&(*rsa)->d, d) != strlen(d)) + return false; return true; } @@ -55,7 +60,7 @@ bool rsa_read_pem_public_key(rsa_t *rsa, FILE *fp) { if(*rsa) return true; - logger(LOG_ERR, "Unable to read RSA public key: %s", ERR_error_string(ERR_get_error(), NULL)); + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA public key: %s", ERR_error_string(ERR_get_error(), NULL)); return false; } @@ -65,7 +70,7 @@ bool rsa_read_pem_private_key(rsa_t *rsa, FILE *fp) { if(*rsa) return true; - logger(LOG_ERR, "Unable to read RSA private key: %s", ERR_error_string(ERR_get_error(), NULL)); + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA private key: %s", ERR_error_string(ERR_get_error(), NULL)); return false; } @@ -77,7 +82,7 @@ bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out) { if(RSA_public_encrypt(len, in, out, *rsa, RSA_NO_PADDING) == len) return true; - logger(LOG_ERR, "Unable to perform RSA encryption: %s", ERR_error_string(ERR_get_error(), NULL)); + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA encryption: %s", ERR_error_string(ERR_get_error(), NULL)); return false; } @@ -85,7 +90,7 @@ bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) { if(RSA_private_decrypt(len, in, out, *rsa, RSA_NO_PADDING) == len) return true; - logger(LOG_ERR, "Unable to perform RSA decryption: %s", ERR_error_string(ERR_get_error(), NULL)); + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA decryption: %s", ERR_error_string(ERR_get_error(), NULL)); return false; }