diff options
author | Damien Miller <djm@mindrot.org> | 2014-02-04 11:03:36 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2014-02-04 11:03:36 +1100 |
commit | 4a1c7aa640fb97d3472d51b215b6a0ec0fd025c7 (patch) | |
tree | 6fb1bfba860987b5d9042c478ae218d848850b64 | |
parent | 4e8d937af79ce4e253f77ec93489d098b25becc3 (diff) |
- markus@cvs.openbsd.org 2014/01/27 19:18:54
[auth-rsa.c cipher.c ssh-agent.c sshconnect1.c sshd.c]
replace openssl MD5 with our ssh_digest_*; ok djm@
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | auth-rsa.c | 22 | ||||
-rw-r--r-- | cipher.c | 14 | ||||
-rw-r--r-- | ssh-agent.c | 16 | ||||
-rw-r--r-- | sshconnect1.c | 16 | ||||
-rw-r--r-- | sshd.c | 30 |
6 files changed, 58 insertions, 43 deletions
@@ -4,6 +4,9 @@ | |||
4 | [Makefile.in digest.c digest.h hostfile.c kex.h mac.c hmac.c hmac.h] | 4 | [Makefile.in digest.c digest.h hostfile.c kex.h mac.c hmac.c hmac.h] |
5 | replace openssl HMAC with an implementation based on our ssh_digest_* | 5 | replace openssl HMAC with an implementation based on our ssh_digest_* |
6 | ok and feedback djm@ | 6 | ok and feedback djm@ |
7 | - markus@cvs.openbsd.org 2014/01/27 19:18:54 | ||
8 | [auth-rsa.c cipher.c ssh-agent.c sshconnect1.c sshd.c] | ||
9 | replace openssl MD5 with our ssh_digest_*; ok djm@ | ||
7 | 10 | ||
8 | 20140131 | 11 | 20140131 |
9 | - (djm) [sandbox-seccomp-filter.c sandbox-systrace.c] Allow shutdown(2) | 12 | - (djm) [sandbox-seccomp-filter.c sandbox-systrace.c] Allow shutdown(2) |
diff --git a/auth-rsa.c b/auth-rsa.c index 545aa496a..5dad6c3dc 100644 --- a/auth-rsa.c +++ b/auth-rsa.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: auth-rsa.c,v 1.85 2013/07/12 00:19:58 djm Exp $ */ | 1 | /* $OpenBSD: auth-rsa.c,v 1.86 2014/01/27 19:18:54 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -20,7 +20,6 @@ | |||
20 | #include <sys/stat.h> | 20 | #include <sys/stat.h> |
21 | 21 | ||
22 | #include <openssl/rsa.h> | 22 | #include <openssl/rsa.h> |
23 | #include <openssl/md5.h> | ||
24 | 23 | ||
25 | #include <pwd.h> | 24 | #include <pwd.h> |
26 | #include <stdio.h> | 25 | #include <stdio.h> |
@@ -48,6 +47,8 @@ | |||
48 | #include "ssh.h" | 47 | #include "ssh.h" |
49 | #include "misc.h" | 48 | #include "misc.h" |
50 | 49 | ||
50 | #include "digest.h" | ||
51 | |||
51 | /* import */ | 52 | /* import */ |
52 | extern ServerOptions options; | 53 | extern ServerOptions options; |
53 | 54 | ||
@@ -91,12 +92,13 @@ int | |||
91 | auth_rsa_verify_response(Key *key, BIGNUM *challenge, u_char response[16]) | 92 | auth_rsa_verify_response(Key *key, BIGNUM *challenge, u_char response[16]) |
92 | { | 93 | { |
93 | u_char buf[32], mdbuf[16]; | 94 | u_char buf[32], mdbuf[16]; |
94 | MD5_CTX md; | 95 | struct ssh_digest_ctx *md; |
95 | int len; | 96 | int len; |
96 | 97 | ||
97 | /* don't allow short keys */ | 98 | /* don't allow short keys */ |
98 | if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) { | 99 | if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) { |
99 | error("auth_rsa_verify_response: RSA modulus too small: %d < minimum %d bits", | 100 | error("%s: RSA modulus too small: %d < minimum %d bits", |
101 | __func__, | ||
100 | BN_num_bits(key->rsa->n), SSH_RSA_MINIMUM_MODULUS_SIZE); | 102 | BN_num_bits(key->rsa->n), SSH_RSA_MINIMUM_MODULUS_SIZE); |
101 | return (0); | 103 | return (0); |
102 | } | 104 | } |
@@ -104,13 +106,15 @@ auth_rsa_verify_response(Key *key, BIGNUM *challenge, u_char response[16]) | |||
104 | /* The response is MD5 of decrypted challenge plus session id. */ | 106 | /* The response is MD5 of decrypted challenge plus session id. */ |
105 | len = BN_num_bytes(challenge); | 107 | len = BN_num_bytes(challenge); |
106 | if (len <= 0 || len > 32) | 108 | if (len <= 0 || len > 32) |
107 | fatal("auth_rsa_verify_response: bad challenge length %d", len); | 109 | fatal("%s: bad challenge length %d", __func__, len); |
108 | memset(buf, 0, 32); | 110 | memset(buf, 0, 32); |
109 | BN_bn2bin(challenge, buf + 32 - len); | 111 | BN_bn2bin(challenge, buf + 32 - len); |
110 | MD5_Init(&md); | 112 | if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL || |
111 | MD5_Update(&md, buf, 32); | 113 | ssh_digest_update(md, buf, 32) < 0 || |
112 | MD5_Update(&md, session_id, 16); | 114 | ssh_digest_update(md, session_id, 16) < 0 || |
113 | MD5_Final(mdbuf, &md); | 115 | ssh_digest_final(md, mdbuf, sizeof(mdbuf)) < 0) |
116 | fatal("%s: md5 failed", __func__); | ||
117 | ssh_digest_free(md); | ||
114 | 118 | ||
115 | /* Verify that the response is the original challenge. */ | 119 | /* Verify that the response is the original challenge. */ |
116 | if (timingsafe_bcmp(response, mdbuf, 16) != 0) { | 120 | if (timingsafe_bcmp(response, mdbuf, 16) != 0) { |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: cipher.c,v 1.94 2014/01/25 10:12:50 dtucker Exp $ */ | 1 | /* $OpenBSD: cipher.c,v 1.95 2014/01/27 19:18:54 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -39,8 +39,6 @@ | |||
39 | 39 | ||
40 | #include <sys/types.h> | 40 | #include <sys/types.h> |
41 | 41 | ||
42 | #include <openssl/md5.h> | ||
43 | |||
44 | #include <string.h> | 42 | #include <string.h> |
45 | #include <stdarg.h> | 43 | #include <stdarg.h> |
46 | #include <stdio.h> | 44 | #include <stdio.h> |
@@ -49,6 +47,8 @@ | |||
49 | #include "log.h" | 47 | #include "log.h" |
50 | #include "misc.h" | 48 | #include "misc.h" |
51 | #include "cipher.h" | 49 | #include "cipher.h" |
50 | #include "buffer.h" | ||
51 | #include "digest.h" | ||
52 | 52 | ||
53 | /* compatibility with old or broken OpenSSL versions */ | 53 | /* compatibility with old or broken OpenSSL versions */ |
54 | #include "openbsd-compat/openssl-compat.h" | 54 | #include "openbsd-compat/openssl-compat.h" |
@@ -436,17 +436,15 @@ void | |||
436 | cipher_set_key_string(CipherContext *cc, const Cipher *cipher, | 436 | cipher_set_key_string(CipherContext *cc, const Cipher *cipher, |
437 | const char *passphrase, int do_encrypt) | 437 | const char *passphrase, int do_encrypt) |
438 | { | 438 | { |
439 | MD5_CTX md; | ||
440 | u_char digest[16]; | 439 | u_char digest[16]; |
441 | 440 | ||
442 | MD5_Init(&md); | 441 | if (ssh_digest_memory(SSH_DIGEST_MD5, passphrase, strlen(passphrase), |
443 | MD5_Update(&md, (const u_char *)passphrase, strlen(passphrase)); | 442 | digest, sizeof(digest)) < 0) |
444 | MD5_Final(digest, &md); | 443 | fatal("%s: md5 failed", __func__); |
445 | 444 | ||
446 | cipher_init(cc, cipher, digest, 16, NULL, 0, do_encrypt); | 445 | cipher_init(cc, cipher, digest, 16, NULL, 0, do_encrypt); |
447 | 446 | ||
448 | memset(digest, 0, sizeof(digest)); | 447 | memset(digest, 0, sizeof(digest)); |
449 | memset(&md, 0, sizeof(md)); | ||
450 | } | 448 | } |
451 | 449 | ||
452 | /* | 450 | /* |
diff --git a/ssh-agent.c b/ssh-agent.c index 95117e076..256dff50c 100644 --- a/ssh-agent.c +++ b/ssh-agent.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-agent.c,v 1.181 2013/12/19 01:19:41 djm Exp $ */ | 1 | /* $OpenBSD: ssh-agent.c,v 1.182 2014/01/27 19:18:54 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -50,7 +50,6 @@ | |||
50 | #include "openbsd-compat/sys-queue.h" | 50 | #include "openbsd-compat/sys-queue.h" |
51 | 51 | ||
52 | #include <openssl/evp.h> | 52 | #include <openssl/evp.h> |
53 | #include <openssl/md5.h> | ||
54 | #include "openbsd-compat/openssl-compat.h" | 53 | #include "openbsd-compat/openssl-compat.h" |
55 | 54 | ||
56 | #include <errno.h> | 55 | #include <errno.h> |
@@ -75,6 +74,7 @@ | |||
75 | #include "compat.h" | 74 | #include "compat.h" |
76 | #include "log.h" | 75 | #include "log.h" |
77 | #include "misc.h" | 76 | #include "misc.h" |
77 | #include "digest.h" | ||
78 | 78 | ||
79 | #ifdef ENABLE_PKCS11 | 79 | #ifdef ENABLE_PKCS11 |
80 | #include "ssh-pkcs11.h" | 80 | #include "ssh-pkcs11.h" |
@@ -248,7 +248,7 @@ process_authentication_challenge1(SocketEntry *e) | |||
248 | Identity *id; | 248 | Identity *id; |
249 | int i, len; | 249 | int i, len; |
250 | Buffer msg; | 250 | Buffer msg; |
251 | MD5_CTX md; | 251 | struct ssh_digest_ctx *md; |
252 | Key *key; | 252 | Key *key; |
253 | 253 | ||
254 | buffer_init(&msg); | 254 | buffer_init(&msg); |
@@ -284,10 +284,12 @@ process_authentication_challenge1(SocketEntry *e) | |||
284 | } | 284 | } |
285 | memset(buf, 0, 32); | 285 | memset(buf, 0, 32); |
286 | BN_bn2bin(challenge, buf + 32 - len); | 286 | BN_bn2bin(challenge, buf + 32 - len); |
287 | MD5_Init(&md); | 287 | if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL || |
288 | MD5_Update(&md, buf, 32); | 288 | ssh_digest_update(md, buf, 32) < 0 || |
289 | MD5_Update(&md, session_id, 16); | 289 | ssh_digest_update(md, session_id, 16) < 0 || |
290 | MD5_Final(mdbuf, &md); | 290 | ssh_digest_final(md, mdbuf, sizeof(mdbuf)) < 0) |
291 | fatal("%s: md5 failed", __func__); | ||
292 | ssh_digest_free(md); | ||
291 | 293 | ||
292 | /* Send the response. */ | 294 | /* Send the response. */ |
293 | buffer_put_char(&msg, SSH_AGENT_RSA_RESPONSE); | 295 | buffer_put_char(&msg, SSH_AGENT_RSA_RESPONSE); |
diff --git a/sshconnect1.c b/sshconnect1.c index 7bd6cb018..57713d24d 100644 --- a/sshconnect1.c +++ b/sshconnect1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshconnect1.c,v 1.72 2013/09/02 22:00:34 deraadt Exp $ */ | 1 | /* $OpenBSD: sshconnect1.c,v 1.73 2014/01/27 19:18:54 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -19,7 +19,6 @@ | |||
19 | #include <sys/socket.h> | 19 | #include <sys/socket.h> |
20 | 20 | ||
21 | #include <openssl/bn.h> | 21 | #include <openssl/bn.h> |
22 | #include <openssl/md5.h> | ||
23 | 22 | ||
24 | #include <stdarg.h> | 23 | #include <stdarg.h> |
25 | #include <stdio.h> | 24 | #include <stdio.h> |
@@ -47,6 +46,7 @@ | |||
47 | #include "canohost.h" | 46 | #include "canohost.h" |
48 | #include "hostfile.h" | 47 | #include "hostfile.h" |
49 | #include "auth.h" | 48 | #include "auth.h" |
49 | #include "digest.h" | ||
50 | 50 | ||
51 | /* Session id for the current session. */ | 51 | /* Session id for the current session. */ |
52 | u_char session_id[16]; | 52 | u_char session_id[16]; |
@@ -161,7 +161,7 @@ static void | |||
161 | respond_to_rsa_challenge(BIGNUM * challenge, RSA * prv) | 161 | respond_to_rsa_challenge(BIGNUM * challenge, RSA * prv) |
162 | { | 162 | { |
163 | u_char buf[32], response[16]; | 163 | u_char buf[32], response[16]; |
164 | MD5_CTX md; | 164 | struct ssh_digest_ctx *md; |
165 | int i, len; | 165 | int i, len; |
166 | 166 | ||
167 | /* Decrypt the challenge using the private key. */ | 167 | /* Decrypt the challenge using the private key. */ |
@@ -179,10 +179,12 @@ respond_to_rsa_challenge(BIGNUM * challenge, RSA * prv) | |||
179 | 179 | ||
180 | memset(buf, 0, sizeof(buf)); | 180 | memset(buf, 0, sizeof(buf)); |
181 | BN_bn2bin(challenge, buf + sizeof(buf) - len); | 181 | BN_bn2bin(challenge, buf + sizeof(buf) - len); |
182 | MD5_Init(&md); | 182 | if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL || |
183 | MD5_Update(&md, buf, 32); | 183 | ssh_digest_update(md, buf, 32) < 0 || |
184 | MD5_Update(&md, session_id, 16); | 184 | ssh_digest_update(md, session_id, 16) < 0 || |
185 | MD5_Final(response, &md); | 185 | ssh_digest_final(md, response, sizeof(response)) < 0) |
186 | fatal("%s: md5 failed", __func__); | ||
187 | ssh_digest_free(md); | ||
186 | 188 | ||
187 | debug("Sending response to host key RSA challenge."); | 189 | debug("Sending response to host key RSA challenge."); |
188 | 190 | ||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshd.c,v 1.414 2014/01/09 23:26:48 djm Exp $ */ | 1 | /* $OpenBSD: sshd.c,v 1.415 2014/01/27 19:18:54 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -74,7 +74,6 @@ | |||
74 | 74 | ||
75 | #include <openssl/dh.h> | 75 | #include <openssl/dh.h> |
76 | #include <openssl/bn.h> | 76 | #include <openssl/bn.h> |
77 | #include <openssl/md5.h> | ||
78 | #include <openssl/rand.h> | 77 | #include <openssl/rand.h> |
79 | #include "openbsd-compat/openssl-compat.h" | 78 | #include "openbsd-compat/openssl-compat.h" |
80 | 79 | ||
@@ -96,6 +95,7 @@ | |||
96 | #include "uidswap.h" | 95 | #include "uidswap.h" |
97 | #include "compat.h" | 96 | #include "compat.h" |
98 | #include "cipher.h" | 97 | #include "cipher.h" |
98 | #include "digest.h" | ||
99 | #include "key.h" | 99 | #include "key.h" |
100 | #include "kex.h" | 100 | #include "kex.h" |
101 | #include "dh.h" | 101 | #include "dh.h" |
@@ -2360,19 +2360,25 @@ do_ssh1_kex(void) | |||
2360 | if (rsafail) { | 2360 | if (rsafail) { |
2361 | int bytes = BN_num_bytes(session_key_int); | 2361 | int bytes = BN_num_bytes(session_key_int); |
2362 | u_char *buf = xmalloc(bytes); | 2362 | u_char *buf = xmalloc(bytes); |
2363 | MD5_CTX md; | 2363 | struct ssh_digest_ctx *md; |
2364 | 2364 | ||
2365 | logit("do_connection: generating a fake encryption key"); | 2365 | logit("do_connection: generating a fake encryption key"); |
2366 | BN_bn2bin(session_key_int, buf); | 2366 | BN_bn2bin(session_key_int, buf); |
2367 | MD5_Init(&md); | 2367 | if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL || |
2368 | MD5_Update(&md, buf, bytes); | 2368 | ssh_digest_update(md, buf, bytes) < 0 || |
2369 | MD5_Update(&md, sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); | 2369 | ssh_digest_update(md, sensitive_data.ssh1_cookie, |
2370 | MD5_Final(session_key, &md); | 2370 | SSH_SESSION_KEY_LENGTH) < 0 || |
2371 | MD5_Init(&md); | 2371 | ssh_digest_final(md, session_key, sizeof(session_key)) < 0) |
2372 | MD5_Update(&md, session_key, 16); | 2372 | fatal("%s: md5 failed", __func__); |
2373 | MD5_Update(&md, buf, bytes); | 2373 | ssh_digest_free(md); |
2374 | MD5_Update(&md, sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); | 2374 | if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL || |
2375 | MD5_Final(session_key + 16, &md); | 2375 | ssh_digest_update(md, session_key, 16) < 0 || |
2376 | ssh_digest_update(md, sensitive_data.ssh1_cookie, | ||
2377 | SSH_SESSION_KEY_LENGTH) < 0 || | ||
2378 | ssh_digest_final(md, session_key + 16, | ||
2379 | sizeof(session_key) - 16) < 0) | ||
2380 | fatal("%s: md5 failed", __func__); | ||
2381 | ssh_digest_free(md); | ||
2376 | memset(buf, 0, bytes); | 2382 | memset(buf, 0, bytes); |
2377 | free(buf); | 2383 | free(buf); |
2378 | for (i = 0; i < 16; i++) | 2384 | for (i = 0; i < 16; i++) |