svnno****@sourc*****
svnno****@sourc*****
2012年 10月 17日 (水) 21:05:49 JST
Revision: 5048 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5048 Author: yutakapon Date: 2012-10-17 21:05:49 +0900 (Wed, 17 Oct 2012) Log Message: ----------- SECSH(sshcom)形式を暫定サポートした。 拡張子はとりあえず".sshcom"と仮定。 Modified Paths: -------------- branches/ssh_putty_pubkey/ttssh2/putty/libputty.c branches/ssh_putty_pubkey/ttssh2/putty/libputty.h branches/ssh_putty_pubkey/ttssh2/ttxssh/auth.c branches/ssh_putty_pubkey/ttssh2/ttxssh/keyfiles.c -------------- next part -------------- Modified: branches/ssh_putty_pubkey/ttssh2/putty/libputty.c =================================================================== --- branches/ssh_putty_pubkey/ttssh2/putty/libputty.c 2012-10-17 11:24:54 UTC (rev 5047) +++ branches/ssh_putty_pubkey/ttssh2/putty/libputty.c 2012-10-17 12:05:49 UTC (rev 5048) @@ -11,19 +11,13 @@ #include "ssh.h" #include "libputty.h" -/* - * PuTTY\x8C`\x8E\xAE\x82̌\xAE\x83t\x83@\x83C\x83\x8B\x82\xF0\x93ǂݍ\x9E\x82݁AOpenSSH\x8C`\x8E\xAE\x82̌\xAE\x83t\x83@\x83C\x83\x8B\x82ɕϊ\xB7\x82\xB7\x82\xE9\x81B - * (2012.10.16 yutaka) - */ -int load_and_convert_putty_keyfile(char *file, char *pass, char *outfile) + +static int common_convert_keyfile(struct ssh2_userkey *ssh2key, char *pass, char *outfile) { - struct ssh2_userkey *ssh2key = NULL; - Filename filename, outfilename; + Filename outfilename; const char *error = NULL; int ret = -1; - filename = filename_from_str(file); - ssh2key = ssh2_load_userkey(&filename, pass, &error); if (ssh2key && ssh2key != SSH2_WRONG_PASSPHRASE) { error = NULL; // success } else if (error == NULL) { @@ -45,11 +39,47 @@ ret = 0; } } + return (ret); +} +/* + * SECSH(ssh.com)\x8C`\x8E\xAE\x82̌\xAE\x83t\x83@\x83C\x83\x8B\x82\xF0\x93ǂݍ\x9E\x82݁AOpenSSH\x8C`\x8E\xAE\x82̌\xAE\x83t\x83@\x83C\x83\x8B\x82ɕϊ\xB7\x82\xB7\x82\xE9\x81B + * (2012.10.17 yutaka) + */ +int load_and_convert_sshcom_keyfile(char *file, char *pass, char *outfile) +{ + struct ssh2_userkey *ssh2key = NULL; + const char *error = NULL; + Filename filename; + int ret = -1; + + filename = filename_from_str(file); + ssh2key = import_ssh2(&filename, SSH_KEYTYPE_SSHCOM, pass, &error); + ret = common_convert_keyfile(ssh2key, pass, outfile); + return (ret); } +/* + * PuTTY\x8C`\x8E\xAE\x82̌\xAE\x83t\x83@\x83C\x83\x8B\x82\xF0\x93ǂݍ\x9E\x82݁AOpenSSH\x8C`\x8E\xAE\x82̌\xAE\x83t\x83@\x83C\x83\x8B\x82ɕϊ\xB7\x82\xB7\x82\xE9\x81B + * (2012.10.16 yutaka) + */ +int load_and_convert_putty_keyfile(char *file, char *pass, char *outfile) +{ + struct ssh2_userkey *ssh2key = NULL; + const char *error = NULL; + Filename filename; + int ret = -1; + + filename = filename_from_str(file); + ssh2key = ssh2_load_userkey(&filename, pass, &error); + ret = common_convert_keyfile(ssh2key, pass, outfile); + + return (ret); +} + + /* * for SSH2 * \x8C\xAE\x82̈ꗗ\x82\xE9 Modified: branches/ssh_putty_pubkey/ttssh2/putty/libputty.h =================================================================== --- branches/ssh_putty_pubkey/ttssh2/putty/libputty.h 2012-10-17 11:24:54 UTC (rev 5047) +++ branches/ssh_putty_pubkey/ttssh2/putty/libputty.h 2012-10-17 12:05:49 UTC (rev 5048) @@ -3,6 +3,7 @@ */ // PuTTY is copyright 1997-2007 Simon Tatham. +int load_and_convert_sshcom_keyfile(char *file, char *pass, char *outfile); int load_and_convert_putty_keyfile(char *file, char *pass, char *outfile); // WINDOWS\WINPGNTC.C Modified: branches/ssh_putty_pubkey/ttssh2/ttxssh/auth.c =================================================================== --- branches/ssh_putty_pubkey/ttssh2/ttxssh/auth.c 2012-10-17 11:24:54 UTC (rev 5047) +++ branches/ssh_putty_pubkey/ttssh2/ttxssh/auth.c 2012-10-17 12:05:49 UTC (rev 5048) @@ -377,8 +377,9 @@ // \x83t\x83B\x83\x8B\x83^\x82̒lj\xC1 (2004.12.19 yutaka) // 3\x83t\x83@\x83C\x83\x8B\x83t\x83B\x83\x8B\x83^\x82̒lj\xC1 (2005.4.26 yutaka) // PuTTY\x83t\x83B\x83\x8B\x83^\x82̒lj\xC1 (2012.10.17 yutaka) + // SECSH(ssh.com)\x83t\x83B\x83\x8B\x83^\x82̒lj\xC1 (2012.10.17 yutaka) UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_FILTER", pvar, - "identity files\\0identity;id_rsa;id_dsa;id_ecdsa\\0identity(RSA1)\\0identity\\0id_rsa(SSH2)\\0id_rsa\\0id_dsa(SSH2)\\0id_dsa\\0id_ecdsa(SSH2)\\0id_ecdsa\\0PuTTY(*.ppk)\\0*.ppk\\0all(*.*)\\0*.*\\0\\0"); + "identity files\\0identity;id_rsa;id_dsa;id_ecdsa\\0identity(RSA1)\\0identity\\0id_rsa(SSH2)\\0id_rsa\\0id_dsa(SSH2)\\0id_dsa\\0id_ecdsa(SSH2)\\0id_ecdsa\\0PuTTY(*.ppk)\\0*.ppk\\0SECSH(*.sshcom)\\0*.sshcom\\0all(*.*)\\0*.*\\0\\0"); memcpy(filter, pvar->ts->UIMsg, sizeof(filter)); params.lpstrFilter = filter; params.lpstrCustomFilter = NULL; Modified: branches/ssh_putty_pubkey/ttssh2/ttxssh/keyfiles.c =================================================================== --- branches/ssh_putty_pubkey/ttssh2/ttxssh/keyfiles.c 2012-10-17 11:24:54 UTC (rev 5047) +++ branches/ssh_putty_pubkey/ttssh2/ttxssh/keyfiles.c 2012-10-17 12:05:49 UTC (rev 5048) @@ -341,13 +341,19 @@ // SSH2 // -static int import_putty_keyfile(char *filename, char *passphrase, char *newfile, int newfilelen) +static int import_not_openssh_keyfile(char *filename, char *passphrase, char *newfile, int newfilelen) { int ret = -1; + int putty_key = 0, sshcom_key = 0; // \x8Ag\x92\xA3\x8Eq\x82\xAA.ppk\x82Ȃ\xE7\x82APuTTY\x8C`\x8E\xAE\x82̌\xAE\x83t\x83@\x83C\x83\x8B\x82ƌ\xA9\x82Ȃ\xB7\x81B - if (strstr(filename, ".ppk") == NULL) + if (strstr(filename, ".ppk") != NULL) { + putty_key = 1; + } else if (strstr(filename, ".sshcom") != NULL) { + sshcom_key = 1; + } else { goto error; + } // \x88ꎞ\x83t\x83@\x83C\x83\x8B\x82̖\xBC\x91O\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B if (tmpnam_s(newfile, newfilelen) != 0) @@ -355,8 +361,11 @@ if (passphrase[0] == 0) // \x8B\xF3\x83p\x83X\x83\x8F\x81[\x83h\x82̏ꍇ passphrase = NULL; - if (load_and_convert_putty_keyfile(filename, passphrase, newfile) < 0) + + if (putty_key && load_and_convert_putty_keyfile(filename, passphrase, newfile) < 0) goto error; + if (sshcom_key && load_and_convert_sshcom_keyfile(filename, passphrase, newfile) < 0) + goto error; ret = 0; error: @@ -389,7 +398,7 @@ // PuTTY\x8C`\x8E\xAE\x82̌\xAE\x83t\x83@\x83C\x83\x8B\x82\xA9\x82ǂ\xA4\x82\xA9\x82\xF0\x83`\x83F\x83b\x83N\x82\xB7\x82\xE9\x81B puttyfile[0] = 0; - if (import_putty_keyfile(filename, passphrase, puttyfile, sizeof(puttyfile)) == 0) { + if (import_not_openssh_keyfile(filename, passphrase, puttyfile, sizeof(puttyfile)) == 0) { strncpy_s(filename, sizeof(filename), puttyfile, _TRUNCATE); }