X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fprotocol_key.c;h=b55e83078a045d975724de39d2d52cc0b57e61bf;hp=0ba5ad34f71b3f04cf9e510fa640806b7f62fdbe;hb=6685f2c8afc4775c3656dccc5a37286c01c0e854;hpb=8794274a30d535d49636fec825a0afbf30d8010d diff --git a/src/protocol_key.c b/src/protocol_key.c index 0ba5ad34..b55e8307 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -127,7 +127,8 @@ bool req_key_h(connection_t *c) { /* Check if this key request is for us */ if(to == myself) { /* Yes, send our own key back */ - send_ans_key(from); + if (!send_ans_key(from)) + return false; } else { if(tunnelserver) return true; @@ -156,7 +157,12 @@ bool send_ans_key(node_t *to) { to->inkey = xrealloc(to->inkey, to->inkeylength); // Create a new key - RAND_bytes((unsigned char *)to->inkey, to->inkeylength); + if (1 != RAND_bytes((unsigned char *)to->inkey, to->inkeylength)) { + int err = ERR_get_error(); + logger(LOG_ERR, "Failed to generate random for key (%s)", "SEND_ANS_KEY", ERR_error_string(err, NULL)); + return false; // Do not send insecure keys, let connection attempt fail. + } + if(to->incipher) EVP_DecryptInit_ex(&to->inctx, to->incipher, NULL, (unsigned char *)to->inkey, (unsigned char *)to->inkey + to->incipher->key_len);