Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ttxsshの鍵ファイル名にUnicodeを使用できるようにする #180

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/en/html/about/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -3485,6 +3485,7 @@ <h3 id="ttssh_3.3">YYYY.MM.DD (Ver 3.3 not released yet)</h3>
<li>Misc
<ul>
<li>If option(<a href="../commandline/ttssh.html#f">/f</a>, <a href="../commandline/ttssh.html#ssh-f">/ssh-f</a>, <a href="../commandline/ttssh.html#ssh-consume">/ssh-consume</a>, <a href="../commandline/ttssh.html#keyfile">/keyfile</a>) argument file name is not absolute path, modify it to be treated as a relative path from %APPDATA%\teraterm5\.</li>
<li>Modified private key file name can use Unicode</li>
</ul>
</li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions doc/ja/html/about/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -3481,6 +3481,7 @@ <h3 id="ttssh_3.3">YYYY.MM.DD (Ver 3.3 not released yet)</h3>
<li>�ύX
<ul>
<li>�I�v�V����(<a href="../commandline/ttssh.html#f">/f</a>, <a href="../commandline/ttssh.html#ssh-f">/ssh-f</a>, <a href="../commandline/ttssh.html#ssh-consume">/ssh-consume</a>, <a href="../commandline/ttssh.html#keyfile">/keyfile</a>)�̃t�@�C��������΃p�X�łȂ��Ƃ��́A%APPDATA%\teraterm5\ ����̑��΃p�X�Ƃ��Ĉ����悤�ɕύX�����B</li>
<li>�閧���t�@�C������Unicode���g�p�ł���悤�C������</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他の行と揃えるために文末に句点「。」を補うと良いと思います。
ただし、このファイルは改版履歴なので、リリース前にまとめて見直し・修正を行うということにしてマージを進めても良いと思います。
(この書き込みは review のテストを兼ねています)

</ul>
</li>

Expand Down
77 changes: 38 additions & 39 deletions ttssh2/ttxssh/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ static void init_auth_dlg(PTInstVar pvar, HWND dlg, BOOL *UseControlChar)
}
}

SetDlgItemText(dlg, IDC_RSAFILENAME,
pvar->session_settings.DefaultRSAPrivateKeyFile);
SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
SetDlgItemTextW(dlg, IDC_RSAFILENAME,
pvar->session_settings.DefaultRSAPrivateKeyFile);
SetDlgItemTextW(dlg, IDC_HOSTRSAFILENAME,
pvar->session_settings.DefaultRhostsHostPrivateKeyFile);
SetDlgItemText(dlg, IDC_LOCALUSERNAME,
pvar->session_settings.DefaultRhostsLocalUserName);
Expand All @@ -393,7 +393,7 @@ static void init_auth_dlg(PTInstVar pvar, HWND dlg, BOOL *UseControlChar)
} else if (pvar->ssh2_authmethod == SSH_AUTH_RSA) {
CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSERSA);

SetDlgItemText(dlg, IDC_RSAFILENAME, pvar->ssh2_keyfile);
SetDlgItemTextW(dlg, IDC_RSAFILENAME, pvar->ssh2_keyfile);
if (pvar->ssh2_autologin == 1) {
EnableWindow(GetDlgItem(dlg, IDC_CHOOSERSAFILE), FALSE);
EnableWindow(GetDlgItem(dlg, IDC_RSAFILENAME), FALSE);
Expand Down Expand Up @@ -457,7 +457,12 @@ static char *alloc_control_text(HWND ctl)
return textA;
}

static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar)
/**
* �t�@�C������Ԃ�
* @retval �t�@�C����(�s�v�ɂȂ�����free()���邱��)
* @retval NULL �L�����Z���������ꂽ
*/
static wchar_t *get_key_file_name(HWND parent, const wchar_t *UILanguageFileW)
{
static const wchar_t *fullname_def = L"identity";
static const wchar_t *filter_def =
Expand All @@ -471,7 +476,6 @@ static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar
L"PEM files(*.pem)\\0*.pem\\0"
L"all(*.*)\\0*.*\\0"
L"\\0";
const wchar_t *UILanguageFileW = pvar->ts->UILanguageFileW;
TTOPENFILENAMEW params;
wchar_t *filter;
wchar_t *title;
Expand All @@ -497,33 +501,32 @@ static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar
free(filter);
free(title);
if (r == FALSE) {
buf[0] = 0;
return 0;
return NULL;
}
else {
char *fullnameA = ToCharW(fullnameW);
copy_teraterm_dir_relative_path(buf, bufsize, fullnameA);
free(fullnameA);
free(fullnameW);
return 1;
return fullnameW;
}
}

static void choose_RSA_key_file(HWND dlg, PTInstVar pvar)
{
char buf[1024];
wchar_t *filename;

if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
SetDlgItemText(dlg, IDC_RSAFILENAME, buf);
filename = get_key_file_name(dlg, pvar->ts->UILanguageFileW);
if (filename != NULL) {
SetDlgItemTextW(dlg, IDC_RSAFILENAME, filename);
free(filename);
}
}

static void choose_host_RSA_key_file(HWND dlg, PTInstVar pvar)
{
char buf[1024];
wchar_t *filename;

if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, buf);
filename = get_key_file_name(dlg, pvar->ts->UILanguageFileW);
if (filename != NULL) {
SetDlgItemTextW(dlg, IDC_HOSTRSAFILENAME, filename);
free(filename);
}
}

Expand All @@ -549,12 +552,12 @@ static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg)
}

if (method == SSH_AUTH_RSA || method == SSH_AUTH_RHOSTS_RSA) {
char keyfile[2048];
wchar_t keyfile[2048];
int file_ctl_ID =
method == SSH_AUTH_RSA ? IDC_RSAFILENAME : IDC_HOSTRSAFILENAME;

keyfile[0] = 0;
GetDlgItemText(dlg, file_ctl_ID, keyfile, sizeof(keyfile));
GetDlgItemTextW(dlg, file_ctl_ID, keyfile, _countof(keyfile));
if (keyfile[0] == 0) {
UTIL_get_lang_msg("MSG_KEYSPECIFY_ERROR", pvar,
"You must specify a file containing the RSA/DSA/ECDSA/ED25519 private key.");
Expand Down Expand Up @@ -760,14 +763,12 @@ static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg)
}
pvar->auth_state.auth_dialog = NULL;

GetDlgItemText(dlg, IDC_RSAFILENAME,
pvar->session_settings.DefaultRSAPrivateKeyFile,
sizeof(pvar->session_settings.
DefaultRSAPrivateKeyFile));
GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
pvar->session_settings.DefaultRhostsHostPrivateKeyFile,
sizeof(pvar->session_settings.
DefaultRhostsHostPrivateKeyFile));
GetDlgItemTextW(dlg, IDC_RSAFILENAME,
pvar->session_settings.DefaultRSAPrivateKeyFile,
_countof(pvar->session_settings.DefaultRSAPrivateKeyFile));
GetDlgItemTextW(dlg, IDC_HOSTRSAFILENAME,
pvar->session_settings.DefaultRhostsHostPrivateKeyFile,
_countof(pvar->session_settings.DefaultRhostsHostPrivateKeyFile));
GetDlgItemText(dlg, IDC_LOCALUSERNAME,
pvar->session_settings.DefaultRhostsLocalUserName,
sizeof(pvar->session_settings.
Expand Down Expand Up @@ -1528,10 +1529,8 @@ static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
}

SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName);
SetDlgItemText(dlg, IDC_RSAFILENAME,
pvar->settings.DefaultRSAPrivateKeyFile);
SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
pvar->settings.DefaultRhostsHostPrivateKeyFile);
SetDlgItemTextW(dlg, IDC_RSAFILENAME, pvar->settings.DefaultRSAPrivateKeyFile);
SetDlgItemTextW(dlg, IDC_HOSTRSAFILENAME, pvar->settings.DefaultRhostsHostPrivateKeyFile);
SetDlgItemText(dlg, IDC_LOCALUSERNAME,
pvar->settings.DefaultRhostsLocalUserName);

Expand Down Expand Up @@ -1577,12 +1576,12 @@ static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)

GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName,
sizeof(pvar->settings.DefaultUserName));
GetDlgItemText(dlg, IDC_RSAFILENAME,
pvar->settings.DefaultRSAPrivateKeyFile,
sizeof(pvar->settings.DefaultRSAPrivateKeyFile));
GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
pvar->settings.DefaultRhostsHostPrivateKeyFile,
sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
GetDlgItemTextW(dlg, IDC_RSAFILENAME,
pvar->settings.DefaultRSAPrivateKeyFile,
_countof(pvar->settings.DefaultRSAPrivateKeyFile));
GetDlgItemTextW(dlg, IDC_HOSTRSAFILENAME,
pvar->settings.DefaultRhostsHostPrivateKeyFile,
_countof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
GetDlgItemText(dlg, IDC_LOCALUSERNAME,
pvar->settings.DefaultRhostsLocalUserName,
sizeof(pvar->settings.DefaultRhostsLocalUserName));
Expand Down
24 changes: 11 additions & 13 deletions ttssh2/ttxssh/keyfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ static BOOL normalize_key(RSA *key)
}

static RSA *read_RSA_private_key(PTInstVar pvar,
char * relative_name,
const wchar_t * relative_name,
char * passphrase,
BOOL * invalid_passphrase,
BOOL is_auto_login)
{
char filename[2048];
wchar_t *filename;
int fd;
unsigned int length, amount_read;
unsigned char *keyfile_data;
Expand All @@ -140,10 +140,10 @@ static RSA *read_RSA_private_key(PTInstVar pvar,

*invalid_passphrase = FALSE;

get_teraterm_dir_relative_name(filename, sizeof(filename),
relative_name);
filename = get_teraterm_dir_relative_nameW(relative_name);

fd = _open(filename, _O_RDONLY | _O_SEQUENTIAL | _O_BINARY);
fd = _wopen(filename, _O_RDONLY | _O_SEQUENTIAL | _O_BINARY);
free(filename);
if (fd == -1) {
if (errno == ENOENT) {
UTIL_get_lang_msg("MSG_KEYFILES_READ_ENOENT_ERROR", pvar,
Expand Down Expand Up @@ -345,7 +345,7 @@ static RSA *read_RSA_private_key(PTInstVar pvar,
}

Key *KEYFILES_read_private_key(PTInstVar pvar,
char * relative_name,
const wchar_t * relative_name,
char * passphrase,
BOOL * invalid_passphrase,
BOOL is_auto_login)
Expand Down Expand Up @@ -1802,21 +1802,19 @@ Key *read_SSH2_SECSH_private_key(PTInstVar pvar,
return (NULL);
}

ssh2_keyfile_type get_ssh2_keytype(char *relative_name,
ssh2_keyfile_type get_ssh2_keytype(const wchar_t *relative_name,
FILE **fp,
char *errmsg,
int errmsg_len) {
ssh2_keyfile_type ret = SSH2_KEYFILE_TYPE_NONE;
char filename[2048];
wchar_t *filename;
char line[200];
int i;

// ���΃p�X���΃p�X�֕ϊ�����B�������邱�Ƃɂ��A�u�h�b�g�Ŏn�܂�v�f�B���N�g����
// ����t�@�C����ǂݍ��ނ��Ƃ��ł���B(2005.2.7 yutaka)
get_teraterm_dir_relative_name(filename, sizeof(filename),
relative_name);
filename = get_teraterm_dir_relative_nameW(relative_name);

*fp = fopen(filename, "r");
*fp = _wfopen(filename, L"r");
free(filename);
if (*fp == NULL) {
strncpy_s(errmsg, errmsg_len, strerror(errno), _TRUNCATE);
return ret;
Expand Down
4 changes: 2 additions & 2 deletions ttssh2/ttxssh/keyfiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef enum {
} ssh2_keyfile_type;

Key * KEYFILES_read_private_key(PTInstVar pvar,
char * relative_name,
const wchar_t * relative_name,
char * passphrase,
BOOL * invalid_passphrase,
BOOL is_auto_login);
Expand Down Expand Up @@ -72,7 +72,7 @@ Key *read_SSH2_SECSH_private_key(PTInstVar pvar,
char *errmsg,
int errmsg_len);

ssh2_keyfile_type get_ssh2_keytype(char *relative_name,
ssh2_keyfile_type get_ssh2_keytype(const wchar_t *relative_name,
FILE **fp,
char *errmsg,
int errmsg_len);
Expand Down
Loading