summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--rsa.c38
-rw-r--r--sshconnect.c21
3 files changed, 38 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index 368f1f674..47f90bc2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
4 - Integrated Makefile patch from Niels Kristian Bech Jensen <nkbj@image.dk> 4 - Integrated Makefile patch from Niels Kristian Bech Jensen <nkbj@image.dk>
5 - Autodetection of RSAref library for US users 5 - Autodetection of RSAref library for US users
6 - Minor doc updates 6 - Minor doc updates
7 - Merged OpenBSD CVS changes:
8 - [rsa.c] bugfix: use correct size for memset()
9 - [sshconnect.c] warn if announced size of modulus 'n' != real size
7 10
819991108 1119991108
9 - Removed debian/ directory. This is now being maintained separately. 12 - Removed debian/ directory. This is now being maintained separately.
diff --git a/rsa.c b/rsa.c
index 6845fab9d..61e53759d 100644
--- a/rsa.c
+++ b/rsa.c
@@ -35,7 +35,7 @@ Description of the RSA algorithm can be found e.g. from the following sources:
35*/ 35*/
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$Id: rsa.c,v 1.2 1999/11/08 04:30:59 damien Exp $"); 38RCSID("$Id: rsa.c,v 1.3 1999/11/08 23:35:52 damien Exp $");
39 39
40#include "rsa.h" 40#include "rsa.h"
41#include "ssh.h" 41#include "ssh.h"
@@ -110,28 +110,26 @@ void
110rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA* key) 110rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA* key)
111{ 111{
112 char *inbuf, *outbuf; 112 char *inbuf, *outbuf;
113 int in_len; 113 int len, ilen, olen;
114 int out_len;
115 int len;
116 114
117 if (BN_num_bits(key->e) < 2 || !BN_is_odd(key->e)) 115 if (BN_num_bits(key->e) < 2 || !BN_is_odd(key->e))
118 fatal("rsa_public_encrypt() exponent too small or not odd"); 116 fatal("rsa_public_encrypt() exponent too small or not odd");
119 117
120 out_len = BN_num_bytes(key->n); 118 olen = BN_num_bytes(key->n);
121 outbuf = xmalloc(out_len); 119 outbuf = xmalloc(olen);
122 120
123 in_len = BN_num_bytes(in); 121 ilen = BN_num_bytes(in);
124 inbuf = xmalloc(in_len); 122 inbuf = xmalloc(ilen);
125 BN_bn2bin(in, inbuf); 123 BN_bn2bin(in, inbuf);
126 124
127 if ((len = RSA_public_encrypt(in_len, inbuf, outbuf, key, 125 if ((len = RSA_public_encrypt(ilen, inbuf, outbuf, key,
128 RSA_PKCS1_PADDING)) <= 0) 126 RSA_PKCS1_PADDING)) <= 0)
129 fatal("rsa_public_encrypt() failed"); 127 fatal("rsa_public_encrypt() failed");
130 128
131 BN_bin2bn(outbuf, len, out); 129 BN_bin2bn(outbuf, len, out);
132 130
133 memset(outbuf, 0, out_len); 131 memset(outbuf, 0, olen);
134 memset(inbuf, 0, in_len); 132 memset(inbuf, 0, ilen);
135 xfree(outbuf); 133 xfree(outbuf);
136 xfree(inbuf); 134 xfree(inbuf);
137} 135}
@@ -140,25 +138,23 @@ void
140rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key) 138rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key)
141{ 139{
142 char *inbuf, *outbuf; 140 char *inbuf, *outbuf;
143 int in_len; 141 int len, ilen, olen;
144 int out_len;
145 int len;
146 142
147 out_len = BN_num_bytes(key->n); 143 olen = BN_num_bytes(key->n);
148 outbuf = xmalloc(out_len); 144 outbuf = xmalloc(olen);
149 145
150 in_len = BN_num_bytes(in); 146 ilen = BN_num_bytes(in);
151 inbuf = xmalloc(in_len); 147 inbuf = xmalloc(ilen);
152 BN_bn2bin(in, inbuf); 148 BN_bn2bin(in, inbuf);
153 149
154 if ((len = RSA_private_decrypt(in_len, inbuf, outbuf, key, 150 if ((len = RSA_private_decrypt(ilen, inbuf, outbuf, key,
155 RSA_SSLV23_PADDING)) <= 0) 151 RSA_SSLV23_PADDING)) <= 0)
156 fatal("rsa_private_decrypt() failed"); 152 fatal("rsa_private_decrypt() failed");
157 153
158 BN_bin2bn(outbuf, len, out); 154 BN_bin2bn(outbuf, len, out);
159 155
160 memset(outbuf, 0, out_len); 156 memset(outbuf, 0, olen);
161 memset(inbuf, 0, in_len); 157 memset(inbuf, 0, ilen);
162 xfree(outbuf); 158 xfree(outbuf);
163 xfree(inbuf); 159 xfree(inbuf);
164} 160}
diff --git a/sshconnect.c b/sshconnect.c
index a6f3788f5..a16e25a8d 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -16,7 +16,7 @@ login (authentication) dialog.
16 16
17#include "config.h" 17#include "config.h"
18#include "includes.h" 18#include "includes.h"
19RCSID("$Id: sshconnect.c,v 1.4 1999/11/08 05:15:55 damien Exp $"); 19RCSID("$Id: sshconnect.c,v 1.5 1999/11/08 23:35:52 damien Exp $");
20 20
21#ifdef HAVE_OPENSSL 21#ifdef HAVE_OPENSSL
22#include <openssl/bn.h> 22#include <openssl/bn.h>
@@ -1022,6 +1022,7 @@ void ssh_login(int host_key_valid,
1022 BIGNUM *key; 1022 BIGNUM *key;
1023 RSA *host_key, *file_key; 1023 RSA *host_key, *file_key;
1024 RSA *public_key; 1024 RSA *public_key;
1025 int bits, rbits;
1025 unsigned char session_key[SSH_SESSION_KEY_LENGTH]; 1026 unsigned char session_key[SSH_SESSION_KEY_LENGTH];
1026 const char *server_user, *local_user; 1027 const char *server_user, *local_user;
1027 char *cp, *host, *ip = NULL; 1028 char *cp, *host, *ip = NULL;
@@ -1068,7 +1069,7 @@ void ssh_login(int host_key_valid,
1068 1069
1069 /* Get the public key. */ 1070 /* Get the public key. */
1070 public_key = RSA_new(); 1071 public_key = RSA_new();
1071 packet_get_int(); /* bits */ 1072 bits = packet_get_int(); /* bits */
1072 public_key->e = BN_new(); 1073 public_key->e = BN_new();
1073 packet_get_bignum(public_key->e, &clen); 1074 packet_get_bignum(public_key->e, &clen);
1074 sum_len += clen; 1075 sum_len += clen;
@@ -1076,9 +1077,16 @@ void ssh_login(int host_key_valid,
1076 packet_get_bignum(public_key->n, &clen); 1077 packet_get_bignum(public_key->n, &clen);
1077 sum_len += clen; 1078 sum_len += clen;
1078 1079
1080 rbits = BN_num_bits(public_key->n);
1081 if (bits != rbits) {
1082 log("Warning: Server lies about size of server public key,");
1083 log("Warning: this may be due to an old implementation of ssh.");
1084 log("Warning: (actual size %d bits, announced size %d bits)", rbits, bits);
1085 }
1086
1079 /* Get the host key. */ 1087 /* Get the host key. */
1080 host_key = RSA_new(); 1088 host_key = RSA_new();
1081 packet_get_int(); /* bits */ 1089 bits = packet_get_int(); /* bits */
1082 host_key->e = BN_new(); 1090 host_key->e = BN_new();
1083 packet_get_bignum(host_key->e, &clen); 1091 packet_get_bignum(host_key->e, &clen);
1084 sum_len += clen; 1092 sum_len += clen;
@@ -1086,6 +1094,13 @@ void ssh_login(int host_key_valid,
1086 packet_get_bignum(host_key->n, &clen); 1094 packet_get_bignum(host_key->n, &clen);
1087 sum_len += clen; 1095 sum_len += clen;
1088 1096
1097 rbits = BN_num_bits(host_key->n);
1098 if (bits != rbits) {
1099 log("Warning: Server lies about size of server host key,");
1100 log("Warning: this may be due to an old implementation of ssh.");
1101 log("Warning: (actual size %d bits, announced size %d bits)", rbits, bits);
1102 }
1103
1089 /* Store the host key from the known host file in here 1104 /* Store the host key from the known host file in here
1090 * so that we can compare it with the key for the IP 1105 * so that we can compare it with the key for the IP
1091 * address. */ 1106 * address. */