Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions libcfnet/client_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,34 @@
return false;
}

decrypted_cchall = xmalloc(encrypted_len);

if (RSA_private_decrypt(encrypted_len, in, (unsigned char *) decrypted_cchall, PRIVKEY, RSA_PKCS1_PADDING) <= 0)
/* RSA_private_decrypt() can write up to RSA_size() bytes, however short
* the ciphertext the server sent us is. */
decrypted_cchall = xmalloc(RSA_size(PRIVKEY));

const int decrypted_len = RSA_private_decrypt(
encrypted_len,
in,
(unsigned char *) decrypted_cchall,
PRIVKEY,
RSA_PKCS1_PADDING);
if (decrypted_len <= 0)
{
Log(LOG_LEVEL_ERR,
"Private decrypt failed, abandoning. (RSA_private_decrypt: %s)",
CryptoLastErrorString());
free(decrypted_cchall);
RSA_free(server_pubkey);
return false;
}

if (decrypted_len < nonce_len)
{
Log(LOG_LEVEL_ERR,
"Counter-challenge from server '%s' is too short (%d bytes, expected %d)",
conn->this_server,
decrypted_len,
nonce_len);
free(decrypted_cchall);
RSA_free(server_pubkey);
return false;
}
Expand Down
Loading