X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fprotocol_key.c;h=22d2ff5403c4ff9e001169cc7ca1cb71d66f280f;hp=0ba5ad34f71b3f04cf9e510fa640806b7f62fdbe;hb=987f2a3dd64620141d30bb8b5d5f38733497af42;hpb=8794274a30d535d49636fec825a0afbf30d8010d diff --git a/src/protocol_key.c b/src/protocol_key.c index 0ba5ad34..22d2ff54 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)", 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);