annotate signkey.c @ 847:f4bb964c8678 keyondemand

Add '-R' for delayed hostkey option
author Matt Johnston <matt@ucc.asn.au>
date Thu, 07 Nov 2013 23:49:37 +0800
parents b298bb438625
children 7540c0822374
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Dropbear - a SSH2 server
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * All rights reserved.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * all copies or substantial portions of the Software.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * SOFTWARE. */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #include "includes.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 #include "dbutil.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #include "signkey.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #include "buffer.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #include "ssh.h"
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
30 #include "ecdsa.h"
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
31
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
32 static const char *signkey_names[DROPBEAR_SIGNKEY_NUM_NAMED] = {
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
33 #ifdef DROPBEAR_RSA
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
34 "ssh-rsa",
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
35 #endif
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
36 #ifdef DROPBEAR_DSS
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
37 "ssh-dss",
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
38 #endif
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
39 #ifdef DROPBEAR_ECDSA
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
40 "ecdsa-sha2-nistp256",
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
41 "ecdsa-sha2-nistp384",
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
42 "ecdsa-sha2-nistp521",
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
43 "ecdsa" // for keygen
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
44 #endif // DROPBEAR_ECDSA
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
45 };
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 /* malloc a new sign_key and set the dss and rsa keys to NULL */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 sign_key * new_sign_key() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 sign_key * ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 ret = (sign_key*)m_malloc(sizeof(sign_key));
551
c3f2ec71e3d4 New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
Matt Johnston <matt@ucc.asn.au>
parents: 436
diff changeset
53 ret->type = DROPBEAR_SIGNKEY_NONE;
c3f2ec71e3d4 New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
Matt Johnston <matt@ucc.asn.au>
parents: 436
diff changeset
54 ret->source = SIGNKEY_SOURCE_INVALID;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 return ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
58 /* Returns key name corresponding to the type. Exits fatally
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
59 * if the type is invalid */
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
60 const char* signkey_name_from_type(enum signkey_type type, unsigned int *namelen) {
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
61 if (type >= DROPBEAR_SIGNKEY_NUM_NAMED) {
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
62 dropbear_exit("Bad key type %d", type);
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
63 }
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
64
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
65 if (namelen) {
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
66 *namelen = strlen(signkey_names[type]);
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
67 }
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
68 return signkey_names[type];
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
69 }
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
70
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
71 /* Returns DROPBEAR_SIGNKEY_NONE if none match */
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
72 enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) {
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
73 int i;
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
74 for (i = 0; i < DROPBEAR_SIGNKEY_NUM_NAMED; i++) {
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
75 const char *fixed_name = signkey_names[i];
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
76 if (namelen == strlen(fixed_name)
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
77 && memcmp(fixed_name, name, namelen) == 0) {
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
78
795
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
79 #ifdef DROPBEAR_ECDSA
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
80 /* Some of the ECDSA key sizes are defined even if they're not compiled in */
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
81 if (0
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
82 #ifndef DROPBEAR_ECC_256
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
83 || i == DROPBEAR_SIGNKEY_ECDSA_NISTP256
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
84 #endif
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
85 #ifndef DROPBEAR_ECC_384
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
86 || i == DROPBEAR_SIGNKEY_ECDSA_NISTP384
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
87 #endif
795
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
88 #ifndef DROPBEAR_ECC_521
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
89 || i == DROPBEAR_SIGNKEY_ECDSA_NISTP521
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
90 #endif
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
91 ) {
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
92 TRACE(("attempt to use ecdsa type %d not compiled in", i))
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
93 return DROPBEAR_SIGNKEY_NONE;
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
94 }
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
95 #endif
7f604f9b3756 ecdsa is working
Matt Johnston <matt@ucc.asn.au>
parents: 794
diff changeset
96
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
97 return i;
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
98 }
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
99 }
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
100
551
c3f2ec71e3d4 New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
Matt Johnston <matt@ucc.asn.au>
parents: 436
diff changeset
101 TRACE(("signkey_type_from_name unexpected key type."))
c3f2ec71e3d4 New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
Matt Johnston <matt@ucc.asn.au>
parents: 436
diff changeset
102
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
103 return DROPBEAR_SIGNKEY_NONE;
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
104 }
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
105
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
106 /* Returns a pointer to the key part specific to "type" */
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
107 void **
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
108 signkey_key_ptr(sign_key *key, enum signkey_type type) {
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
109 switch (type) {
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
110 #ifdef DROPBEAR_ECC_256
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
111 case DROPBEAR_SIGNKEY_ECDSA_NISTP256:
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
112 return (void**)&key->ecckey256;
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
113 #endif
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
114 #ifdef DROPBEAR_ECC_384
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
115 case DROPBEAR_SIGNKEY_ECDSA_NISTP384:
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
116 return (void**)&key->ecckey384;
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
117 #endif
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
118 #ifdef DROPBEAR_ECC_521
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
119 case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
120 return (void**)&key->ecckey521;
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
121 #endif
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
122 #ifdef DROPBEAR_RSA
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
123 case DROPBEAR_SIGNKEY_RSA:
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
124 return (void**)&key->rsakey;
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
125 #endif
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
126 #ifdef DROPBEAR_DSS
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
127 case DROPBEAR_SIGNKEY_DSS:
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
128 return (void**)&key->dsskey;
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
129 #endif
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
130 default:
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
131 return NULL;
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
132 }
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
133 }
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
134
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail.
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
136 * type should be set by the caller to specify the type to read, and
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
137 * on return is set to the type read (useful when type = _ANY) */
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
138 int buf_get_pub_key(buffer *buf, sign_key *key, enum signkey_type *type) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 unsigned char* ident;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 unsigned int len;
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
142 int keytype;
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
143 int ret = DROPBEAR_FAILURE;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
145 TRACE2(("enter buf_get_pub_key"))
34
e2a1eaa19f22 Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
146
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 ident = buf_getstring(buf, &len);
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
148 keytype = signkey_type_from_name(ident, len);
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
149 m_free(ident);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
151 if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) {
651
a48a1f6ab43e - Fix some format strings in TRACE()s
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
152 TRACE(("buf_get_pub_key bad type - got %d, expected %d", keytype, *type))
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
153 return DROPBEAR_FAILURE;
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
154 }
551
c3f2ec71e3d4 New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
Matt Johnston <matt@ucc.asn.au>
parents: 436
diff changeset
155
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
156 TRACE2(("buf_get_pub_key keytype is %d", keytype))
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
157
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
158 *type = keytype;
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
159
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
160 /* Rewind the buffer back before "ssh-rsa" etc */
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
161 buf_incrpos(buf, -len - 4);
34
e2a1eaa19f22 Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
162
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 #ifdef DROPBEAR_DSS
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
164 if (keytype == DROPBEAR_SIGNKEY_DSS) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 dss_key_free(key->dsskey);
586
b50f0107e505 Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents: 560
diff changeset
166 key->dsskey = m_malloc(sizeof(*key->dsskey));
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
167 ret = buf_get_dss_pub_key(buf, key->dsskey);
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
168 if (ret == DROPBEAR_FAILURE) {
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
169 m_free(key->dsskey);
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
170 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 #ifdef DROPBEAR_RSA
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
174 if (keytype == DROPBEAR_SIGNKEY_RSA) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 rsa_key_free(key->rsakey);
586
b50f0107e505 Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents: 560
diff changeset
176 key->rsakey = m_malloc(sizeof(*key->rsakey));
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
177 ret = buf_get_rsa_pub_key(buf, key->rsakey);
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
178 if (ret == DROPBEAR_FAILURE) {
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
179 m_free(key->rsakey);
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
180 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 #endif
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
183 #ifdef DROPBEAR_ECDSA
846
b298bb438625 refactor key generation, make it generate as required.
Matt Johnston <matt@ucc.asn.au>
parents: 841
diff changeset
184 if (signkey_is_ecdsa(keytype)) {
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
185 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
186 if (eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
187 if (*eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
188 ecc_free(*eck);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
189 *eck = NULL;
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
190 }
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
191 *eck = buf_get_ecdsa_pub_key(buf);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
192 if (*eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
193 ret = DROPBEAR_SUCCESS;
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
194 }
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
195 }
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
196 }
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
197 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
199 TRACE2(("leave buf_get_pub_key"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
201 return ret;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
205 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail.
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
206 * type should be set by the caller to specify the type to read, and
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
207 * on return is set to the type read (useful when type = _ANY) */
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
208 int buf_get_priv_key(buffer *buf, sign_key *key, enum signkey_type *type) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 unsigned char* ident;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211 unsigned int len;
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
212 int keytype;
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
213 int ret = DROPBEAR_FAILURE;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
215 TRACE2(("enter buf_get_priv_key"))
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
216
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 ident = buf_getstring(buf, &len);
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
218 keytype = signkey_type_from_name(ident, len);
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
219 m_free(ident);
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
220
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
221 if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
222 TRACE(("wrong key type: %d %d", *type, keytype))
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
223 return DROPBEAR_FAILURE;
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
224 }
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
225
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
226 *type = keytype;
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
227
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
228 /* Rewind the buffer back before "ssh-rsa" etc */
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
229 buf_incrpos(buf, -len - 4);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 #ifdef DROPBEAR_DSS
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
232 if (keytype == DROPBEAR_SIGNKEY_DSS) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 dss_key_free(key->dsskey);
586
b50f0107e505 Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents: 560
diff changeset
234 key->dsskey = m_malloc(sizeof(*key->dsskey));
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235 ret = buf_get_dss_priv_key(buf, key->dsskey);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236 if (ret == DROPBEAR_FAILURE) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 m_free(key->dsskey);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241 #ifdef DROPBEAR_RSA
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
242 if (keytype == DROPBEAR_SIGNKEY_RSA) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243 rsa_key_free(key->rsakey);
586
b50f0107e505 Rename rsa_key to dropbear_rsa_key (and same for dss too) so
Matt Johnston <matt@ucc.asn.au>
parents: 560
diff changeset
244 key->rsakey = m_malloc(sizeof(*key->rsakey));
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245 ret = buf_get_rsa_priv_key(buf, key->rsakey);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246 if (ret == DROPBEAR_FAILURE) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247 m_free(key->rsakey);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 #endif
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
251 #ifdef DROPBEAR_ECDSA
846
b298bb438625 refactor key generation, make it generate as required.
Matt Johnston <matt@ucc.asn.au>
parents: 841
diff changeset
252 if (signkey_is_ecdsa(keytype)) {
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
253 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
254 if (eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
255 if (*eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
256 ecc_free(*eck);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
257 *eck = NULL;
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
258 }
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
259 *eck = buf_get_ecdsa_priv_key(buf);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
260 if (*eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
261 ret = DROPBEAR_SUCCESS;
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
262 }
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
263 }
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
264 }
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
265 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
267 TRACE2(("leave buf_get_priv_key"))
44
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
268
45edf30ea0a6 Improved signkey code
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
269 return ret;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
271 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
272
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
274 void buf_put_pub_key(buffer* buf, sign_key *key, enum signkey_type type) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276 buffer *pubkeys;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
277
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
278 TRACE2(("enter buf_put_pub_key"))
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
279 pubkeys = buf_new(MAX_PUBKEY_SIZE);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
281 #ifdef DROPBEAR_DSS
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282 if (type == DROPBEAR_SIGNKEY_DSS) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 buf_put_dss_pub_key(pubkeys, key->dsskey);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286 #ifdef DROPBEAR_RSA
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287 if (type == DROPBEAR_SIGNKEY_RSA) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
288 buf_put_rsa_pub_key(pubkeys, key->rsakey);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290 #endif
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
291 #ifdef DROPBEAR_ECDSA
846
b298bb438625 refactor key generation, make it generate as required.
Matt Johnston <matt@ucc.asn.au>
parents: 841
diff changeset
292 if (signkey_is_ecdsa(type)) {
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
293 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
294 if (eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
295 buf_put_ecdsa_pub_key(pubkeys, *eck);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
296 }
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
297 }
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
298 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299 if (pubkeys->len == 0) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 586
diff changeset
300 dropbear_exit("Bad key types in buf_put_pub_key");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
301 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302
760
f336d232fc63 Make _sign and _verify functions take a buffer* rather than void* and int
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
303 buf_putbufstring(buf, pubkeys);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
304 buf_free(pubkeys);
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
305 TRACE2(("leave buf_put_pub_key"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
308 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
309 void buf_put_priv_key(buffer* buf, sign_key *key, enum signkey_type type) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
311 TRACE(("enter buf_put_priv_key"))
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
312 TRACE(("type is %d", type))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 #ifdef DROPBEAR_DSS
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315 if (type == DROPBEAR_SIGNKEY_DSS) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316 buf_put_dss_priv_key(buf, key->dsskey);
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
317 TRACE(("leave buf_put_priv_key: dss done"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321 #ifdef DROPBEAR_RSA
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 if (type == DROPBEAR_SIGNKEY_RSA) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323 buf_put_rsa_priv_key(buf, key->rsakey);
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
324 TRACE(("leave buf_put_priv_key: rsa done"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
327 #endif
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
328 #ifdef DROPBEAR_ECDSA
846
b298bb438625 refactor key generation, make it generate as required.
Matt Johnston <matt@ucc.asn.au>
parents: 841
diff changeset
329 if (signkey_is_ecdsa(type)) {
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
330 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
331 if (eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
332 buf_put_ecdsa_priv_key(buf, *eck);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
333 TRACE(("leave buf_put_priv_key: ecdsa done"))
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
334 return;
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
335 }
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
336 }
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
337 #endif
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 586
diff changeset
338 dropbear_exit("Bad key types in put pub key");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
339 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
340
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
341 void sign_key_free(sign_key *key) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
342
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
343 TRACE2(("enter sign_key_free"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
344
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
345 #ifdef DROPBEAR_DSS
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
346 dss_key_free(key->dsskey);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
347 key->dsskey = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
348 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
349 #ifdef DROPBEAR_RSA
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
350 rsa_key_free(key->rsakey);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
351 key->rsakey = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
352 #endif
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
353 #ifdef DROPBEAR_ECDSA
847
f4bb964c8678 Add '-R' for delayed hostkey option
Matt Johnston <matt@ucc.asn.au>
parents: 846
diff changeset
354 #ifdef DROPBEAR_ECC_256
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
355 if (key->ecckey256) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
356 ecc_free(key->ecckey256);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
357 key->ecckey256 = NULL;
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
358 }
847
f4bb964c8678 Add '-R' for delayed hostkey option
Matt Johnston <matt@ucc.asn.au>
parents: 846
diff changeset
359 #endif
f4bb964c8678 Add '-R' for delayed hostkey option
Matt Johnston <matt@ucc.asn.au>
parents: 846
diff changeset
360 #ifdef DROPBEAR_ECC_384
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
361 if (key->ecckey384) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
362 ecc_free(key->ecckey384);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
363 key->ecckey384 = NULL;
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
364 }
847
f4bb964c8678 Add '-R' for delayed hostkey option
Matt Johnston <matt@ucc.asn.au>
parents: 846
diff changeset
365 #endif
f4bb964c8678 Add '-R' for delayed hostkey option
Matt Johnston <matt@ucc.asn.au>
parents: 846
diff changeset
366 #ifdef DROPBEAR_ECC_521
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
367 if (key->ecckey521) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
368 ecc_free(key->ecckey521);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
369 key->ecckey521 = NULL;
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
370 }
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
371 #endif
847
f4bb964c8678 Add '-R' for delayed hostkey option
Matt Johnston <matt@ucc.asn.au>
parents: 846
diff changeset
372 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
373
551
c3f2ec71e3d4 New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
Matt Johnston <matt@ucc.asn.au>
parents: 436
diff changeset
374 m_free(key->filename);
c3f2ec71e3d4 New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
Matt Johnston <matt@ucc.asn.au>
parents: 436
diff changeset
375
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
376 m_free(key);
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
377 TRACE2(("leave sign_key_free"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
379
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380 static char hexdig(unsigned char x) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
381 if (x > 0xf)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
382 return 'X';
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
383
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
384 if (x < 10)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
385 return '0' + x;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386 else
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
387 return 'a' + x - 10;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
389
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390 /* Since we're not sure if we'll have md5 or sha1, we present both.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
391 * MD5 is used in preference, but sha1 could still be useful */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
392 #ifdef DROPBEAR_MD5_HMAC
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
393 static char * sign_key_md5_fingerprint(unsigned char* keyblob,
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
394 unsigned int keybloblen) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
395
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
396 char * ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
397 hash_state hs;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
398 unsigned char hash[MD5_HASH_SIZE];
214
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
399 unsigned int i;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
400 unsigned int buflen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
401
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
402 md5_init(&hs);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
403
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
404 /* skip the size int of the string - this is a bit messy */
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
405 md5_process(&hs, keyblob, keybloblen);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
407 md5_done(&hs, hash);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
408
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409 /* "md5 hexfingerprinthere\0", each hex digit is "AB:" etc */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410 buflen = 4 + 3*MD5_HASH_SIZE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
411 ret = (char*)m_malloc(buflen);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413 memset(ret, 'Z', buflen);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
414 strcpy(ret, "md5 ");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415
214
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
416 for (i = 0; i < MD5_HASH_SIZE; i++) {
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
417 unsigned int pos = 4 + i*3;
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
418 ret[pos] = hexdig(hash[i] >> 4);
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
419 ret[pos+1] = hexdig(hash[i] & 0x0f);
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
420 ret[pos+2] = ':';
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
421 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
422 ret[buflen-1] = 0x0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
424 return ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
426
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
427 #else /* use SHA1 rather than MD5 for fingerprint */
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
428 static char * sign_key_sha1_fingerprint(unsigned char* keyblob,
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
429 unsigned int keybloblen) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
430
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
431 char * ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
432 hash_state hs;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
433 unsigned char hash[SHA1_HASH_SIZE];
214
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
434 unsigned int i;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
435 unsigned int buflen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
437 sha1_init(&hs);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
438
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
439 /* skip the size int of the string - this is a bit messy */
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
440 sha1_process(&hs, keyblob, keybloblen);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
442 sha1_done(&hs, hash);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
443
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
444 /* "sha1!! hexfingerprinthere\0", each hex digit is "AB:" etc */
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
445 buflen = 7 + 3*SHA1_HASH_SIZE;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
446 ret = (char*)m_malloc(buflen);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
447
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
448 strcpy(ret, "sha1!! ");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
449
214
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
450 for (i = 0; i < SHA1_HASH_SIZE; i++) {
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
451 unsigned int pos = 7 + 3*i;
214
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
452 ret[pos] = hexdig(hash[i] >> 4);
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
453 ret[pos+1] = hexdig(hash[i] & 0x0f);
5a75f8a21503 Change the format of for loops, gcc4 produces incorrect binaries with
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
454 ret[pos+2] = ':';
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
455 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
456 ret[buflen-1] = 0x0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
457
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
458 return ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
459 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
460
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461 #endif /* MD5/SHA1 switch */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
463 /* This will return a freshly malloced string, containing a fingerprint
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
464 * in either sha1 or md5 */
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
465 char * sign_key_fingerprint(unsigned char* keyblob, unsigned int keybloblen) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
466
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
467 #ifdef DROPBEAR_MD5_HMAC
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
468 return sign_key_md5_fingerprint(keyblob, keybloblen);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
469 #else
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
470 return sign_key_sha1_fingerprint(keyblob, keybloblen);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
471 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
474 void buf_put_sign(buffer* buf, sign_key *key, enum signkey_type type,
760
f336d232fc63 Make _sign and _verify functions take a buffer* rather than void* and int
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
475 buffer *data_buf) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
476 buffer *sigblob;
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
477 sigblob = buf_new(MAX_PUBKEY_SIZE);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
478
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
479 #ifdef DROPBEAR_DSS
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
480 if (type == DROPBEAR_SIGNKEY_DSS) {
760
f336d232fc63 Make _sign and _verify functions take a buffer* rather than void* and int
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
481 buf_put_dss_sign(sigblob, key->dsskey, data_buf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
482 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
483 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
484 #ifdef DROPBEAR_RSA
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
485 if (type == DROPBEAR_SIGNKEY_RSA) {
760
f336d232fc63 Make _sign and _verify functions take a buffer* rather than void* and int
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
486 buf_put_rsa_sign(sigblob, key->rsakey, data_buf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
487 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
488 #endif
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
489 #ifdef DROPBEAR_ECDSA
846
b298bb438625 refactor key generation, make it generate as required.
Matt Johnston <matt@ucc.asn.au>
parents: 841
diff changeset
490 if (signkey_is_ecdsa(type)) {
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
491 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
492 if (eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
493 buf_put_ecdsa_sign(sigblob, *eck, data_buf);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
494 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
495 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
496 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
497 if (sigblob->len == 0) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 586
diff changeset
498 dropbear_exit("Non-matching signing type");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
499 }
760
f336d232fc63 Make _sign and _verify functions take a buffer* rather than void* and int
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
500 buf_putbufstring(buf, sigblob);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
501 buf_free(sigblob);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
502
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
503 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
504
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
505 #ifdef DROPBEAR_SIGNKEY_VERIFY
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
506 /* Return DROPBEAR_SUCCESS or DROPBEAR_FAILURE.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
507 * If FAILURE is returned, the position of
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
508 * buf is undefined. If SUCCESS is returned, buf will be positioned after the
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
509 * signature blob */
760
f336d232fc63 Make _sign and _verify functions take a buffer* rather than void* and int
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
510 int buf_verify(buffer * buf, sign_key *key, buffer *data_buf) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
511
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
512 unsigned int bloblen;
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
513 unsigned char * type_name = NULL;
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
514 unsigned int type_name_len = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
515
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
516 TRACE(("enter buf_verify"))
34
e2a1eaa19f22 Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents: 26
diff changeset
517
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
518 bloblen = buf_getint(buf);
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
519 type_name = buf_getstring(buf, &type_name_len);
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
520 enum signkey_type type = signkey_type_from_name(type_name, type_name_len);
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
521 m_free(type_name);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
522
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
523 #ifdef DROPBEAR_DSS
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
524 if (type == DROPBEAR_SIGNKEY_DSS) {
244
eb7b9f2bb8e8 - add explicit check that correct keytype exists for pubkey verification
Matt Johnston <matt@ucc.asn.au>
parents: 214
diff changeset
525 if (key->dsskey == NULL) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 586
diff changeset
526 dropbear_exit("No DSS key to verify signature");
244
eb7b9f2bb8e8 - add explicit check that correct keytype exists for pubkey verification
Matt Johnston <matt@ucc.asn.au>
parents: 214
diff changeset
527 }
760
f336d232fc63 Make _sign and _verify functions take a buffer* rather than void* and int
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
528 return buf_dss_verify(buf, key->dsskey, data_buf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
529 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
530 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
531
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
532 #ifdef DROPBEAR_RSA
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
533 if (type == DROPBEAR_SIGNKEY_RSA) {
244
eb7b9f2bb8e8 - add explicit check that correct keytype exists for pubkey verification
Matt Johnston <matt@ucc.asn.au>
parents: 214
diff changeset
534 if (key->rsakey == NULL) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 586
diff changeset
535 dropbear_exit("No RSA key to verify signature");
244
eb7b9f2bb8e8 - add explicit check that correct keytype exists for pubkey verification
Matt Johnston <matt@ucc.asn.au>
parents: 214
diff changeset
536 }
760
f336d232fc63 Make _sign and _verify functions take a buffer* rather than void* and int
Matt Johnston <matt@ucc.asn.au>
parents: 651
diff changeset
537 return buf_rsa_verify(buf, key->rsakey, data_buf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
538 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
539 #endif
794
d386defb5376 more ecdsa signkey work, not correct
Matt Johnston <matt@ucc.asn.au>
parents: 793
diff changeset
540 #ifdef DROPBEAR_ECDSA
846
b298bb438625 refactor key generation, make it generate as required.
Matt Johnston <matt@ucc.asn.au>
parents: 841
diff changeset
541 if (signkey_is_ecdsa(type)) {
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 807
diff changeset
542 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
807
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
543 if (eck) {
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
544 return buf_ecdsa_verify(buf, *eck, data_buf);
75509065db53 have separate ecdsa keys for each size
Matt Johnston <matt@ucc.asn.au>
parents: 801
diff changeset
545 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
546 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
547 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
548
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 586
diff changeset
549 dropbear_exit("Non-matching signing type");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
550 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
551 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
552 #endif /* DROPBEAR_SIGNKEY_VERIFY */
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
553
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
554 #ifdef DROPBEAR_KEY_LINES /* ie we're using authorized_keys or known_hosts */
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
555
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
556 /* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE when given a buffer containing
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
557 * a key, a key, and a type. The buffer is positioned at the start of the
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
558 * base64 data, and contains no trailing data */
436
7282370416a0 Improve known_hosts checking.
Matt Johnston <matt@ucc.asn.au>
parents: 244
diff changeset
559 /* If fingerprint is non-NULL, it will be set to a malloc()ed fingerprint
7282370416a0 Improve known_hosts checking.
Matt Johnston <matt@ucc.asn.au>
parents: 244
diff changeset
560 of the key if it is successfully decoded */
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
561 int cmp_base64_key(const unsigned char* keyblob, unsigned int keybloblen,
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
562 const unsigned char* algoname, unsigned int algolen,
436
7282370416a0 Improve known_hosts checking.
Matt Johnston <matt@ucc.asn.au>
parents: 244
diff changeset
563 buffer * line, char ** fingerprint) {
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
564
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
565 buffer * decodekey = NULL;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
566 int ret = DROPBEAR_FAILURE;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
567 unsigned int len, filealgolen;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
568 unsigned long decodekeylen;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
569 unsigned char* filealgo = NULL;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
570
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
571 /* now we have the actual data */
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
572 len = line->len - line->pos;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
573 decodekeylen = len * 2; /* big to be safe */
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
574 decodekey = buf_new(decodekeylen);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
575
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
576 if (base64_decode(buf_getptr(line, len), len,
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
577 buf_getwriteptr(decodekey, decodekey->size),
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
578 &decodekeylen) != CRYPT_OK) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
579 TRACE(("checkpubkey: base64 decode failed"))
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
580 goto out;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
581 }
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
582 TRACE(("checkpubkey: base64_decode success"))
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
583 buf_incrlen(decodekey, decodekeylen);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
584
436
7282370416a0 Improve known_hosts checking.
Matt Johnston <matt@ucc.asn.au>
parents: 244
diff changeset
585 if (fingerprint) {
7282370416a0 Improve known_hosts checking.
Matt Johnston <matt@ucc.asn.au>
parents: 244
diff changeset
586 *fingerprint = sign_key_fingerprint(buf_getptr(decodekey, decodekeylen),
7282370416a0 Improve known_hosts checking.
Matt Johnston <matt@ucc.asn.au>
parents: 244
diff changeset
587 decodekeylen);
7282370416a0 Improve known_hosts checking.
Matt Johnston <matt@ucc.asn.au>
parents: 244
diff changeset
588 }
7282370416a0 Improve known_hosts checking.
Matt Johnston <matt@ucc.asn.au>
parents: 244
diff changeset
589
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
590 /* compare the keys */
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
591 if ( ( decodekeylen != keybloblen )
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
592 || memcmp( buf_getptr(decodekey, decodekey->len),
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
593 keyblob, decodekey->len) != 0) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
594 TRACE(("checkpubkey: compare failed"))
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
595 goto out;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
596 }
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
597
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
598 /* ... and also check that the algo specified and the algo in the key
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
599 * itself match */
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
600 filealgolen = buf_getint(decodekey);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
601 filealgo = buf_getptr(decodekey, filealgolen);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
602 if (filealgolen != algolen || memcmp(filealgo, algoname, algolen) != 0) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
603 TRACE(("checkpubkey: algo match failed"))
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
604 goto out;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
605 }
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
606
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
607 /* All checks passed */
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
608 ret = DROPBEAR_SUCCESS;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
609
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
610 out:
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
611 buf_free(decodekey);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
612 decodekey = NULL;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
613 return ret;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
614 }
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 44
diff changeset
615 #endif