]>
Commit | Line | Data |
---|---|---|
2e437378 | 1 | /* $OpenBSD: kex.h,v 1.44 2006/08/03 03:34:42 deraadt Exp $ */ |
3c0ef626 | 2 | |
3 | /* | |
4 | * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 | */ | |
26 | #ifndef KEX_H | |
27 | #define KEX_H | |
28 | ||
2e437378 | 29 | #include <signal.h> |
3c0ef626 | 30 | #include <openssl/evp.h> |
3c0ef626 | 31 | |
e00da40d | 32 | #define KEX_DH1 "diffie-hellman-group1-sha1" |
33 | #define KEX_DH14 "diffie-hellman-group14-sha1" | |
34 | #define KEX_DHGEX_SHA1 "diffie-hellman-group-exchange-sha1" | |
2e437378 | 35 | #define KEX_DHGEX_SHA256 "diffie-hellman-group-exchange-sha256" |
3c0ef626 | 36 | |
34fee935 | 37 | #define COMP_NONE 0 |
38 | #define COMP_ZLIB 1 | |
39 | #define COMP_DELAYED 2 | |
40 | ||
3c0ef626 | 41 | enum kex_init_proposals { |
42 | PROPOSAL_KEX_ALGS, | |
43 | PROPOSAL_SERVER_HOST_KEY_ALGS, | |
44 | PROPOSAL_ENC_ALGS_CTOS, | |
45 | PROPOSAL_ENC_ALGS_STOC, | |
46 | PROPOSAL_MAC_ALGS_CTOS, | |
47 | PROPOSAL_MAC_ALGS_STOC, | |
48 | PROPOSAL_COMP_ALGS_CTOS, | |
49 | PROPOSAL_COMP_ALGS_STOC, | |
50 | PROPOSAL_LANG_CTOS, | |
51 | PROPOSAL_LANG_STOC, | |
52 | PROPOSAL_MAX | |
53 | }; | |
54 | ||
55 | enum kex_modes { | |
56 | MODE_IN, | |
57 | MODE_OUT, | |
58 | MODE_MAX | |
59 | }; | |
60 | ||
61 | enum kex_exchange { | |
1c14df9e | 62 | KEX_DH_GRP1_SHA1, |
1b56ff3d | 63 | KEX_DH_GRP14_SHA1, |
1c14df9e | 64 | KEX_DH_GEX_SHA1, |
2e437378 | 65 | KEX_DH_GEX_SHA256, |
1c14df9e | 66 | KEX_GSS_GRP1_SHA1, |
2e437378 | 67 | KEX_GSS_GRP14_SHA1, |
34fee935 | 68 | KEX_GSS_GEX_SHA1, |
1c14df9e | 69 | KEX_MAX |
3c0ef626 | 70 | }; |
71 | ||
72 | #define KEX_INIT_SENT 0x0001 | |
73 | ||
74 | typedef struct Kex Kex; | |
75 | typedef struct Mac Mac; | |
76 | typedef struct Comp Comp; | |
77 | typedef struct Enc Enc; | |
78 | typedef struct Newkeys Newkeys; | |
79 | ||
80 | struct Enc { | |
81 | char *name; | |
82 | Cipher *cipher; | |
83 | int enabled; | |
e9a17296 | 84 | u_int key_len; |
85 | u_int block_size; | |
3c0ef626 | 86 | u_char *key; |
87 | u_char *iv; | |
88 | }; | |
89 | struct Mac { | |
90 | char *name; | |
91 | int enabled; | |
ff2d7a98 | 92 | const EVP_MD *md; |
34fee935 | 93 | u_int mac_len; |
3c0ef626 | 94 | u_char *key; |
34fee935 | 95 | u_int key_len; |
3c0ef626 | 96 | }; |
97 | struct Comp { | |
98 | int type; | |
99 | int enabled; | |
100 | char *name; | |
101 | }; | |
102 | struct Newkeys { | |
103 | Enc enc; | |
104 | Mac mac; | |
105 | Comp comp; | |
106 | }; | |
b9a54c29 | 107 | |
3c0ef626 | 108 | struct Kex { |
109 | u_char *session_id; | |
e54b3d7c | 110 | u_int session_id_len; |
3c0ef626 | 111 | Newkeys *newkeys[MODE_MAX]; |
34fee935 | 112 | u_int we_need; |
3c0ef626 | 113 | int server; |
114 | char *name; | |
115 | int hostkey_type; | |
116 | int kex_type; | |
117 | Buffer my; | |
118 | Buffer peer; | |
2e437378 | 119 | sig_atomic_t done; |
3c0ef626 | 120 | int flags; |
e00da40d | 121 | const EVP_MD *evp_md; |
34fee935 | 122 | #ifdef GSSAPI |
e00da40d | 123 | int gss_deleg_creds; |
34fee935 | 124 | int gss_trust_dns; |
125 | char *gss_host; | |
126 | #endif | |
3c0ef626 | 127 | char *client_version_string; |
128 | char *server_version_string; | |
129 | int (*verify_host_key)(Key *); | |
130 | Key *(*load_host_key)(int); | |
2980ea68 | 131 | int (*host_key_index)(Key *); |
1c14df9e | 132 | void (*kex[KEX_MAX])(Kex *); |
3c0ef626 | 133 | }; |
134 | ||
34fee935 | 135 | void kex_prop2buf(Buffer *, char *proposal[PROPOSAL_MAX]); |
136 | ||
3c0ef626 | 137 | Kex *kex_setup(char *[PROPOSAL_MAX]); |
138 | void kex_finish(Kex *); | |
139 | ||
140 | void kex_send_kexinit(Kex *); | |
e9a17296 | 141 | void kex_input_kexinit(int, u_int32_t, void *); |
e00da40d | 142 | void kex_derive_keys(Kex *, u_char *, u_int, BIGNUM *); |
3c0ef626 | 143 | |
1c14df9e | 144 | Newkeys *kex_get_newkeys(int); |
145 | ||
146 | void kexdh_client(Kex *); | |
147 | void kexdh_server(Kex *); | |
148 | void kexgex_client(Kex *); | |
149 | void kexgex_server(Kex *); | |
34fee935 | 150 | |
b9a54c29 | 151 | #ifdef GSSAPI |
34fee935 | 152 | void kexgss_client(Kex *); |
153 | void kexgss_server(Kex *); | |
b9a54c29 | 154 | #endif |
3c0ef626 | 155 | |
e00da40d | 156 | void |
1c14df9e | 157 | kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int, |
e00da40d | 158 | BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *); |
159 | void | |
160 | kexgex_hash(const EVP_MD *, char *, char *, char *, int, char *, | |
2e437378 | 161 | int, u_char *, int, int, int, int, BIGNUM *, BIGNUM *, BIGNUM *, |
e00da40d | 162 | BIGNUM *, BIGNUM *, u_char **, u_int *); |
3c0ef626 | 163 | |
1b56ff3d | 164 | void |
165 | derive_ssh1_session_id(BIGNUM *, BIGNUM *, u_int8_t[8], u_int8_t[16]); | |
166 | ||
3c0ef626 | 167 | #if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) |
168 | void dump_digest(char *, u_char *, int); | |
169 | #endif | |
170 | ||
171 | #endif |