Mercurial > dropbear
comparison cli-authpubkey.c @ 47:4b53a43f0082
- client pubkey auth works
- rearrange the runopts code for client and server (hostkey reading is needed
by both (if the client is doing pubkey auth. otherwise....))
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 06 Aug 2004 16:18:01 +0000 |
parents | 9ee8996a375f |
children | 20563735e8b5 |
comparison
equal
deleted
inserted
replaced
46:3bea78e1b175 | 47:4b53a43f0082 |
---|---|
14 | 14 |
15 struct PubkeyList *keyitem; | 15 struct PubkeyList *keyitem; |
16 | 16 |
17 TRACE(("enter cli_pubkeyfail")); | 17 TRACE(("enter cli_pubkeyfail")); |
18 /* Find the key we failed with, and remove it */ | 18 /* Find the key we failed with, and remove it */ |
19 for (keyitem = cli_ses.pubkeys; keyitem != NULL; keyitem = keyitem->next) { | 19 for (keyitem = cli_opts.pubkeys; keyitem != NULL; keyitem = keyitem->next) { |
20 if (keyitem->next == cli_ses.lastpubkey) { | 20 if (keyitem->next == cli_ses.lastpubkey) { |
21 keyitem->next = cli_ses.lastpubkey->next; | 21 keyitem->next = cli_ses.lastpubkey->next; |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
38 | 38 |
39 TRACE(("enter recv_msg_userauth_pk_ok")); | 39 TRACE(("enter recv_msg_userauth_pk_ok")); |
40 | 40 |
41 algotype = buf_getstring(ses.payload, &algolen); | 41 algotype = buf_getstring(ses.payload, &algolen); |
42 keytype = signkey_type_from_name(algotype, algolen); | 42 keytype = signkey_type_from_name(algotype, algolen); |
43 TRACE(("recv_msg_userauth_pk_ok: type %d", keytype)); | |
43 m_free(algotype); | 44 m_free(algotype); |
44 | 45 |
45 keybuf = buf_new(MAX_PUBKEY_SIZE); | 46 keybuf = buf_new(MAX_PUBKEY_SIZE); |
46 | 47 |
47 remotelen = buf_getint(ses.payload); | 48 remotelen = buf_getint(ses.payload); |
48 | 49 |
49 /* Iterate through our keys, find which one it was that matched, and | 50 /* Iterate through our keys, find which one it was that matched, and |
50 * send a real request with that key */ | 51 * send a real request with that key */ |
51 for (keyitem = cli_ses.pubkeys; keyitem != NULL; keyitem = keyitem->next) { | 52 for (keyitem = cli_opts.pubkeys; keyitem != NULL; keyitem = keyitem->next) { |
52 | 53 |
53 if (keyitem->type != keytype) { | 54 if (keyitem->type != keytype) { |
54 /* Types differed */ | 55 /* Types differed */ |
56 TRACE(("types differed")); | |
55 continue; | 57 continue; |
56 } | 58 } |
57 | 59 |
58 /* Now we compare the contents of the key */ | 60 /* Now we compare the contents of the key */ |
59 keybuf->pos = keybuf->len = 0; | 61 keybuf->pos = keybuf->len = 0; |
60 buf_put_pub_key(keybuf, keyitem->key, keytype); | 62 buf_put_pub_key(keybuf, keyitem->key, keytype); |
63 buf_setpos(keybuf, 0); | |
64 buf_incrpos(keybuf, 4); /* first int is the length of the remainder (ie | |
65 remotelen) which has already been taken from | |
66 the remote buffer */ | |
61 | 67 |
62 if (keybuf->len != remotelen) { | 68 |
69 if (keybuf->len-4 != remotelen) { | |
70 TRACE(("lengths differed: localh %d remote %d", keybuf->len, remotelen)); | |
63 /* Lengths differed */ | 71 /* Lengths differed */ |
64 continue; | 72 continue; |
65 } | 73 } |
66 | 74 if (memcmp(buf_getptr(keybuf, remotelen), |
67 if (memcmp(keybuf->data, | |
68 buf_getptr(ses.payload, remotelen), remotelen) != 0) { | 75 buf_getptr(ses.payload, remotelen), remotelen) != 0) { |
69 /* Data didn't match this key */ | 76 /* Data didn't match this key */ |
77 TRACE(("data differed")); | |
70 continue; | 78 continue; |
71 } | 79 } |
72 | 80 |
73 /* Success */ | 81 /* Success */ |
74 break; | 82 break; |
131 | 139 |
132 int cli_auth_pubkey() { | 140 int cli_auth_pubkey() { |
133 | 141 |
134 TRACE(("enter cli_auth_pubkey")); | 142 TRACE(("enter cli_auth_pubkey")); |
135 | 143 |
136 if (cli_ses.pubkeys != NULL) { | 144 if (cli_opts.pubkeys != NULL) { |
137 /* Send a trial request */ | 145 /* Send a trial request */ |
138 send_msg_userauth_pubkey(cli_ses.pubkeys->key, | 146 send_msg_userauth_pubkey(cli_opts.pubkeys->key, |
139 cli_ses.pubkeys->type, 0); | 147 cli_opts.pubkeys->type, 0); |
140 TRACE(("leave cli_auth_pubkey-success")); | 148 TRACE(("leave cli_auth_pubkey-success")); |
141 return 1; | 149 return 1; |
142 } else { | 150 } else { |
143 TRACE(("leave cli_auth_pubkey-failure")); | 151 TRACE(("leave cli_auth_pubkey-failure")); |
144 return 0; | 152 return 0; |