| 1 |
/* |
| 2 |
* Copyright (c) 1998-2001, Robert O'Callahan |
| 3 |
* (C) 2004- TeraTerm Project |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* |
| 10 |
* 1. Redistributions of source code must retain the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer. |
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
* documentation and/or other materials provided with the distribution. |
| 15 |
* 3. The name of the author may not be used to endorse or promote products |
| 16 |
* derived from this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 19 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
*/ |
| 29 |
|
| 30 |
/* |
| 31 |
This code is copyright (C) 1998-1999 Robert O'Callahan. |
| 32 |
See LICENSE.TXT for the license. |
| 33 |
*/ |
| 34 |
|
| 35 |
#ifndef __TTXSSH_H |
| 36 |
#define __TTXSSH_H |
| 37 |
|
| 38 |
#pragma warning(3 : 4035) |
| 39 |
|
| 40 |
/* VS2015(VC14.0)�����AWSASocketA(), inet_ntoa() ������API��deprecated�������� |
| 41 |
* �x�������������A�x�����}�~�����B�����������u���������AVS2005(VC8.0)���r���h |
| 42 |
* �����������������A�x�����}�~���������������B |
| 43 |
*/ |
| 44 |
#if _MSC_VER >= 1800 // VSC2013(VC12.0) or later |
| 45 |
#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS |
| 46 |
#define _WINSOCK_DEPRECATED_NO_WARNINGS |
| 47 |
#endif |
| 48 |
#endif |
| 49 |
|
| 50 |
#include <winsock2.h> |
| 51 |
#include <ws2tcpip.h> |
| 52 |
#include <wspiapi.h> |
| 53 |
/* actual body of in6addr_any and in6addr_loopback is disappeared?? */ |
| 54 |
#undef IN6_IS_ADDR_LOOPBACK |
| 55 |
#define IN6_IS_ADDR_LOOPBACK(a) \ |
| 56 |
((*(unsigned int *)(&(a)->s6_addr[0]) == 0) && \ |
| 57 |
(*(unsigned int *)(&(a)->s6_addr[4]) == 0) && \ |
| 58 |
(*(unsigned int *)(&(a)->s6_addr[8]) == 0) && \ |
| 59 |
(*(unsigned int *)(&(a)->s6_addr[12]) == ntohl(1))) |
| 60 |
/* work around for MS Platform SDK Oct 2000 */ |
| 61 |
#include <malloc.h> /* prevent of conflict stdlib.h */ |
| 62 |
#include <stdlib.h> |
| 63 |
#include <stdarg.h> |
| 64 |
#include <crtdbg.h> |
| 65 |
|
| 66 |
#include "i18n.h" |
| 67 |
#include "ttlib.h" |
| 68 |
|
| 69 |
typedef struct _TInstVar *PTInstVar; |
| 70 |
|
| 71 |
#include "util.h" |
| 72 |
#include "pkt.h" |
| 73 |
#include "ssh.h" |
| 74 |
#include "auth.h" |
| 75 |
#include "crypt.h" |
| 76 |
#include "cipher.h" |
| 77 |
#include "comp.h" |
| 78 |
#include "kex.h" |
| 79 |
#include "hostkey.h" |
| 80 |
#include "key.h" |
| 81 |
#include "hosts.h" |
| 82 |
#include "fwd.h" |
| 83 |
|
| 84 |
#include <openssl/dh.h> |
| 85 |
#include <openssl/ec.h> |
| 86 |
#include <openssl/evp.h> |
| 87 |
#include "buffer.h" |
| 88 |
|
| 89 |
/* tttypes.h �����`���������� EM �}�N���� openssl/rsa.h (OpenSSL 0.9.8)�������v���g�^�C�v������ |
| 90 |
* �������������d�����������������A�r���h�G���[�������B���L3�w�b�_��include���u�����L�����������B |
| 91 |
* (2005.7.9 yutaka) |
| 92 |
*/ |
| 93 |
#include "teraterm.h" |
| 94 |
#include "tttypes.h" |
| 95 |
#include "ttplugin.h" |
| 96 |
|
| 97 |
#if defined(_MSC_VER) && !defined(_Printf_format_string_) |
| 98 |
// ���`�������������������������������������`�������� |
| 99 |
#define _Printf_format_string_ |
| 100 |
#endif |
| 101 |
|
| 102 |
extern HANDLE hInst; /* Instance handle of TTXSSH.DLL */ |
| 103 |
|
| 104 |
#define ID_SSHSCPMENU 52110 |
| 105 |
#define ID_SSHSETUPMENU 52310 |
| 106 |
#define ID_SSHAUTHSETUPMENU 52320 |
| 107 |
#define ID_SSHFWDSETUPMENU 52330 |
| 108 |
#define ID_SSHKEYGENMENU 52340 |
| 109 |
#define ID_ABOUTMENU 52910 |
| 110 |
|
| 111 |
#define ID_SSHAUTH 62501 |
| 112 |
#define ID_SSHUNKNOWNHOST 62502 |
| 113 |
#define ID_SSHDIFFERENTKEY 62503 |
| 114 |
#define ID_SSHASYNCMESSAGEBOX 62504 |
| 115 |
#define ID_SSHDIFFERENT_TYPE_KEY 62505 |
| 116 |
|
| 117 |
#define OPTION_NONE 0 |
| 118 |
#define OPTION_CLEAR 1 |
| 119 |
#define OPTION_REPLACE 2 |
| 120 |
|
| 121 |
/* |
| 122 |
* DisablePopupMessage �p���r�b�g���` |
| 123 |
*/ |
| 124 |
#define POPUP_MSG_default 0 |
| 125 |
#define POPUP_MSG_FWD_received_data (1 << 0) |
| 126 |
#define POPUP_MSG_FWD_channel_open (1 << 1) |
| 127 |
|
| 128 |
|
| 129 |
/* |
| 130 |
* Host key rotation |
| 131 |
*/ |
| 132 |
#define SSH_UPDATE_HOSTKEYS_NO 0 |
| 133 |
#define SSH_UPDATE_HOSTKEYS_YES 1 |
| 134 |
#define SSH_UPDATE_HOSTKEYS_ASK 2 |
| 135 |
#define SSH_UPDATE_HOSTKEYS_MAX 3 |
| 136 |
|
| 137 |
/* |
| 138 |
* Server compatibility flag |
| 139 |
*/ |
| 140 |
#define SSH_BUG_DHGEX_LARGE 0x00000001 |
| 141 |
|
| 142 |
|
| 143 |
/* |
| 144 |
These are the fields that WOULD go in Tera Term's 'ts' structure, if |
| 145 |
we could put them there. |
| 146 |
*/ |
| 147 |
typedef struct _TS_SSH { |
| 148 |
BOOL Enabled; |
| 149 |
int CompressionLevel; /* 0 = NONE, else 1-9 */ |
| 150 |
|
| 151 |
int DefaultUserType; /* 0/1/2 = no input/DefaultUserName/Windows logon user */ |
| 152 |
char DefaultUserName[256]; |
| 153 |
|
| 154 |
/* this next option is a string of digits. Each digit represents a |
| 155 |
cipher. The first digit is the most preferred cipher, and so on. |
| 156 |
The digit SSH_CIPHER_NONE signifies that any ciphers after it are |
| 157 |
disabled. */ |
| 158 |
char CipherOrder[SSH_CIPHER_MAX+2]; |
| 159 |
|
| 160 |
char KnownHostsFiles[2048]; |
| 161 |
int DefaultAuthMethod; |
| 162 |
char DefaultRhostsLocalUserName[256]; |
| 163 |
char DefaultRhostsHostPrivateKeyFile[1024]; |
| 164 |
char DefaultRSAPrivateKeyFile[1024]; |
| 165 |
|
| 166 |
char DefaultForwarding[4096]; |
| 167 |
BOOL TryDefaultAuth; |
| 168 |
|
| 169 |
int LogLevel; /* 0 = NONE, 100 = Verbose */ |
| 170 |
int WriteBufferSize; |
| 171 |
|
| 172 |
int ssh_protocol_version; // SSH version (2004.10.11 yutaka) |
| 173 |
int ssh_heartbeat_overtime; // SSH heartbeat(keepalive) (2004.12.11 yutaka) |
| 174 |
// whether password will permanently store on heap memory (2006.8.5 yutaka) |
| 175 |
int remember_password; |
| 176 |
|
| 177 |
// try auth with "none" method for disable unsupported on dialog (2007.9.24 maya) |
| 178 |
BOOL CheckAuthListFirst; |
| 179 |
|
| 180 |
// Enable connection to the server that has RSA key length less than 768 bit (2008.9.11 maya) |
| 181 |
BOOL EnableRsaShortKeyServer; |
| 182 |
|
| 183 |
// Enable Agent forwarding |
| 184 |
BOOL ForwardAgent; |
| 185 |
|
| 186 |
// Confirm Agent forwarding |
| 187 |
BOOL ForwardAgentConfirm; |
| 188 |
|
| 189 |
// Confirm Agent forwarding |
| 190 |
BOOL ForwardAgentNotify; |
| 191 |
|
| 192 |
// KEX order(derived from teraterm.ini) |
| 193 |
char KexOrder[KEX_DH_MAX+1]; |
| 194 |
char HostKeyOrder[KEY_ALGO_MAX+1]; |
| 195 |
char MacOrder[HMAC_MAX+1]; |
| 196 |
char CompOrder[COMP_MAX+1]; |
| 197 |
|
| 198 |
BOOL VerifyHostKeyDNS; |
| 199 |
|
| 200 |
int IconID; |
| 201 |
|
| 202 |
int DisablePopupMessage; |
| 203 |
|
| 204 |
char X11Display[128]; |
| 205 |
|
| 206 |
int UpdateHostkeys; |
| 207 |
|
| 208 |
int GexMinimalGroupSize; |
| 209 |
|
| 210 |
int AuthBanner; |
| 211 |
|
| 212 |
BOOL KexKeyLogging; |
| 213 |
wchar_t KexKeyLogFile[1024]; |
| 214 |
|
| 215 |
// Sign algorithm order |
| 216 |
// for publickey authentication (not for server hostkey) |
| 217 |
// for RSA key only |
| 218 |
char RSAPubkeySignAlgorithmOrder[RSA_PUBKEY_SIGN_ALGO_MAX+1]; |
| 219 |
} TS_SSH; |
| 220 |
|
| 221 |
typedef struct _TInstVar { |
| 222 |
PTTSet ts; |
| 223 |
PComVar cv; |
| 224 |
|
| 225 |
/* shared memory for settings across instances. Basically it's |
| 226 |
a cache for the INI file.*/ |
| 227 |
TS_SSH *ts_SSH; |
| 228 |
|
| 229 |
int fatal_error; |
| 230 |
int showing_err; |
| 231 |
char *err_msg; |
| 232 |
|
| 233 |
Tconnect Pconnect; |
| 234 |
Trecv Precv; |
| 235 |
Tsend Psend; |
| 236 |
TWSAAsyncSelect PWSAAsyncSelect; |
| 237 |
TWSAGetLastError PWSAGetLastError; |
| 238 |
|
| 239 |
PReadIniFile ReadIniFile; |
| 240 |
PWriteIniFile WriteIniFile; |
| 241 |
PParseParam ParseParam; |
| 242 |
|
| 243 |
HMENU FileMenu; |
| 244 |
|
| 245 |
SOCKET socket; |
| 246 |
HWND NotificationWindow; |
| 247 |
unsigned int notification_msg; |
| 248 |
long notification_events; |
| 249 |
HICON OldSmallIcon; // �g�p������ |
| 250 |
HICON OldLargeIcon; // �g�p������ |
| 251 |
|
| 252 |
BOOL hostdlg_activated; |
| 253 |
BOOL hostdlg_Enabled; |
| 254 |
|
| 255 |
int protocol_major; |
| 256 |
int protocol_minor; |
| 257 |
|
| 258 |
PKTState pkt_state; |
| 259 |
SSHState ssh_state; |
| 260 |
AUTHState auth_state; |
| 261 |
CRYPTState crypt_state; |
| 262 |
HOSTSState hosts_state; |
| 263 |
FWDState fwd_state; |
| 264 |
|
| 265 |
/* The settings applied to the current session. The user may change |
| 266 |
the settings but usually we don't want that to affect the session |
| 267 |
in progress (race conditions). So user setup changes usually |
| 268 |
modify the 'settings' field below. */ |
| 269 |
TS_SSH session_settings; |
| 270 |
|
| 271 |
/* our copy of the global settings. This is synced up with the shared |
| 272 |
memory only when we do a ReadIniFile or WriteIniFile |
| 273 |
(i.e. the user loads or saves setup) */ |
| 274 |
TS_SSH settings; |
| 275 |
|
| 276 |
// SSH2 |
| 277 |
DH *kexdh; |
| 278 |
char server_version_string[128]; |
| 279 |
char client_version_string[128]; |
| 280 |
buffer_t *my_kex; |
| 281 |
buffer_t *peer_kex; |
| 282 |
kex_algorithm kex_type; // KEX algorithm |
| 283 |
ssh_keyalgo hostkey_type; |
| 284 |
const struct ssh2cipher *ciphers[MODE_MAX]; |
| 285 |
const struct SSH2Mac *macs[MODE_MAX]; |
| 286 |
compression_type ctos_compression; |
| 287 |
compression_type stoc_compression; |
| 288 |
int we_need; |
| 289 |
int kex_status; |
| 290 |
char *session_id; |
| 291 |
int session_id_len; |
| 292 |
SSHKeys ssh2_keys[MODE_MAX]; |
| 293 |
struct sshcipher_ctx *cc[MODE_MAX]; |
| 294 |
int userauth_success; |
| 295 |
int shell_id; |
| 296 |
int session_nego_status; |
| 297 |
/* |
| 298 |
unsigned int local_window; |
| 299 |
unsigned int local_window_max; |
| 300 |
unsigned int local_consumed; |
| 301 |
unsigned int local_maxpacket; |
| 302 |
unsigned int remote_window; |
| 303 |
unsigned int remote_maxpacket; |
| 304 |
*/ |
| 305 |
int client_key_bits; |
| 306 |
int server_key_bits; |
| 307 |
int kexgex_min; |
| 308 |
int kexgex_bits; |
| 309 |
int kexgex_max; |
| 310 |
int ssh2_autologin; |
| 311 |
int ask4passwd; |
| 312 |
SSHAuthMethod ssh2_authmethod; |
| 313 |
char ssh2_username[MAX_PATH]; |
| 314 |
char ssh2_password[MAX_PATH]; |
| 315 |
char ssh2_keyfile[MAX_PATH]; |
| 316 |
time_t ssh_heartbeat_tick; |
| 317 |
HANDLE ssh_heartbeat_thread; |
| 318 |
int keyboard_interactive_password_input; |
| 319 |
int userauth_retry_count; |
| 320 |
buffer_t *decomp_buffer; |
| 321 |
buffer_t *authbanner_buffer; |
| 322 |
char *ssh2_authlist; |
| 323 |
BOOL tryed_ssh2_authlist; |
| 324 |
HWND ssh_hearbeat_dialog; |
| 325 |
|
| 326 |
/* Pageant �������M�p */ |
| 327 |
unsigned char *pageant_key; |
| 328 |
unsigned char *pageant_curkey; |
| 329 |
int pageant_keylistlen; |
| 330 |
int pageant_keycount; |
| 331 |
int pageant_keycurrent; |
| 332 |
BOOL pageant_keyfinal;// SSH2 PK_OK ������������ TRUE ������ |
| 333 |
|
| 334 |
// agent forward |
| 335 |
BOOL agentfwd_enable; |
| 336 |
|
| 337 |
BOOL origDisableTCPEchoCR; |
| 338 |
|
| 339 |
BOOL nocheck_known_hosts; |
| 340 |
|
| 341 |
EC_KEY *ecdh_client_key; |
| 342 |
|
| 343 |
int dns_key_check; |
| 344 |
|
| 345 |
unsigned int server_compat_flag; |
| 346 |
|
| 347 |
void *hostkey_ctx; |
| 348 |
|
| 349 |
BOOL use_subsystem; |
| 350 |
char subsystem_name[256]; |
| 351 |
|
| 352 |
BOOL nosession; |
| 353 |
|
| 354 |
// dialog resource |
| 355 |
HFONT hFontFixed; // hosts.c�����_�C�A���O�p |
| 356 |
|
| 357 |
struct { |
| 358 |
BOOL suspended; // SCP���M���t���[�����p,TRUE������������������������ |
| 359 |
//BOOL timer_triggerd; |
| 360 |
UINT_PTR timer_id; |
| 361 |
BOOL data_finished; // TRUE������,�f�[�^�����M���������� |
| 362 |
BOOL close_request; |
| 363 |
} recv; |
| 364 |
|
| 365 |
char *server_sig_algs; |
| 366 |
|
| 367 |
char UIMsg[MAX_UIMSG]; |
| 368 |
} TInstVar; |
| 369 |
|
| 370 |
// �o�[�W���������������������X�������B ��: TTSSH_2-81_TS_data |
| 371 |
#define TTSSH_FILEMAPNAME "TTSSH_" TTSSH_VERSION_STR("-") "_TS_data" |
| 372 |
|
| 373 |
#define LOG_LEVEL_FATAL 5 |
| 374 |
#define LOG_LEVEL_ERROR 10 |
| 375 |
#define LOG_LEVEL_WARNING 30 |
| 376 |
#define LOG_LEVEL_NOTICE 50 |
| 377 |
#define LOG_LEVEL_INFO 80 |
| 378 |
#define LOG_LEVEL_VERBOSE 100 |
| 379 |
#define LOG_LEVEL_SSHDUMP 200 |
| 380 |
|
| 381 |
#define SSHv1(pvar) ((pvar)->protocol_major == 1) |
| 382 |
#define SSHv2(pvar) ((pvar)->protocol_major == 2) |
| 383 |
|
| 384 |
#define LogLevel(pvar, level) ((pvar)->settings.LogLevel >= (level)) |
| 385 |
|
| 386 |
void notify_established_secure_connection(PTInstVar pvar); |
| 387 |
void notify_closed_connection(PTInstVar pvar, char *send_msg); |
| 388 |
void notify_nonfatal_error(PTInstVar pvar, char *msg); |
| 389 |
void notify_fatal_error(PTInstVar pvar, char *msg, BOOL send_disconnect); |
| 390 |
void logputs(int level, char *msg); |
| 391 |
#if defined(_MSC_VER) |
| 392 |
void logprintf(int level, _Printf_format_string_ const char *fmt, ...); |
| 393 |
void logprintf_hexdump(int level, const char *data, int len, _Printf_format_string_ const char *fmt, ...); |
| 394 |
#elif defined(__GNUC__) |
| 395 |
void logprintf(int level, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); |
| 396 |
void logprintf_hexdump(int level, const char *data, int len, const char *fmt, ...) __attribute__ ((format (printf, 4, 5))); |
| 397 |
#else |
| 398 |
void logprintf(int level, const char *fmt, ...); |
| 399 |
void logprintf_hexdump(int level, const char *data, int len, const char *fmt, ...); |
| 400 |
#endif |
| 401 |
|
| 402 |
void get_teraterm_dir_relative_name(char *buf, int bufsize, char *basename); |
| 403 |
wchar_t *get_teraterm_dir_relative_nameW(const wchar_t *basename); |
| 404 |
int copy_teraterm_dir_relative_path(char *dest, int destsize, char *basename); |
| 405 |
wchar_t *get_home_dir_relative_nameW(const wchar_t *basename); |
| 406 |
wchar_t *get_log_dir_relative_nameW(const wchar_t *basename); |
| 407 |
int uuencode(unsigned char *src, int srclen, unsigned char *target, int targsize); |
| 408 |
|
| 409 |
#endif |