summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2002-01-22 23:09:22 +1100
committerDamien Miller <djm@mindrot.org>2002-01-22 23:09:22 +1100
commitda7551677b301c6fd063eb162c7d32b37723a360 (patch)
treeee731b658802d003930540958f0b7ffc5a4a12bf
parent154dda73a858a5924c2f5684dfec3e377cc3ab5d (diff)
- markus@cvs.openbsd.org 2001/12/27 18:22:16
[auth1.c authfile.c auth-rsa.c dh.c kexdh.c kexgex.c key.c rsa.c scard.c ssh-agent.c sshconnect1.c sshd.c ssh-dss.c] call fatal() for openssl allocation failures
-rw-r--r--ChangeLog6
-rw-r--r--auth-rsa.c11
-rw-r--r--auth1.c31
-rw-r--r--authfile.c16
-rw-r--r--dh.c21
-rw-r--r--kexdh.c14
-rw-r--r--kexgex.c14
-rw-r--r--key.c52
-rw-r--r--rsa.c11
-rw-r--r--scard.c5
-rw-r--r--ssh-agent.c7
-rw-r--r--ssh-dss.c11
-rw-r--r--sshconnect1.c85
-rw-r--r--sshd.c5
14 files changed, 146 insertions, 143 deletions
diff --git a/ChangeLog b/ChangeLog
index 9f9772468..f69f3c95a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -35,6 +35,10 @@
35 - markus@cvs.openbsd.org 2001/12/27 18:10:29 35 - markus@cvs.openbsd.org 2001/12/27 18:10:29
36 [ssh-keygen.c] 36 [ssh-keygen.c]
37 -t is only needed for key generation (unbreaks -i, -e, etc). 37 -t is only needed for key generation (unbreaks -i, -e, etc).
38 - markus@cvs.openbsd.org 2001/12/27 18:22:16
39 [auth1.c authfile.c auth-rsa.c dh.c kexdh.c kexgex.c key.c rsa.c]
40 [scard.c ssh-agent.c sshconnect1.c sshd.c ssh-dss.c]
41 call fatal() for openssl allocation failures
38 42
3920020121 4320020121
40 - (djm) Rework ssh-rand-helper: 44 - (djm) Rework ssh-rand-helper:
@@ -7182,4 +7186,4 @@
7182 - Wrote replacements for strlcpy and mkdtemp 7186 - Wrote replacements for strlcpy and mkdtemp
7183 - Released 1.0pre1 7187 - Released 1.0pre1
7184 7188
7185$Id: ChangeLog,v 1.1732 2002/01/22 12:08:16 djm Exp $ 7189$Id: ChangeLog,v 1.1733 2002/01/22 12:09:22 djm Exp $
diff --git a/auth-rsa.c b/auth-rsa.c
index 5846a0662..de50b8ef8 100644
--- a/auth-rsa.c
+++ b/auth-rsa.c
@@ -14,7 +14,7 @@
14 */ 14 */
15 15
16#include "includes.h" 16#include "includes.h"
17RCSID("$OpenBSD: auth-rsa.c,v 1.46 2001/12/18 10:06:24 jakob Exp $"); 17RCSID("$OpenBSD: auth-rsa.c,v 1.47 2001/12/27 18:22:16 markus Exp $");
18 18
19#include <openssl/rsa.h> 19#include <openssl/rsa.h>
20#include <openssl/md5.h> 20#include <openssl/md5.h>
@@ -68,12 +68,15 @@ auth_rsa_challenge_dialog(RSA *pk)
68 u_int i; 68 u_int i;
69 int plen, len; 69 int plen, len;
70 70
71 encrypted_challenge = BN_new(); 71 if ((encrypted_challenge = BN_new()) == NULL)
72 challenge = BN_new(); 72 fatal("auth_rsa_challenge_dialog: BN_new() failed");
73 if ((challenge = BN_new()) == NULL)
74 fatal("auth_rsa_challenge_dialog: BN_new() failed");
73 75
74 /* Generate a random challenge. */ 76 /* Generate a random challenge. */
75 BN_rand(challenge, 256, 0, 0); 77 BN_rand(challenge, 256, 0, 0);
76 ctx = BN_CTX_new(); 78 if ((ctx = BN_CTX_new()) == NULL)
79 fatal("auth_rsa_challenge_dialog: BN_CTX_new() failed");
77 BN_mod(challenge, challenge, pk->n, ctx); 80 BN_mod(challenge, challenge, pk->n, ctx);
78 BN_CTX_free(ctx); 81 BN_CTX_free(ctx);
79 82
diff --git a/auth1.c b/auth1.c
index 41628cedc..921a1757a 100644
--- a/auth1.c
+++ b/auth1.c
@@ -10,7 +10,7 @@
10 */ 10 */
11 11
12#include "includes.h" 12#include "includes.h"
13RCSID("$OpenBSD: auth1.c,v 1.28 2001/12/25 18:53:00 markus Exp $"); 13RCSID("$OpenBSD: auth1.c,v 1.29 2001/12/27 18:22:16 markus Exp $");
14 14
15#include "xmalloc.h" 15#include "xmalloc.h"
16#include "rsa.h" 16#include "rsa.h"
@@ -66,7 +66,7 @@ do_authloop(Authctxt *authctxt)
66{ 66{
67 int authenticated = 0; 67 int authenticated = 0;
68 u_int bits; 68 u_int bits;
69 RSA *client_host_key; 69 Key *client_host_key;
70 BIGNUM *n; 70 BIGNUM *n;
71 char *client_user, *password; 71 char *client_user, *password;
72 char info[1024]; 72 char info[1024];
@@ -202,24 +202,20 @@ do_authloop(Authctxt *authctxt)
202 client_user = packet_get_string(&ulen); 202 client_user = packet_get_string(&ulen);
203 203
204 /* Get the client host key. */ 204 /* Get the client host key. */
205 client_host_key = RSA_new(); 205 client_host_key = key_new(KEY_RSA1);
206 if (client_host_key == NULL)
207 fatal("RSA_new failed");
208 client_host_key->e = BN_new();
209 client_host_key->n = BN_new();
210 if (client_host_key->e == NULL || client_host_key->n == NULL)
211 fatal("BN_new failed");
212 bits = packet_get_int(); 206 bits = packet_get_int();
213 packet_get_bignum(client_host_key->e, &elen); 207 packet_get_bignum(client_host_key->rsa->e, &elen);
214 packet_get_bignum(client_host_key->n, &nlen); 208 packet_get_bignum(client_host_key->rsa->n, &nlen);
215 209
216 if (bits != BN_num_bits(client_host_key->n)) 210 if (bits != BN_num_bits(client_host_key->rsa->n))
217 verbose("Warning: keysize mismatch for client_host_key: " 211 verbose("Warning: keysize mismatch for client_host_key: "
218 "actual %d, announced %d", BN_num_bits(client_host_key->n), bits); 212 "actual %d, announced %d",
213 BN_num_bits(client_host_key->rsa->n), bits);
219 packet_integrity_check(plen, (4 + ulen) + 4 + elen + nlen, type); 214 packet_integrity_check(plen, (4 + ulen) + 4 + elen + nlen, type);
220 215
221 authenticated = auth_rhosts_rsa(pw, client_user, client_host_key); 216 authenticated = auth_rhosts_rsa(pw, client_user,
222 RSA_free(client_host_key); 217 client_host_key->rsa);
218 key_free(client_host_key);
223 219
224 snprintf(info, sizeof info, " ruser %.100s", client_user); 220 snprintf(info, sizeof info, " ruser %.100s", client_user);
225 break; 221 break;
@@ -230,9 +226,8 @@ do_authloop(Authctxt *authctxt)
230 break; 226 break;
231 } 227 }
232 /* RSA authentication requested. */ 228 /* RSA authentication requested. */
233 n = BN_new(); 229 if ((n = BN_new()) == NULL)
234 if (n == NULL) 230 fatal("do_authloop: BN_new failed");
235 fatal("BN_new failed");
236 packet_get_bignum(n, &nlen); 231 packet_get_bignum(n, &nlen);
237 packet_integrity_check(plen, nlen, type); 232 packet_integrity_check(plen, nlen, type);
238 authenticated = auth_rsa(pw, n); 233 authenticated = auth_rsa(pw, n);
diff --git a/authfile.c b/authfile.c
index 3bfca4ac5..cd600362a 100644
--- a/authfile.c
+++ b/authfile.c
@@ -36,7 +36,7 @@
36 */ 36 */
37 37
38#include "includes.h" 38#include "includes.h"
39RCSID("$OpenBSD: authfile.c,v 1.42 2001/12/19 17:16:13 stevesk Exp $"); 39RCSID("$OpenBSD: authfile.c,v 1.43 2001/12/27 18:22:16 markus Exp $");
40 40
41#include <openssl/err.h> 41#include <openssl/err.h>
42#include <openssl/evp.h> 42#include <openssl/evp.h>
@@ -316,8 +316,6 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
316 char *cp; 316 char *cp;
317 CipherContext ciphercontext; 317 CipherContext ciphercontext;
318 Cipher *cipher; 318 Cipher *cipher;
319 BN_CTX *ctx;
320 BIGNUM *aux;
321 Key *prv = NULL; 319 Key *prv = NULL;
322 320
323 len = lseek(fd, (off_t) 0, SEEK_END); 321 len = lseek(fd, (off_t) 0, SEEK_END);
@@ -406,17 +404,7 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase,
406 buffer_get_bignum(&decrypted, prv->rsa->p); /* q */ 404 buffer_get_bignum(&decrypted, prv->rsa->p); /* q */
407 405
408 /* calculate p-1 and q-1 */ 406 /* calculate p-1 and q-1 */
409 ctx = BN_CTX_new(); 407 rsa_generate_additional_parameters(prv->rsa);
410 aux = BN_new();
411
412 BN_sub(aux, prv->rsa->q, BN_value_one());
413 BN_mod(prv->rsa->dmq1, prv->rsa->d, aux, ctx);
414
415 BN_sub(aux, prv->rsa->p, BN_value_one());
416 BN_mod(prv->rsa->dmp1, prv->rsa->d, aux, ctx);
417
418 BN_clear_free(aux);
419 BN_CTX_free(ctx);
420 408
421 buffer_free(&decrypted); 409 buffer_free(&decrypted);
422 close(fd); 410 close(fd);
diff --git a/dh.c b/dh.c
index fa2508af7..a5d6f379c 100644
--- a/dh.c
+++ b/dh.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: dh.c,v 1.17 2001/06/23 15:12:18 itojun Exp $"); 26RCSID("$OpenBSD: dh.c,v 1.18 2001/12/27 18:22:16 markus Exp $");
27 27
28#include "xmalloc.h" 28#include "xmalloc.h"
29 29
@@ -78,8 +78,10 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
78 if (cp != NULL || *prime == '\0') 78 if (cp != NULL || *prime == '\0')
79 goto fail; 79 goto fail;
80 80
81 dhg->g = BN_new(); 81 if ((dhg->g = BN_new()) == NULL)
82 dhg->p = BN_new(); 82 fatal("parse_prime: BN_new failed");
83 if ((dhg->p = BN_new()) == NULL)
84 fatal("parse_prime: BN_new failed");
83 if (BN_hex2bn(&dhg->g, gen) == 0) 85 if (BN_hex2bn(&dhg->g, gen) == 0)
84 goto failclean; 86 goto failclean;
85 87
@@ -202,8 +204,7 @@ dh_gen_key(DH *dh, int need)
202 do { 204 do {
203 if (dh->priv_key != NULL) 205 if (dh->priv_key != NULL)
204 BN_free(dh->priv_key); 206 BN_free(dh->priv_key);
205 dh->priv_key = BN_new(); 207 if ((dh->priv_key = BN_new()) == NULL)
206 if (dh->priv_key == NULL)
207 fatal("dh_gen_key: BN_new failed"); 208 fatal("dh_gen_key: BN_new failed");
208 /* generate a 2*need bits random private exponent */ 209 /* generate a 2*need bits random private exponent */
209 if (!BN_rand(dh->priv_key, 2*need, 0, 0)) 210 if (!BN_rand(dh->priv_key, 2*need, 0, 0))
@@ -225,9 +226,8 @@ dh_new_group_asc(const char *gen, const char *modulus)
225{ 226{
226 DH *dh; 227 DH *dh;
227 228
228 dh = DH_new(); 229 if ((dh = DH_new()) == NULL)
229 if (dh == NULL) 230 fatal("dh_new_group_asc: DH_new");
230 fatal("DH_new");
231 231
232 if (BN_hex2bn(&dh->p, modulus) == 0) 232 if (BN_hex2bn(&dh->p, modulus) == 0)
233 fatal("BN_hex2bn p"); 233 fatal("BN_hex2bn p");
@@ -247,9 +247,8 @@ dh_new_group(BIGNUM *gen, BIGNUM *modulus)
247{ 247{
248 DH *dh; 248 DH *dh;
249 249
250 dh = DH_new(); 250 if ((dh = DH_new()) == NULL)
251 if (dh == NULL) 251 fatal("dh_new_group: DH_new");
252 fatal("DH_new");
253 dh->p = modulus; 252 dh->p = modulus;
254 dh->g = gen; 253 dh->g = gen;
255 254
diff --git a/kexdh.c b/kexdh.c
index b850a1a22..1e9f35835 100644
--- a/kexdh.c
+++ b/kexdh.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: kexdh.c,v 1.7 2001/09/17 19:27:15 stevesk Exp $"); 26RCSID("$OpenBSD: kexdh.c,v 1.8 2001/12/27 18:22:16 markus Exp $");
27 27
28#include <openssl/crypto.h> 28#include <openssl/crypto.h>
29#include <openssl/bn.h> 29#include <openssl/bn.h>
@@ -129,8 +129,7 @@ kexdh_client(Kex *kex)
129 fatal("server_host_key verification failed"); 129 fatal("server_host_key verification failed");
130 130
131 /* DH paramter f, server public DH key */ 131 /* DH paramter f, server public DH key */
132 dh_server_pub = BN_new(); 132 if ((dh_server_pub = BN_new()) == NULL)
133 if (dh_server_pub == NULL)
134 fatal("dh_server_pub == NULL"); 133 fatal("dh_server_pub == NULL");
135 packet_get_bignum2(dh_server_pub, &dlen); 134 packet_get_bignum2(dh_server_pub, &dlen);
136 135
@@ -154,7 +153,8 @@ kexdh_client(Kex *kex)
154#ifdef DEBUG_KEXDH 153#ifdef DEBUG_KEXDH
155 dump_digest("shared secret", kbuf, kout); 154 dump_digest("shared secret", kbuf, kout);
156#endif 155#endif
157 shared_secret = BN_new(); 156 if ((shared_secret = BN_new()) == NULL)
157 fatal("kexdh_client: BN_new failed");
158 BN_bin2bn(kbuf, kout, shared_secret); 158 BN_bin2bn(kbuf, kout, shared_secret);
159 memset(kbuf, 0, klen); 159 memset(kbuf, 0, klen);
160 xfree(kbuf); 160 xfree(kbuf);
@@ -217,8 +217,7 @@ kexdh_server(Kex *kex)
217 fatal("Unsupported hostkey type %d", kex->hostkey_type); 217 fatal("Unsupported hostkey type %d", kex->hostkey_type);
218 218
219 /* key, cert */ 219 /* key, cert */
220 dh_client_pub = BN_new(); 220 if ((dh_client_pub = BN_new()) == NULL)
221 if (dh_client_pub == NULL)
222 fatal("dh_client_pub == NULL"); 221 fatal("dh_client_pub == NULL");
223 packet_get_bignum2(dh_client_pub, &dlen); 222 packet_get_bignum2(dh_client_pub, &dlen);
224 223
@@ -244,7 +243,8 @@ kexdh_server(Kex *kex)
244#ifdef DEBUG_KEXDH 243#ifdef DEBUG_KEXDH
245 dump_digest("shared secret", kbuf, kout); 244 dump_digest("shared secret", kbuf, kout);
246#endif 245#endif
247 shared_secret = BN_new(); 246 if ((shared_secret = BN_new()) == NULL)
247 fatal("kexdh_server: BN_new failed");
248 BN_bin2bn(kbuf, kout, shared_secret); 248 BN_bin2bn(kbuf, kout, shared_secret);
249 memset(kbuf, 0, klen); 249 memset(kbuf, 0, klen);
250 xfree(kbuf); 250 xfree(kbuf);
diff --git a/kexgex.c b/kexgex.c
index a35b301fc..b4fdac695 100644
--- a/kexgex.c
+++ b/kexgex.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26#include "includes.h" 26#include "includes.h"
27RCSID("$OpenBSD: kexgex.c,v 1.10 2001/12/05 10:06:12 deraadt Exp $"); 27RCSID("$OpenBSD: kexgex.c,v 1.11 2001/12/27 18:22:16 markus Exp $");
28 28
29#include <openssl/bn.h> 29#include <openssl/bn.h>
30 30
@@ -183,8 +183,7 @@ kexgex_client(Kex *kex)
183 fatal("server_host_key verification failed"); 183 fatal("server_host_key verification failed");
184 184
185 /* DH paramter f, server public DH key */ 185 /* DH paramter f, server public DH key */
186 dh_server_pub = BN_new(); 186 if ((dh_server_pub = BN_new()) == NULL)
187 if (dh_server_pub == NULL)
188 fatal("dh_server_pub == NULL"); 187 fatal("dh_server_pub == NULL");
189 packet_get_bignum2(dh_server_pub, &dlen); 188 packet_get_bignum2(dh_server_pub, &dlen);
190 189
@@ -208,7 +207,8 @@ kexgex_client(Kex *kex)
208#ifdef DEBUG_KEXDH 207#ifdef DEBUG_KEXDH
209 dump_digest("shared secret", kbuf, kout); 208 dump_digest("shared secret", kbuf, kout);
210#endif 209#endif
211 shared_secret = BN_new(); 210 if ((shared_secret = BN_new()) == NULL)
211 fatal("kexgex_client: BN_new failed");
212 BN_bin2bn(kbuf, kout, shared_secret); 212 BN_bin2bn(kbuf, kout, shared_secret);
213 memset(kbuf, 0, klen); 213 memset(kbuf, 0, klen);
214 xfree(kbuf); 214 xfree(kbuf);
@@ -315,8 +315,7 @@ kexgex_server(Kex *kex)
315 packet_read_expect(&plen, SSH2_MSG_KEX_DH_GEX_INIT); 315 packet_read_expect(&plen, SSH2_MSG_KEX_DH_GEX_INIT);
316 316
317 /* key, cert */ 317 /* key, cert */
318 dh_client_pub = BN_new(); 318 if ((dh_client_pub = BN_new()) == NULL)
319 if (dh_client_pub == NULL)
320 fatal("dh_client_pub == NULL"); 319 fatal("dh_client_pub == NULL");
321 packet_get_bignum2(dh_client_pub, &dlen); 320 packet_get_bignum2(dh_client_pub, &dlen);
322 321
@@ -342,7 +341,8 @@ kexgex_server(Kex *kex)
342#ifdef DEBUG_KEXDH 341#ifdef DEBUG_KEXDH
343 dump_digest("shared secret", kbuf, kout); 342 dump_digest("shared secret", kbuf, kout);
344#endif 343#endif
345 shared_secret = BN_new(); 344 if ((shared_secret = BN_new()) == NULL)
345 fatal("kexgex_server: BN_new failed");
346 BN_bin2bn(kbuf, kout, shared_secret); 346 BN_bin2bn(kbuf, kout, shared_secret);
347 memset(kbuf, 0, klen); 347 memset(kbuf, 0, klen);
348 xfree(kbuf); 348 xfree(kbuf);
diff --git a/key.c b/key.c
index 3a0ed046b..5288e2b6e 100644
--- a/key.c
+++ b/key.c
@@ -32,7 +32,7 @@
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34#include "includes.h" 34#include "includes.h"
35RCSID("$OpenBSD: key.c,v 1.37 2001/12/25 18:49:56 markus Exp $"); 35RCSID("$OpenBSD: key.c,v 1.38 2001/12/27 18:22:16 markus Exp $");
36 36
37#include <openssl/evp.h> 37#include <openssl/evp.h>
38 38
@@ -60,22 +60,25 @@ key_new(int type)
60 switch (k->type) { 60 switch (k->type) {
61 case KEY_RSA1: 61 case KEY_RSA1:
62 case KEY_RSA: 62 case KEY_RSA:
63 rsa = RSA_new(); 63 if ((rsa = RSA_new()) == NULL)
64 rsa->n = BN_new(); 64 fatal("key_new: RSA_new failed");
65 rsa->e = BN_new(); 65 if ((rsa->n = BN_new()) == NULL)
66 if (rsa == NULL || rsa->n == NULL || rsa->e == NULL) 66 fatal("key_new: BN_new failed");
67 fatal("key_new: malloc failure"); 67 if ((rsa->e = BN_new()) == NULL)
68 fatal("key_new: BN_new failed");
68 k->rsa = rsa; 69 k->rsa = rsa;
69 break; 70 break;
70 case KEY_DSA: 71 case KEY_DSA:
71 dsa = DSA_new(); 72 if ((dsa = DSA_new()) == NULL)
72 dsa->p = BN_new(); 73 fatal("key_new: DSA_new failed");
73 dsa->q = BN_new(); 74 if ((dsa->p = BN_new()) == NULL)
74 dsa->g = BN_new(); 75 fatal("key_new: BN_new failed");
75 dsa->pub_key = BN_new(); 76 if ((dsa->q = BN_new()) == NULL)
76 if (dsa == NULL || dsa->p == NULL || dsa->q == NULL || 77 fatal("key_new: BN_new failed");
77 dsa->g == NULL || dsa->pub_key == NULL) 78 if ((dsa->g = BN_new()) == NULL)
78 fatal("key_new: malloc failure"); 79 fatal("key_new: BN_new failed");
80 if ((dsa->pub_key = BN_new()) == NULL)
81 fatal("key_new: BN_new failed");
79 k->dsa = dsa; 82 k->dsa = dsa;
80 break; 83 break;
81 case KEY_UNSPEC: 84 case KEY_UNSPEC:
@@ -93,15 +96,22 @@ key_new_private(int type)
93 switch (k->type) { 96 switch (k->type) {
94 case KEY_RSA1: 97 case KEY_RSA1:
95 case KEY_RSA: 98 case KEY_RSA:
96 k->rsa->d = BN_new(); 99 if ((k->rsa->d = BN_new()) == NULL)
97 k->rsa->iqmp = BN_new(); 100 fatal("key_new_private: BN_new failed");
98 k->rsa->q = BN_new(); 101 if ((k->rsa->iqmp = BN_new()) == NULL)
99 k->rsa->p = BN_new(); 102 fatal("key_new_private: BN_new failed");
100 k->rsa->dmq1 = BN_new(); 103 if ((k->rsa->q = BN_new()) == NULL)
101 k->rsa->dmp1 = BN_new(); 104 fatal("key_new_private: BN_new failed");
105 if ((k->rsa->p = BN_new()) == NULL)
106 fatal("key_new_private: BN_new failed");
107 if ((k->rsa->dmq1 = BN_new()) == NULL)
108 fatal("key_new_private: BN_new failed");
109 if ((k->rsa->dmp1 = BN_new()) == NULL)
110 fatal("key_new_private: BN_new failed");
102 break; 111 break;
103 case KEY_DSA: 112 case KEY_DSA:
104 k->dsa->priv_key = BN_new(); 113 if ((k->dsa->priv_key = BN_new()) == NULL)
114 fatal("key_new_private: BN_new failed");
105 break; 115 break;
106 case KEY_UNSPEC: 116 case KEY_UNSPEC:
107 break; 117 break;
diff --git a/rsa.c b/rsa.c
index 113ee7fc4..66561a421 100644
--- a/rsa.c
+++ b/rsa.c
@@ -60,7 +60,7 @@
60 */ 60 */
61 61
62#include "includes.h" 62#include "includes.h"
63RCSID("$OpenBSD: rsa.c,v 1.23 2001/06/27 05:42:24 markus Exp $"); 63RCSID("$OpenBSD: rsa.c,v 1.24 2001/12/27 18:22:16 markus Exp $");
64 64
65#include "rsa.h" 65#include "rsa.h"
66#include "log.h" 66#include "log.h"
@@ -120,14 +120,17 @@ rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key)
120 return len; 120 return len;
121} 121}
122 122
123/* calculate p-1 and q-1 */
123void 124void
124rsa_generate_additional_parameters(RSA *rsa) 125rsa_generate_additional_parameters(RSA *rsa)
125{ 126{
126 BIGNUM *aux; 127 BIGNUM *aux;
127 BN_CTX *ctx; 128 BN_CTX *ctx;
128 /* Generate additional parameters */ 129
129 aux = BN_new(); 130 if ((aux = BN_new()) == NULL)
130 ctx = BN_CTX_new(); 131 fatal("rsa_generate_additional_parameters: BN_new failed");
132 if ((ctx = BN_CTX_new()) == NULL)
133 fatal("rsa_generate_additional_parameters: BN_CTX_new failed");
131 134
132 BN_sub(aux, rsa->q, BN_value_one()); 135 BN_sub(aux, rsa->q, BN_value_one());
133 BN_mod(rsa->dmq1, rsa->d, aux, ctx); 136 BN_mod(rsa->dmq1, rsa->d, aux, ctx);
diff --git a/scard.c b/scard.c
index 19d0e2a4c..e8319314c 100644
--- a/scard.c
+++ b/scard.c
@@ -24,7 +24,7 @@
24 24
25#include "includes.h" 25#include "includes.h"
26#ifdef SMARTCARD 26#ifdef SMARTCARD
27RCSID("$OpenBSD: scard.c,v 1.16 2001/12/19 07:18:56 deraadt Exp $"); 27RCSID("$OpenBSD: scard.c,v 1.17 2001/12/27 18:22:16 markus Exp $");
28 28
29#include <openssl/engine.h> 29#include <openssl/engine.h>
30#include <sectok.h> 30#include <sectok.h>
@@ -320,7 +320,8 @@ sc_get_engine(void)
320 smart_rsa.rsa_sign = def->rsa_sign; 320 smart_rsa.rsa_sign = def->rsa_sign;
321 smart_rsa.rsa_verify = def->rsa_verify; 321 smart_rsa.rsa_verify = def->rsa_verify;
322 322
323 smart_engine = ENGINE_new(); 323 if ((smart_engine = ENGINE_new()) == NULL)
324 fatal("ENGINE_new failed");
324 325
325 ENGINE_set_id(smart_engine, "sectok"); 326 ENGINE_set_id(smart_engine, "sectok");
326 ENGINE_set_name(smart_engine, "libsectok"); 327 ENGINE_set_name(smart_engine, "libsectok");
diff --git a/ssh-agent.c b/ssh-agent.c
index e8018bf3a..5620b6b90 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-agent.c,v 1.75 2001/12/19 07:18:56 deraadt Exp $ */ 1/* $OpenBSD: ssh-agent.c,v 1.76 2001/12/27 18:22:16 markus Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -36,7 +36,7 @@
36 */ 36 */
37 37
38#include "includes.h" 38#include "includes.h"
39RCSID("$OpenBSD: ssh-agent.c,v 1.75 2001/12/19 07:18:56 deraadt Exp $"); 39RCSID("$OpenBSD: ssh-agent.c,v 1.76 2001/12/27 18:22:16 markus Exp $");
40 40
41#include <openssl/evp.h> 41#include <openssl/evp.h>
42#include <openssl/md5.h> 42#include <openssl/md5.h>
@@ -186,7 +186,8 @@ process_authentication_challenge1(SocketEntry *e)
186 186
187 buffer_init(&msg); 187 buffer_init(&msg);
188 key = key_new(KEY_RSA1); 188 key = key_new(KEY_RSA1);
189 challenge = BN_new(); 189 if ((challenge = BN_new()) == NULL)
190 fatal("process_authentication_challenge1: BN_new failed");
190 191
191 buffer_get_int(&e->input); /* ignored */ 192 buffer_get_int(&e->input); /* ignored */
192 buffer_get_bignum(&e->input, key->rsa->e); 193 buffer_get_bignum(&e->input, key->rsa->e);
diff --git a/ssh-dss.c b/ssh-dss.c
index 30bd1f8cb..bd709a226 100644
--- a/ssh-dss.c
+++ b/ssh-dss.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: ssh-dss.c,v 1.10 2001/12/05 10:06:12 deraadt Exp $"); 26RCSID("$OpenBSD: ssh-dss.c,v 1.11 2001/12/27 18:22:16 markus Exp $");
27 27
28#include <openssl/bn.h> 28#include <openssl/bn.h>
29#include <openssl/evp.h> 29#include <openssl/evp.h>
@@ -158,9 +158,12 @@ ssh_dss_verify(
158 } 158 }
159 159
160 /* parse signature */ 160 /* parse signature */
161 sig = DSA_SIG_new(); 161 if ((sig = DSA_SIG_new()) == NULL)
162 sig->r = BN_new(); 162 fatal("ssh_dss_verify: DSA_SIG_new failed");
163 sig->s = BN_new(); 163 if ((sig->r = BN_new()) == NULL)
164 fatal("ssh_dss_verify: BN_new failed");
165 if ((sig->s = BN_new()) == NULL)
166 fatal("ssh_dss_verify: BN_new failed");
164 BN_bin2bn(sigblob, INTBLOB_LEN, sig->r); 167 BN_bin2bn(sigblob, INTBLOB_LEN, sig->r);
165 BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, sig->s); 168 BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, sig->s);
166 169
diff --git a/sshconnect1.c b/sshconnect1.c
index 2829ca5a7..166e392e7 100644
--- a/sshconnect1.c
+++ b/sshconnect1.c
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15#include "includes.h" 15#include "includes.h"
16RCSID("$OpenBSD: sshconnect1.c,v 1.42 2001/12/19 07:18:56 deraadt Exp $"); 16RCSID("$OpenBSD: sshconnect1.c,v 1.43 2001/12/27 18:22:16 markus Exp $");
17 17
18#include <openssl/bn.h> 18#include <openssl/bn.h>
19#include <openssl/evp.h> 19#include <openssl/evp.h>
@@ -76,8 +76,8 @@ try_agent_authentication(void)
76 if (!auth) 76 if (!auth)
77 return 0; 77 return 0;
78 78
79 challenge = BN_new(); 79 if ((challenge = BN_new()) == NULL)
80 80 fatal("try_agent_authentication: BN_new failed");
81 /* Loop through identities served by the agent. */ 81 /* Loop through identities served by the agent. */
82 for (key = ssh_get_first_identity(auth, &comment, 1); 82 for (key = ssh_get_first_identity(auth, &comment, 1);
83 key != NULL; 83 key != NULL;
@@ -241,7 +241,8 @@ try_rsa_authentication(int idx)
241 packet_disconnect("Protocol error during RSA authentication: %d", type); 241 packet_disconnect("Protocol error during RSA authentication: %d", type);
242 242
243 /* Get the challenge from the packet. */ 243 /* Get the challenge from the packet. */
244 challenge = BN_new(); 244 if ((challenge = BN_new()) == NULL)
245 fatal("try_rsa_authentication: BN_new failed");
245 packet_get_bignum(challenge, &clen); 246 packet_get_bignum(challenge, &clen);
246 247
247 packet_integrity_check(plen, clen, type); 248 packet_integrity_check(plen, clen, type);
@@ -355,7 +356,8 @@ try_rhosts_rsa_authentication(const char *local_user, Key * host_key)
355 packet_disconnect("Protocol error during RSA authentication: %d", type); 356 packet_disconnect("Protocol error during RSA authentication: %d", type);
356 357
357 /* Get the challenge from the packet. */ 358 /* Get the challenge from the packet. */
358 challenge = BN_new(); 359 if ((challenge = BN_new()) == NULL)
360 fatal("try_rhosts_rsa_authentication: BN_new failed");
359 packet_get_bignum(challenge, &clen); 361 packet_get_bignum(challenge, &clen);
360 362
361 packet_integrity_check(plen, clen, type); 363 packet_integrity_check(plen, clen, type);
@@ -912,9 +914,7 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
912{ 914{
913 int i; 915 int i;
914 BIGNUM *key; 916 BIGNUM *key;
915 RSA *host_key; 917 Key *host_key, *server_key;
916 RSA *public_key;
917 Key k;
918 int bits, rbits; 918 int bits, rbits;
919 int ssh_cipher_default = SSH_CIPHER_3DES; 919 int ssh_cipher_default = SSH_CIPHER_3DES;
920 u_char session_key[SSH_SESSION_KEY_LENGTH]; 920 u_char session_key[SSH_SESSION_KEY_LENGTH];
@@ -934,32 +934,28 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
934 cookie[i] = packet_get_char(); 934 cookie[i] = packet_get_char();
935 935
936 /* Get the public key. */ 936 /* Get the public key. */
937 public_key = RSA_new(); 937 server_key = key_new(KEY_RSA1);
938 bits = packet_get_int();/* bits */ 938 bits = packet_get_int();
939 public_key->e = BN_new(); 939 packet_get_bignum(server_key->rsa->e, &clen);
940 packet_get_bignum(public_key->e, &clen);
941 sum_len += clen; 940 sum_len += clen;
942 public_key->n = BN_new(); 941 packet_get_bignum(server_key->rsa->n, &clen);
943 packet_get_bignum(public_key->n, &clen);
944 sum_len += clen; 942 sum_len += clen;
945 943
946 rbits = BN_num_bits(public_key->n); 944 rbits = BN_num_bits(server_key->rsa->n);
947 if (bits != rbits) { 945 if (bits != rbits) {
948 log("Warning: Server lies about size of server public key: " 946 log("Warning: Server lies about size of server public key: "
949 "actual size is %d bits vs. announced %d.", rbits, bits); 947 "actual size is %d bits vs. announced %d.", rbits, bits);
950 log("Warning: This may be due to an old implementation of ssh."); 948 log("Warning: This may be due to an old implementation of ssh.");
951 } 949 }
952 /* Get the host key. */ 950 /* Get the host key. */
953 host_key = RSA_new(); 951 host_key = key_new(KEY_RSA1);
954 bits = packet_get_int();/* bits */ 952 bits = packet_get_int();
955 host_key->e = BN_new(); 953 packet_get_bignum(host_key->rsa->e, &clen);
956 packet_get_bignum(host_key->e, &clen);
957 sum_len += clen; 954 sum_len += clen;
958 host_key->n = BN_new(); 955 packet_get_bignum(host_key->rsa->n, &clen);
959 packet_get_bignum(host_key->n, &clen);
960 sum_len += clen; 956 sum_len += clen;
961 957
962 rbits = BN_num_bits(host_key->n); 958 rbits = BN_num_bits(host_key->rsa->n);
963 if (bits != rbits) { 959 if (bits != rbits) {
964 log("Warning: Server lies about size of server host key: " 960 log("Warning: Server lies about size of server host key: "
965 "actual size is %d bits vs. announced %d.", rbits, bits); 961 "actual size is %d bits vs. announced %d.", rbits, bits);
@@ -974,19 +970,17 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
974 supported_authentications = packet_get_int(); 970 supported_authentications = packet_get_int();
975 971
976 debug("Received server public key (%d bits) and host key (%d bits).", 972 debug("Received server public key (%d bits) and host key (%d bits).",
977 BN_num_bits(public_key->n), BN_num_bits(host_key->n)); 973 BN_num_bits(server_key->rsa->n), BN_num_bits(host_key->rsa->n));
978 974
979 packet_integrity_check(payload_len, 975 packet_integrity_check(payload_len,
980 8 + 4 + sum_len + 0 + 4 + 0 + 0 + 4 + 4 + 4, 976 8 + 4 + sum_len + 0 + 4 + 0 + 0 + 4 + 4 + 4,
981 SSH_SMSG_PUBLIC_KEY); 977 SSH_SMSG_PUBLIC_KEY);
982 k.type = KEY_RSA1; 978 if (verify_host_key(host, hostaddr, host_key) == -1)
983 k.rsa = host_key;
984 if (verify_host_key(host, hostaddr, &k) == -1)
985 fatal("Host key verification failed."); 979 fatal("Host key verification failed.");
986 980
987 client_flags = SSH_PROTOFLAG_SCREEN_NUMBER | SSH_PROTOFLAG_HOST_IN_FWD_OPEN; 981 client_flags = SSH_PROTOFLAG_SCREEN_NUMBER | SSH_PROTOFLAG_HOST_IN_FWD_OPEN;
988 982
989 compute_session_id(session_id, cookie, host_key->n, public_key->n); 983 compute_session_id(session_id, cookie, host_key->rsa->n, server_key->rsa->n);
990 984
991 /* Generate a session key. */ 985 /* Generate a session key. */
992 arc4random_stir(); 986 arc4random_stir();
@@ -1008,7 +1002,8 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
1008 * is the highest byte of the integer. The session key is xored with 1002 * is the highest byte of the integer. The session key is xored with
1009 * the first 16 bytes of the session id. 1003 * the first 16 bytes of the session id.
1010 */ 1004 */
1011 key = BN_new(); 1005 if ((key = BN_new()) == NULL)
1006 fatal("respond_to_rsa_challenge: BN_new failed");
1012 BN_set_word(key, 0); 1007 BN_set_word(key, 0);
1013 for (i = 0; i < SSH_SESSION_KEY_LENGTH; i++) { 1008 for (i = 0; i < SSH_SESSION_KEY_LENGTH; i++) {
1014 BN_lshift(key, key, 8); 1009 BN_lshift(key, key, 8);
@@ -1022,35 +1017,35 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
1022 * Encrypt the integer using the public key and host key of the 1017 * Encrypt the integer using the public key and host key of the
1023 * server (key with smaller modulus first). 1018 * server (key with smaller modulus first).
1024 */ 1019 */
1025 if (BN_cmp(public_key->n, host_key->n) < 0) { 1020 if (BN_cmp(server_key->rsa->n, host_key->rsa->n) < 0) {
1026 /* Public key has smaller modulus. */ 1021 /* Public key has smaller modulus. */
1027 if (BN_num_bits(host_key->n) < 1022 if (BN_num_bits(host_key->rsa->n) <
1028 BN_num_bits(public_key->n) + SSH_KEY_BITS_RESERVED) { 1023 BN_num_bits(server_key->rsa->n) + SSH_KEY_BITS_RESERVED) {
1029 fatal("respond_to_rsa_challenge: host_key %d < public_key %d + " 1024 fatal("respond_to_rsa_challenge: host_key %d < server_key %d + "
1030 "SSH_KEY_BITS_RESERVED %d", 1025 "SSH_KEY_BITS_RESERVED %d",
1031 BN_num_bits(host_key->n), 1026 BN_num_bits(host_key->rsa->n),
1032 BN_num_bits(public_key->n), 1027 BN_num_bits(server_key->rsa->n),
1033 SSH_KEY_BITS_RESERVED); 1028 SSH_KEY_BITS_RESERVED);
1034 } 1029 }
1035 rsa_public_encrypt(key, key, public_key); 1030 rsa_public_encrypt(key, key, server_key->rsa);
1036 rsa_public_encrypt(key, key, host_key); 1031 rsa_public_encrypt(key, key, host_key->rsa);
1037 } else { 1032 } else {
1038 /* Host key has smaller modulus (or they are equal). */ 1033 /* Host key has smaller modulus (or they are equal). */
1039 if (BN_num_bits(public_key->n) < 1034 if (BN_num_bits(server_key->rsa->n) <
1040 BN_num_bits(host_key->n) + SSH_KEY_BITS_RESERVED) { 1035 BN_num_bits(host_key->rsa->n) + SSH_KEY_BITS_RESERVED) {
1041 fatal("respond_to_rsa_challenge: public_key %d < host_key %d + " 1036 fatal("respond_to_rsa_challenge: server_key %d < host_key %d + "
1042 "SSH_KEY_BITS_RESERVED %d", 1037 "SSH_KEY_BITS_RESERVED %d",
1043 BN_num_bits(public_key->n), 1038 BN_num_bits(server_key->rsa->n),
1044 BN_num_bits(host_key->n), 1039 BN_num_bits(host_key->rsa->n),
1045 SSH_KEY_BITS_RESERVED); 1040 SSH_KEY_BITS_RESERVED);
1046 } 1041 }
1047 rsa_public_encrypt(key, key, host_key); 1042 rsa_public_encrypt(key, key, host_key->rsa);
1048 rsa_public_encrypt(key, key, public_key); 1043 rsa_public_encrypt(key, key, server_key->rsa);
1049 } 1044 }
1050 1045
1051 /* Destroy the public keys since we no longer need them. */ 1046 /* Destroy the public keys since we no longer need them. */
1052 RSA_free(public_key); 1047 key_free(server_key);
1053 RSA_free(host_key); 1048 key_free(host_key);
1054 1049
1055 if (options.cipher == SSH_CIPHER_NOT_SET) { 1050 if (options.cipher == SSH_CIPHER_NOT_SET) {
1056 if (cipher_mask_ssh1(1) & supported_ciphers & (1 << ssh_cipher_default)) 1051 if (cipher_mask_ssh1(1) & supported_ciphers & (1 << ssh_cipher_default))
diff --git a/sshd.c b/sshd.c
index c166a84ea..69372765a 100644
--- a/sshd.c
+++ b/sshd.c
@@ -40,7 +40,7 @@
40 */ 40 */
41 41
42#include "includes.h" 42#include "includes.h"
43RCSID("$OpenBSD: sshd.c,v 1.217 2001/12/19 07:18:56 deraadt Exp $"); 43RCSID("$OpenBSD: sshd.c,v 1.218 2001/12/27 18:22:16 markus Exp $");
44 44
45#include <openssl/dh.h> 45#include <openssl/dh.h>
46#include <openssl/bn.h> 46#include <openssl/bn.h>
@@ -1352,7 +1352,8 @@ do_ssh1_kex(void)
1352 debug("Encryption type: %.200s", cipher_name(cipher_type)); 1352 debug("Encryption type: %.200s", cipher_name(cipher_type));
1353 1353
1354 /* Get the encrypted integer. */ 1354 /* Get the encrypted integer. */
1355 session_key_int = BN_new(); 1355 if ((session_key_int = BN_new()) == NULL)
1356 fatal("do_ssh1_kex: BN_new failed");
1356 packet_get_bignum(session_key_int, &slen); 1357 packet_get_bignum(session_key_int, &slen);
1357 1358
1358 protocol_flags = packet_get_int(); 1359 protocol_flags = packet_get_int();