| 1 |
yutakakn |
2728 |
/* |
| 2 |
|
|
Copyright (c) 1998-2001, Robert O'Callahan |
| 3 |
|
|
All rights reserved. |
| 4 |
|
|
|
| 5 |
|
|
Redistribution and use in source and binary forms, with or without modification, |
| 6 |
|
|
are permitted provided that the following conditions are met: |
| 7 |
|
|
|
| 8 |
|
|
Redistributions of source code must retain the above copyright notice, this list of |
| 9 |
|
|
conditions and the following disclaimer. |
| 10 |
|
|
|
| 11 |
|
|
Redistributions in binary form must reproduce the above copyright notice, this list |
| 12 |
|
|
of conditions and the following disclaimer in the documentation and/or other materials |
| 13 |
|
|
provided with the distribution. |
| 14 |
|
|
|
| 15 |
|
|
The name of Robert O'Callahan may not be used to endorse or promote products derived from |
| 16 |
|
|
this software without specific prior written permission. |
| 17 |
|
|
|
| 18 |
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND |
| 19 |
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 21 |
|
|
THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 |
|
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 |
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 |
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 |
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
|
|
*/ |
| 28 |
|
|
|
| 29 |
|
|
/* |
| 30 |
|
|
This code is copyright (C) 1998-1999 Robert O'Callahan. |
| 31 |
|
|
See LICENSE.TXT for the license. |
| 32 |
|
|
*/ |
| 33 |
|
|
|
| 34 |
|
|
#ifndef __TTXSSH_H |
| 35 |
|
|
#define __TTXSSH_H |
| 36 |
|
|
|
| 37 |
|
|
#pragma warning(3 : 4035) |
| 38 |
|
|
|
| 39 |
|
|
#ifdef INET6 |
| 40 |
|
|
#include <winsock2.h> |
| 41 |
|
|
#include <ws2tcpip.h> |
| 42 |
|
|
/* actual body of in6addr_any and in6addr_loopback is disappeared?? */ |
| 43 |
|
|
#undef IN6_IS_ADDR_LOOPBACK |
| 44 |
|
|
#define IN6_IS_ADDR_LOOPBACK(a) \ |
| 45 |
|
|
((*(unsigned int *)(&(a)->s6_addr[0]) == 0) && \ |
| 46 |
|
|
(*(unsigned int *)(&(a)->s6_addr[4]) == 0) && \ |
| 47 |
|
|
(*(unsigned int *)(&(a)->s6_addr[8]) == 0) && \ |
| 48 |
|
|
(*(unsigned int *)(&(a)->s6_addr[12]) == ntohl(1))) |
| 49 |
|
|
/* work around for MS Platform SDK Oct 2000 */ |
| 50 |
|
|
#include <malloc.h> /* prevent of conflict stdlib.h */ |
| 51 |
|
|
#endif /* INET6 */ |
| 52 |
|
|
#include <stdlib.h> |
| 53 |
|
|
#include <crtdbg.h> |
| 54 |
|
|
|
| 55 |
|
|
|
| 56 |
|
|
typedef struct _TInstVar FAR * PTInstVar; |
| 57 |
|
|
|
| 58 |
|
|
#include "util.h" |
| 59 |
|
|
#include "pkt.h" |
| 60 |
|
|
#include "ssh.h" |
| 61 |
|
|
#include "auth.h" |
| 62 |
|
|
#include "crypt.h" |
| 63 |
|
|
#include "hosts.h" |
| 64 |
|
|
#include "fwd.h" |
| 65 |
|
|
|
| 66 |
|
|
#include <openssl/dh.h> |
| 67 |
|
|
#include <openssl/evp.h> |
| 68 |
|
|
#include "buffer.h" |
| 69 |
|
|
|
| 70 |
yutakakn |
2831 |
/* tttypes.h �����`���������� EM �}�N���� openssl/rsa.h (OpenSSL 0.9.8)�������v���g�^�C�v������ |
| 71 |
|
|
* �������������d�����������������A�r���h�G���[�������B���L3�w�b�_��include���u�����L�����������B |
| 72 |
|
|
* (2005.7.9 yutaka) |
| 73 |
|
|
*/ |
| 74 |
|
|
#include "teraterm.h" |
| 75 |
|
|
#include "tttypes.h" |
| 76 |
|
|
#include "ttplugin.h" |
| 77 |
|
|
|
| 78 |
yutakakn |
2728 |
HANDLE hInst; /* Instance handle of TTXSSH.DLL */ |
| 79 |
|
|
|
| 80 |
|
|
#define ID_ABOUTMENU 62501 |
| 81 |
|
|
#define ID_SSHAUTH 62502 |
| 82 |
|
|
#define ID_SSHSETUPMENU 62503 |
| 83 |
|
|
#define ID_SSHUNKNOWNHOST 62504 |
| 84 |
|
|
#define ID_SSHDIFFERENTHOST 62505 |
| 85 |
|
|
#define ID_SSHAUTHSETUPMENU 62506 |
| 86 |
|
|
#define ID_SSHASYNCMESSAGEBOX 62507 |
| 87 |
|
|
#define ID_SSHFWDSETUPMENU 62508 |
| 88 |
yutakakn |
2816 |
#define ID_SSHKEYGENMENU 62509 |
| 89 |
yutakakn |
2728 |
|
| 90 |
|
|
/* |
| 91 |
|
|
These are the fields that WOULD go in Teraterm's 'ts' structure, if |
| 92 |
|
|
we could put them there. |
| 93 |
|
|
*/ |
| 94 |
|
|
typedef struct _TS_SSH { |
| 95 |
|
|
BOOL Enabled; |
| 96 |
|
|
int CompressionLevel; /* 0 = NONE, else 1-9 */ |
| 97 |
|
|
char DefaultUserName[256]; |
| 98 |
|
|
|
| 99 |
|
|
/* this next option is a string of digits. Each digit represents a |
| 100 |
|
|
cipher. The first digit is the most preferred cipher, and so on. |
| 101 |
|
|
The digit SSH_CIPHER_NONE signifies that any ciphers after it are |
| 102 |
|
|
disabled. */ |
| 103 |
|
|
char CipherOrder[16]; |
| 104 |
|
|
|
| 105 |
|
|
char KnownHostsFiles[2048]; |
| 106 |
|
|
int DefaultAuthMethod; |
| 107 |
|
|
char DefaultRhostsLocalUserName[256]; |
| 108 |
|
|
char DefaultRhostsHostPrivateKeyFile[1024]; |
| 109 |
|
|
char DefaultRSAPrivateKeyFile[1024]; |
| 110 |
|
|
|
| 111 |
|
|
char DefaultForwarding[2048]; |
| 112 |
|
|
BOOL TryDefaultAuth; |
| 113 |
|
|
|
| 114 |
|
|
int LogLevel; /* 0 = NONE, 100 = Verbose */ |
| 115 |
|
|
int WriteBufferSize; |
| 116 |
|
|
int LocalForwardingIdentityCheck; |
| 117 |
|
|
|
| 118 |
|
|
int ssh_protocol_version; // SSH version (2004.10.11 yutaka) |
| 119 |
yutakakn |
2748 |
int ssh_heartbeat_overtime; // SSH heartbeat(keepalive) (2004.12.11 yutaka) |
| 120 |
yutakakn |
2782 |
int ssh2_keyboard_interactive; // SSH2 keyboard-interactive (2005.1.23 yutaka) |
| 121 |
yutakakn |
2728 |
} TS_SSH; |
| 122 |
|
|
|
| 123 |
|
|
typedef struct _TInstVar { |
| 124 |
|
|
PTTSet ts; |
| 125 |
|
|
PComVar cv; |
| 126 |
|
|
|
| 127 |
|
|
/* shared memory for settings across instances. Basically it's |
| 128 |
|
|
a cache for the INI file.*/ |
| 129 |
|
|
TS_SSH FAR * ts_SSH; |
| 130 |
|
|
|
| 131 |
|
|
int fatal_error; |
| 132 |
|
|
int showing_err; |
| 133 |
|
|
char FAR * err_msg; |
| 134 |
|
|
|
| 135 |
|
|
Tconnect Pconnect; |
| 136 |
|
|
Trecv Precv; |
| 137 |
|
|
Tsend Psend; |
| 138 |
|
|
TWSAAsyncSelect PWSAAsyncSelect; |
| 139 |
|
|
TWSAGetLastError PWSAGetLastError; |
| 140 |
|
|
|
| 141 |
|
|
PReadIniFile ReadIniFile; |
| 142 |
|
|
PWriteIniFile WriteIniFile; |
| 143 |
|
|
PParseParam ParseParam; |
| 144 |
|
|
|
| 145 |
|
|
SOCKET socket; |
| 146 |
|
|
HWND NotificationWindow; |
| 147 |
|
|
unsigned int notification_msg; |
| 148 |
|
|
long notification_events; |
| 149 |
|
|
HICON OldSmallIcon; |
| 150 |
|
|
HICON OldLargeIcon; |
| 151 |
|
|
|
| 152 |
|
|
BOOL hostdlg_activated; |
| 153 |
|
|
BOOL hostdlg_Enabled; |
| 154 |
|
|
|
| 155 |
|
|
int protocol_major; |
| 156 |
|
|
int protocol_minor; |
| 157 |
|
|
|
| 158 |
|
|
PKTState pkt_state; |
| 159 |
|
|
SSHState ssh_state; |
| 160 |
|
|
AUTHState auth_state; |
| 161 |
|
|
CRYPTState crypt_state; |
| 162 |
|
|
HOSTSState hosts_state; |
| 163 |
|
|
FWDState fwd_state; |
| 164 |
|
|
|
| 165 |
|
|
/* The settings applied to the current session. The user may change |
| 166 |
|
|
the settings but usually we don't want that to affect the session |
| 167 |
|
|
in progress (race conditions). So user setup changes usually |
| 168 |
|
|
modify the 'settings' field below. */ |
| 169 |
|
|
TS_SSH session_settings; |
| 170 |
|
|
|
| 171 |
|
|
/* our copy of the global settings. This is synced up with the shared |
| 172 |
|
|
memory only when we do a ReadIniFile or WriteIniFile |
| 173 |
|
|
(i.e. the user loads or saves setup) */ |
| 174 |
|
|
TS_SSH settings; |
| 175 |
|
|
|
| 176 |
|
|
// SSH2 |
| 177 |
|
|
DH *kexdh; |
| 178 |
|
|
char server_version_string[128]; |
| 179 |
|
|
char client_version_string[128]; |
| 180 |
|
|
buffer_t *my_kex; |
| 181 |
|
|
buffer_t *peer_kex; |
| 182 |
|
|
enum kex_exchange kex_type; // KEX algorithm |
| 183 |
|
|
enum hostkey_type hostkey_type; |
| 184 |
|
|
SSHCipher ctos_cipher; |
| 185 |
|
|
SSHCipher stoc_cipher; |
| 186 |
yutakakn |
2757 |
enum hmac_type ctos_hmac; |
| 187 |
|
|
enum hmac_type stoc_hmac; |
| 188 |
yutakakn |
2833 |
int ctos_compression; |
| 189 |
|
|
int stoc_compression; |
| 190 |
yutakakn |
2728 |
int we_need; |
| 191 |
|
|
int key_done; |
| 192 |
|
|
int rekeying; |
| 193 |
|
|
char *session_id; |
| 194 |
|
|
int session_id_len; |
| 195 |
|
|
Newkeys ssh2_keys[MODE_MAX]; |
| 196 |
|
|
EVP_CIPHER_CTX evpcip[MODE_MAX]; |
| 197 |
|
|
int userauth_success; |
| 198 |
yutakakn |
2809 |
int shell_id; |
| 199 |
|
|
/*int remote_id;*/ |
| 200 |
yutakakn |
2728 |
int session_nego_status; |
| 201 |
yutakakn |
2809 |
/* |
| 202 |
yutakakn |
2728 |
unsigned int local_window; |
| 203 |
|
|
unsigned int local_window_max; |
| 204 |
|
|
unsigned int local_consumed; |
| 205 |
|
|
unsigned int local_maxpacket; |
| 206 |
|
|
unsigned int remote_window; |
| 207 |
|
|
unsigned int remote_maxpacket; |
| 208 |
yutakakn |
2809 |
*/ |
| 209 |
yutakakn |
2728 |
int client_key_bits; |
| 210 |
|
|
int server_key_bits; |
| 211 |
|
|
int kexgex_min; |
| 212 |
|
|
int kexgex_bits; |
| 213 |
|
|
int kexgex_max; |
| 214 |
yutakakn |
2739 |
int ssh2_autologin; |
| 215 |
yutakakn |
2784 |
SSHAuthMethod ssh2_authmethod; |
| 216 |
yutakakn |
2739 |
char ssh2_username[MAX_PATH]; |
| 217 |
|
|
char ssh2_password[MAX_PATH]; |
| 218 |
yutakakn |
2784 |
char ssh2_keyfile[MAX_PATH]; |
| 219 |
yutakakn |
2748 |
time_t ssh_heartbeat_tick; |
| 220 |
yutakakn |
2766 |
HANDLE ssh_heartbeat_thread; |
| 221 |
yutakakn |
2782 |
int keyboard_interactive_done; |
| 222 |
yutakakn |
2800 |
int keyboard_interactive_password_input; |
| 223 |
yutakakn |
2798 |
int userauth_retry_count; |
| 224 |
yutakakn |
2833 |
buffer_t *decomp_buffer; |
| 225 |
yutakakn |
2728 |
} TInstVar; |
| 226 |
|
|
|
| 227 |
|
|
#define LOG_LEVEL_FATAL 5 |
| 228 |
|
|
#define LOG_LEVEL_ERROR 10 |
| 229 |
|
|
#define LOG_LEVEL_URGENT 20 |
| 230 |
|
|
#define LOG_LEVEL_WARNING 30 |
| 231 |
|
|
#define LOG_LEVEL_VERBOSE 100 |
| 232 |
|
|
|
| 233 |
|
|
#define SSHv1(pvar) ((pvar)->protocol_major == 1) |
| 234 |
|
|
#define SSHv2(pvar) ((pvar)->protocol_major == 2) |
| 235 |
|
|
|
| 236 |
|
|
void notify_established_secure_connection(PTInstVar pvar); |
| 237 |
|
|
void notify_closed_connection(PTInstVar pvar); |
| 238 |
|
|
void notify_nonfatal_error(PTInstVar pvar, char FAR * msg); |
| 239 |
|
|
void notify_fatal_error(PTInstVar pvar, char FAR * msg); |
| 240 |
|
|
void notify_verbose_message(PTInstVar pvar, char FAR * msg, int level); |
| 241 |
|
|
|
| 242 |
|
|
void get_teraterm_dir_relative_name(char FAR * buf, int bufsize, char FAR * basename); |
| 243 |
|
|
int copy_teraterm_dir_relative_path(char FAR * dest, int destsize, char FAR * basename); |
| 244 |
yutakakn |
2793 |
void get_file_version(char *exefile, int *major, int *minor, int *release, int *build); |
| 245 |
yutakakn |
2728 |
|
| 246 |
|
|
#endif |
| 247 |
yutakakn |
2739 |
|
| 248 |
|
|
/* |
| 249 |
|
|
* $Log: not supported by cvs2svn $ |
| 250 |
yutakakn |
2833 |
* Revision 1.13 2005/07/09 05:16:06 yutakakn |
| 251 |
|
|
* OpenSSL 0.9.8���r���h�����������������B |
| 252 |
|
|
* |
| 253 |
yutakakn |
2831 |
* Revision 1.12 2005/04/23 17:26:57 yutakakn |
| 254 |
|
|
* �L�[�����_�C�A���O�������B |
| 255 |
|
|
* |
| 256 |
yutakakn |
2816 |
* Revision 1.11 2005/04/03 14:39:48 yutakakn |
| 257 |
|
|
* SSH2 channel lookup�@�\�������i�|�[�g�t�H���[�f�B���O�������j�B |
| 258 |
|
|
* TTSSH 2.10����������log dump�@�\���������ADH������������buffer free�� |
| 259 |
|
|
* �A�v���P�[�V�������������������o�O���C���B |
| 260 |
|
|
* |
| 261 |
yutakakn |
2809 |
* Revision 1.10 2005/03/12 15:07:34 yutakakn |
| 262 |
|
|
* SSH2 keyboard-interactive�F����TIS�_�C�A���O�����������B |
| 263 |
|
|
* |
| 264 |
yutakakn |
2800 |
* Revision 1.9 2005/03/10 13:40:39 yutakakn |
| 265 |
|
|
* ���������O�C���������s���������������ASSH2_MSG_SERVICE_REQUEST�����M�� |
| 266 |
|
|
* �����������������BOpenSSH�����x���������ATru64 UNIX�����T�[�o�G���[�������������������B |
| 267 |
|
|
* |
| 268 |
yutakakn |
2798 |
* Revision 1.8 2005/03/03 13:28:23 yutakakn |
| 269 |
|
|
* �N���C�A���g��SSH�o�[�W������ ttxssh.dll �������������A�T�[�o�����������������B |
| 270 |
|
|
* |
| 271 |
yutakakn |
2793 |
* Revision 1.7 2005/01/27 13:30:33 yutakakn |
| 272 |
|
|
* ���J���F���������O�C�����T�|�[�g�B |
| 273 |
|
|
* /auth=publickey, /keyfile �I�v�V�������V�K���������B |
| 274 |
|
|
* �����A�����������������T�|�[�g�B |
| 275 |
|
|
* |
| 276 |
yutakakn |
2784 |
* Revision 1.6 2005/01/24 14:07:07 yutakakn |
| 277 |
|
|
* �Ekeyboard-interactive�F�����T�|�[�g�����B |
| 278 |
|
|
* �@�����������Ateraterm.ini�� "KeyboardInteractive" �G���g�������������B |
| 279 |
|
|
* �E�o�[�W�����_�C�A���O�� OpenSSL�o�[�W���� ������ |
| 280 |
|
|
* |
| 281 |
yutakakn |
2782 |
* Revision 1.5 2004/12/27 14:05:08 yutakakn |
| 282 |
|
|
* 'Auto window close'���L���������A���f�������������������������C�������B |
| 283 |
|
|
* �@�E�X���b�h���I���������������������� |
| 284 |
|
|
* �@�E�m������SSH���\�[�X������ |
| 285 |
|
|
* |
| 286 |
yutakakn |
2766 |
* Revision 1.4 2004/12/17 14:05:55 yutakakn |
| 287 |
|
|
* �p�P�b�g���M����HMAC�`�F�b�N�������B |
| 288 |
|
|
* KEX��������HMAC�A���S���Y���`�F�b�N�������B |
| 289 |
|
|
* |
| 290 |
yutakakn |
2757 |
* Revision 1.3 2004/12/11 07:31:00 yutakakn |
| 291 |
|
|
* SSH heartbeat�X���b�h�����������B�����������AIP�}�X�J���[�h�������������A���[�^�� |
| 292 |
|
|
* NAT�e�[�u���N���A�������ASSH�R�l�N�V���������f�����������������������B |
| 293 |
|
|
* ���������������Ateraterm.ini��TTSSH�Z�N�V�������AHeartBeat �G���g���������B |
| 294 |
|
|
* |
| 295 |
yutakakn |
2748 |
* Revision 1.2 2004/12/01 15:37:49 yutakakn |
| 296 |
|
|
* SSH2�������O�C���@�\�������B |
| 297 |
|
|
* �����A�p�X���[�h�F�������������B |
| 298 |
|
|
* �E�R�}���h���C�� |
| 299 |
|
|
* /ssh /auth=�F�����\�b�h /user=���[�U�� /passwd=�p�X���[�h |
| 300 |
|
|
* |
| 301 |
yutakakn |
2739 |
*/ |