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