| 38 |
#include <openssl/engine.h> |
#include <openssl/engine.h> |
| 39 |
#include <openssl/rsa.h> |
#include <openssl/rsa.h> |
| 40 |
#include <openssl/dsa.h> |
#include <openssl/dsa.h> |
| 41 |
|
#include <openssl/md5.h> |
| 42 |
#include <limits.h> |
#include <limits.h> |
| 43 |
#include <malloc.h> |
#include <malloc.h> |
| 44 |
#include <string.h> |
#include <string.h> |
| 1258 |
|
|
| 1259 |
static BOOL handle_rsa_auth_refused(PTInstVar pvar) |
static BOOL handle_rsa_auth_refused(PTInstVar pvar) |
| 1260 |
{ |
{ |
| 1261 |
|
if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) { |
| 1262 |
|
if (pvar->pageant_keycount <= pvar->pageant_keycurrent) { |
| 1263 |
|
// 全ての鍵を試し終わった |
| 1264 |
|
safefree(pvar->pageant_key); |
| 1265 |
|
} |
| 1266 |
|
else { |
| 1267 |
|
// まだ鍵がある |
| 1268 |
|
pvar->ssh_state.status_flags &= ~STATUS_DONT_SEND_CREDENTIALS; |
| 1269 |
|
try_send_credentials(pvar); |
| 1270 |
|
return TRUE; |
| 1271 |
|
} |
| 1272 |
|
} |
| 1273 |
AUTH_destroy_cur_cred(pvar); |
AUTH_destroy_cur_cred(pvar); |
| 1274 |
return handle_auth_failure(pvar); |
return handle_auth_failure(pvar); |
| 1275 |
} |
} |
| 2220 |
} |
} |
| 2221 |
} |
} |
| 2222 |
else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) { |
else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) { |
| 2223 |
|
int server_key_bits = BN_num_bits(pvar->crypt_state.server_key.RSA_key->n); |
| 2224 |
|
int host_key_bits = BN_num_bits(pvar->crypt_state.host_key.RSA_key->n); |
| 2225 |
|
int server_key_bytes = (server_key_bits + 7) / 8; |
| 2226 |
|
int host_key_bytes = (host_key_bits + 7) / 8; |
| 2227 |
|
int session_buf_len = server_key_bytes + host_key_bytes + 8; |
| 2228 |
|
char FAR *session_buf = (char FAR *) malloc(session_buf_len); |
| 2229 |
|
unsigned char session_id[16]; |
| 2230 |
|
|
| 2231 |
unsigned char *hash; |
unsigned char *hash; |
| 2232 |
int pubkeylen, hashlen; |
int pubkeylen, hashlen; |
| 2233 |
|
|
| 2234 |
/* Pageant にハッシュを計算してもらう */ |
/* Pageant にハッシュを計算してもらう */ |
| 2235 |
|
// 公開鍵の長さ |
| 2236 |
pubkeylen = putty_get_ssh1_keylen(pvar->pageant_curkey, |
pubkeylen = putty_get_ssh1_keylen(pvar->pageant_curkey, |
| 2237 |
pvar->pageant_keylistlen); |
pvar->pageant_keylistlen); |
| 2238 |
|
// セッションIDを作成 |
| 2239 |
|
BN_bn2bin(pvar->crypt_state.host_key.RSA_key->n, session_buf); |
| 2240 |
|
BN_bn2bin(pvar->crypt_state.server_key.RSA_key->n, |
| 2241 |
|
session_buf + host_key_bytes); |
| 2242 |
|
memcpy(session_buf + server_key_bytes + host_key_bytes, |
| 2243 |
|
pvar->crypt_state.server_cookie, 8); |
| 2244 |
|
MD5(session_buf, session_buf_len, session_id); |
| 2245 |
|
// ハッシュを受け取る |
| 2246 |
hash = putty_hash_ssh1_challenge(pvar->pageant_curkey, |
hash = putty_hash_ssh1_challenge(pvar->pageant_curkey, |
| 2247 |
pubkeylen, |
pubkeylen, |
| 2248 |
pvar->ssh_state.payload, |
pvar->ssh_state.payload, |
| 2249 |
challenge_bytes + 2, |
challenge_bytes + 2, |
| 2250 |
|
session_id, |
| 2251 |
&hashlen); |
&hashlen); |
| 2252 |
|
|
| 2253 |
|
// ハッシュを送信 |
| 2254 |
|
memcpy(outmsg, hash, 16); |
| 2255 |
|
free(hash); |
| 2256 |
|
|
| 2257 |
|
finish_send_packet(pvar); |
| 2258 |
|
|
| 2259 |
|
enque_simple_auth_handlers(pvar); |
| 2260 |
} |
} |
| 2261 |
} |
} |
| 2262 |
|
|
| 2378 |
unsigned char *pubkey; |
unsigned char *pubkey; |
| 2379 |
int len, bn_bytes; |
int len, bn_bytes; |
| 2380 |
|
|
| 2381 |
|
if (pvar->pageant_keycurrent != 0) { |
| 2382 |
|
// 直前の鍵をスキップ |
| 2383 |
|
pvar->pageant_curkey += 4; |
| 2384 |
|
len = get_ushort16_MSBfirst(pvar->pageant_curkey); |
| 2385 |
|
bn_bytes = (len + 7) / 8; |
| 2386 |
|
pvar->pageant_curkey += 2 + bn_bytes; |
| 2387 |
|
len = get_ushort16_MSBfirst(pvar->pageant_curkey); |
| 2388 |
|
bn_bytes = (len + 7) / 8; |
| 2389 |
|
pvar->pageant_curkey += 2 + bn_bytes; |
| 2390 |
|
// 直前の鍵のコメントをスキップ |
| 2391 |
|
len = get_uint32_MSBfirst(pvar->pageant_curkey); |
| 2392 |
|
pvar->pageant_curkey += 4 + len; |
| 2393 |
|
// 次の鍵の位置へ来る |
| 2394 |
|
} |
| 2395 |
pubkey = pvar->pageant_curkey + 4; |
pubkey = pvar->pageant_curkey + 4; |
| 2396 |
len = get_ushort16_MSBfirst(pubkey); |
len = get_ushort16_MSBfirst(pubkey); |
| 2397 |
bn_bytes = (len + 7) / 8; |
bn_bytes = (len + 7) / 8; |
| 2408 |
set_ushort16_MSBfirst(outmsg, bn_bytes * 8); |
set_ushort16_MSBfirst(outmsg, bn_bytes * 8); |
| 2409 |
memcpy(outmsg + 2, pubkey, bn_bytes); |
memcpy(outmsg + 2, pubkey, bn_bytes); |
| 2410 |
/* don't destroy the current credentials yet */ |
/* don't destroy the current credentials yet */ |
| 2411 |
|
|
| 2412 |
|
pvar->pageant_keycurrent++; |
| 2413 |
|
|
| 2414 |
enque_handlers(pvar, 2, RSA_msgs, RSA_handlers); |
enque_handlers(pvar, 2, RSA_msgs, RSA_handlers); |
| 2415 |
break; |
break; |
| 2416 |
} |
} |
| 6550 |
// 直前の鍵のコメントをスキップ |
// 直前の鍵のコメントをスキップ |
| 6551 |
len = get_uint32_MSBfirst(pvar->pageant_curkey); |
len = get_uint32_MSBfirst(pvar->pageant_curkey); |
| 6552 |
pvar->pageant_curkey += 4 + len; |
pvar->pageant_curkey += 4 + len; |
| 6553 |
// 次の鍵へ来る |
// 次の鍵の位置へ来る |
| 6554 |
} |
} |
| 6555 |
puttykey = pvar->pageant_curkey; |
puttykey = pvar->pageant_curkey; |
| 6556 |
|
|