X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fopenssl%2Frsa.c;h=986c98f24e20888524654fd0f8a4a1d979a60a04;hp=9c880e6931212fba375fd60331bd68085ee95c0b;hb=d917c8cb6b69475d568ccbe82389b9f2b3eb5e80;hpb=8ac096b5bf9da1b3961a3ac4a03d083629222a63 diff --git a/src/openssl/rsa.c b/src/openssl/rsa.c index 9c880e69..986c98f2 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; } @@ -49,7 +54,7 @@ bool rsa_read_pem_public_key(rsa_t *rsa, FILE *fp) { if(*rsa) return true; - + *rsa = PEM_read_RSA_PUBKEY(fp, rsa, NULL, NULL); if(*rsa) @@ -64,7 +69,7 @@ bool rsa_read_pem_private_key(rsa_t *rsa, FILE *fp) { if(*rsa) return true; - + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA private key: %s", ERR_error_string(ERR_get_error(), NULL)); return false; } @@ -78,7 +83,7 @@ bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out) { return true; logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA encryption: %s", ERR_error_string(ERR_get_error(), NULL)); - return false; + return false; } bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) { @@ -86,7 +91,7 @@ bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) { return true; logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA decryption: %s", ERR_error_string(ERR_get_error(), NULL)); - return false; + return false; } bool rsa_active(rsa_t *rsa) {