diff options
Diffstat (limited to 'kexdhs.c')
-rw-r--r-- | kexdhs.c | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/kexdhs.c b/kexdhs.c deleted file mode 100644 index e33901bbf..000000000 --- a/kexdhs.c +++ /dev/null | |||
@@ -1,142 +0,0 @@ | |||
1 | /* $OpenBSD: kexdhs.c,v 1.35 2019/01/21 10:05:09 djm Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2001 Markus Friedl. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * | ||
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
24 | */ | ||
25 | |||
26 | #include "includes.h" | ||
27 | |||
28 | #ifdef WITH_OPENSSL | ||
29 | |||
30 | #include <sys/types.h> | ||
31 | |||
32 | #include <stdarg.h> | ||
33 | #include <string.h> | ||
34 | #include <signal.h> | ||
35 | |||
36 | #include <openssl/dh.h> | ||
37 | |||
38 | #include "openbsd-compat/openssl-compat.h" | ||
39 | |||
40 | #include "sshkey.h" | ||
41 | #include "cipher.h" | ||
42 | #include "digest.h" | ||
43 | #include "dh.h" | ||
44 | #include "kex.h" | ||
45 | #include "log.h" | ||
46 | #include "packet.h" | ||
47 | #include "ssh2.h" | ||
48 | |||
49 | #include "dispatch.h" | ||
50 | #include "compat.h" | ||
51 | #include "ssherr.h" | ||
52 | #include "sshbuf.h" | ||
53 | |||
54 | static int input_kex_dh_init(int, u_int32_t, struct ssh *); | ||
55 | |||
56 | int | ||
57 | kexdh_server(struct ssh *ssh) | ||
58 | { | ||
59 | struct kex *kex = ssh->kex; | ||
60 | int r; | ||
61 | |||
62 | /* generate server DH public key */ | ||
63 | if ((r = kex_dh_keygen(kex)) != 0) | ||
64 | return r; | ||
65 | debug("expecting SSH2_MSG_KEXDH_INIT"); | ||
66 | ssh_dispatch_set(ssh, SSH2_MSG_KEXDH_INIT, &input_kex_dh_init); | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | int | ||
71 | input_kex_dh_init(int type, u_int32_t seq, struct ssh *ssh) | ||
72 | { | ||
73 | struct kex *kex = ssh->kex; | ||
74 | BIGNUM *dh_client_pub = NULL; | ||
75 | const BIGNUM *pub_key; | ||
76 | struct sshkey *server_host_public, *server_host_private; | ||
77 | struct sshbuf *shared_secret = NULL; | ||
78 | u_char *signature = NULL, *server_host_key_blob = NULL; | ||
79 | u_char hash[SSH_DIGEST_MAX_LENGTH]; | ||
80 | size_t sbloblen, slen; | ||
81 | size_t hashlen; | ||
82 | int r; | ||
83 | |||
84 | if ((r = kex_load_hostkey(ssh, &server_host_private, | ||
85 | &server_host_public)) != 0) | ||
86 | goto out; | ||
87 | |||
88 | /* key, cert */ | ||
89 | if ((r = sshpkt_get_bignum2(ssh, &dh_client_pub)) != 0 || | ||
90 | (r = sshpkt_get_end(ssh)) != 0) | ||
91 | goto out; | ||
92 | if ((shared_secret = sshbuf_new()) == NULL) { | ||
93 | r = SSH_ERR_ALLOC_FAIL; | ||
94 | goto out; | ||
95 | } | ||
96 | if ((r = kex_dh_compute_key(kex, dh_client_pub, shared_secret)) != 0) | ||
97 | goto out; | ||
98 | if ((r = sshkey_to_blob(server_host_public, &server_host_key_blob, | ||
99 | &sbloblen)) != 0) | ||
100 | goto out; | ||
101 | /* calc H */ | ||
102 | DH_get0_key(kex->dh, &pub_key, NULL); | ||
103 | hashlen = sizeof(hash); | ||
104 | if ((r = kex_dh_hash( | ||
105 | kex->hash_alg, | ||
106 | kex->client_version, | ||
107 | kex->server_version, | ||
108 | sshbuf_ptr(kex->peer), sshbuf_len(kex->peer), | ||
109 | sshbuf_ptr(kex->my), sshbuf_len(kex->my), | ||
110 | server_host_key_blob, sbloblen, | ||
111 | dh_client_pub, | ||
112 | pub_key, | ||
113 | sshbuf_ptr(shared_secret), sshbuf_len(shared_secret), | ||
114 | hash, &hashlen)) != 0) | ||
115 | goto out; | ||
116 | |||
117 | /* sign H */ | ||
118 | if ((r = kex->sign(ssh, server_host_private, server_host_public, | ||
119 | &signature, &slen, hash, hashlen, kex->hostkey_alg)) < 0) | ||
120 | goto out; | ||
121 | |||
122 | /* send server hostkey, DH pubkey 'f' and signed H */ | ||
123 | if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_REPLY)) != 0 || | ||
124 | (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 || | ||
125 | (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 || /* f */ | ||
126 | (r = sshpkt_put_string(ssh, signature, slen)) != 0 || | ||
127 | (r = sshpkt_send(ssh)) != 0) | ||
128 | goto out; | ||
129 | |||
130 | if ((r = kex_derive_keys(ssh, hash, hashlen, shared_secret)) == 0) | ||
131 | r = kex_send_newkeys(ssh); | ||
132 | out: | ||
133 | explicit_bzero(hash, sizeof(hash)); | ||
134 | DH_free(kex->dh); | ||
135 | kex->dh = NULL; | ||
136 | BN_clear_free(dh_client_pub); | ||
137 | sshbuf_free(shared_secret); | ||
138 | free(server_host_key_blob); | ||
139 | free(signature); | ||
140 | return r; | ||
141 | } | ||
142 | #endif /* WITH_OPENSSL */ | ||