|
|
17e9d0 |
From dc2eaa017fe77e53bd9f1d4327a480d9bfe6cc6a Mon Sep 17 00:00:00 2001
|
|
|
17e9d0 |
From: Aris Adamantiadis <aris@0xbadc0de.be>
|
|
|
17e9d0 |
Date: Tue, 9 Feb 2016 15:09:27 +0100
|
|
|
17e9d0 |
Subject: [PATCH] dh: fix CVE-2016-0739
|
|
|
17e9d0 |
|
|
|
17e9d0 |
Due to a byte/bit confusion, the DH secret was too short. This file was
|
|
|
17e9d0 |
completely reworked and will be commited in a future version.
|
|
|
17e9d0 |
---
|
|
|
17e9d0 |
src/dh.c | 22 +++++++++++++++++-----
|
|
|
17e9d0 |
1 file changed, 17 insertions(+), 5 deletions(-)
|
|
|
17e9d0 |
|
|
|
17e9d0 |
diff --git a/src/dh.c b/src/dh.c
|
|
|
17e9d0 |
index e489a1d..d27b66e 100644
|
|
|
17e9d0 |
--- a/src/dh.c
|
|
|
17e9d0 |
+++ b/src/dh.c
|
|
|
17e9d0 |
@@ -227,15 +227,21 @@ void ssh_crypto_finalize(void) {
|
|
|
17e9d0 |
}
|
|
|
17e9d0 |
|
|
|
17e9d0 |
int dh_generate_x(ssh_session session) {
|
|
|
17e9d0 |
+ int keysize;
|
|
|
17e9d0 |
+ if (session->next_crypto->kex_type == SSH_KEX_DH_GROUP1_SHA1) {
|
|
|
17e9d0 |
+ keysize = 1023;
|
|
|
17e9d0 |
+ } else {
|
|
|
17e9d0 |
+ keysize = 2047;
|
|
|
17e9d0 |
+ }
|
|
|
17e9d0 |
session->next_crypto->x = bignum_new();
|
|
|
17e9d0 |
if (session->next_crypto->x == NULL) {
|
|
|
17e9d0 |
return -1;
|
|
|
17e9d0 |
}
|
|
|
17e9d0 |
|
|
|
17e9d0 |
#ifdef HAVE_LIBGCRYPT
|
|
|
17e9d0 |
- bignum_rand(session->next_crypto->x, 128);
|
|
|
17e9d0 |
+ bignum_rand(session->next_crypto->x, keysize);
|
|
|
17e9d0 |
#elif defined HAVE_LIBCRYPTO
|
|
|
17e9d0 |
- bignum_rand(session->next_crypto->x, 128, 0, -1);
|
|
|
17e9d0 |
+ bignum_rand(session->next_crypto->x, keysize, -1, 0);
|
|
|
17e9d0 |
#endif
|
|
|
17e9d0 |
|
|
|
17e9d0 |
/* not harder than this */
|
|
|
17e9d0 |
@@ -248,15 +254,21 @@ int dh_generate_x(ssh_session session) {
|
|
|
17e9d0 |
|
|
|
17e9d0 |
/* used by server */
|
|
|
17e9d0 |
int dh_generate_y(ssh_session session) {
|
|
|
17e9d0 |
- session->next_crypto->y = bignum_new();
|
|
|
17e9d0 |
+ int keysize;
|
|
|
17e9d0 |
+ if (session->next_crypto->kex_type == SSH_KEX_DH_GROUP1_SHA1) {
|
|
|
17e9d0 |
+ keysize = 1023;
|
|
|
17e9d0 |
+ } else {
|
|
|
17e9d0 |
+ keysize = 2047;
|
|
|
17e9d0 |
+ }
|
|
|
17e9d0 |
+ session->next_crypto->y = bignum_new();
|
|
|
17e9d0 |
if (session->next_crypto->y == NULL) {
|
|
|
17e9d0 |
return -1;
|
|
|
17e9d0 |
}
|
|
|
17e9d0 |
|
|
|
17e9d0 |
#ifdef HAVE_LIBGCRYPT
|
|
|
17e9d0 |
- bignum_rand(session->next_crypto->y, 128);
|
|
|
17e9d0 |
+ bignum_rand(session->next_crypto->y, keysize);
|
|
|
17e9d0 |
#elif defined HAVE_LIBCRYPTO
|
|
|
17e9d0 |
- bignum_rand(session->next_crypto->y, 128, 0, -1);
|
|
|
17e9d0 |
+ bignum_rand(session->next_crypto->y, keysize, -1, 0);
|
|
|
17e9d0 |
#endif
|
|
|
17e9d0 |
|
|
|
17e9d0 |
/* not harder than this */
|
|
|
17e9d0 |
--
|
|
|
17e9d0 |
2.7.1
|
|
|
17e9d0 |
|
|
|
17e9d0 |
|