| 1 |
maya |
3227 |
/* |
| 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 |
|
|
#ifndef NO_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 /* NO_INET6 */ |
| 52 |
|
|
#include <stdlib.h> |
| 53 |
|
|
#include <crtdbg.h> |
| 54 |
|
|
|
| 55 |
|
|
#include "i18n.h" |
| 56 |
maya |
3295 |
#include "ttlib.h" |
| 57 |
maya |
3227 |
|
| 58 |
|
|
typedef struct _TInstVar FAR * PTInstVar; |
| 59 |
|
|
|
| 60 |
|
|
#include "util.h" |
| 61 |
|
|
#include "pkt.h" |
| 62 |
|
|
#include "ssh.h" |
| 63 |
|
|
#include "auth.h" |
| 64 |
|
|
#include "crypt.h" |
| 65 |
|
|
#include "hosts.h" |
| 66 |
|
|
#include "fwd.h" |
| 67 |
|
|
|
| 68 |
|
|
#include <openssl/dh.h> |
| 69 |
maya |
4314 |
#include <openssl/ec.h> |
| 70 |
maya |
3227 |
#include <openssl/evp.h> |
| 71 |
|
|
#include "buffer.h" |
| 72 |
|
|
|
| 73 |
|
|
/* tttypes.h �����`���������� EM �}�N���� openssl/rsa.h (OpenSSL 0.9.8)�������v���g�^�C�v������ |
| 74 |
|
|
* �������������d�����������������A�r���h�G���[�������B���L3�w�b�_��include���u�����L�����������B |
| 75 |
|
|
* (2005.7.9 yutaka) |
| 76 |
|
|
*/ |
| 77 |
|
|
#include "teraterm.h" |
| 78 |
|
|
#include "tttypes.h" |
| 79 |
|
|
#include "ttplugin.h" |
| 80 |
|
|
|
| 81 |
|
|
HANDLE hInst; /* Instance handle of TTXSSH.DLL */ |
| 82 |
|
|
|
| 83 |
|
|
#define ID_SSHSCPMENU 52110 |
| 84 |
|
|
#define ID_SSHSETUPMENU 52310 |
| 85 |
|
|
#define ID_SSHAUTHSETUPMENU 52320 |
| 86 |
|
|
#define ID_SSHFWDSETUPMENU 52330 |
| 87 |
|
|
#define ID_SSHKEYGENMENU 52340 |
| 88 |
|
|
#define ID_ABOUTMENU 52910 |
| 89 |
|
|
|
| 90 |
|
|
#define ID_SSHAUTH 62501 |
| 91 |
|
|
#define ID_SSHUNKNOWNHOST 62502 |
| 92 |
maya |
4330 |
#define ID_SSHDIFFERENTKEY 62503 |
| 93 |
maya |
3227 |
#define ID_SSHASYNCMESSAGEBOX 62504 |
| 94 |
|
|
|
| 95 |
|
|
#define OPTION_NONE 0 |
| 96 |
|
|
#define OPTION_CLEAR 1 |
| 97 |
|
|
#define OPTION_REPLACE 2 |
| 98 |
|
|
|
| 99 |
|
|
/* |
| 100 |
yutakapon |
5620 |
* DisablePopupMessage �p���r�b�g���` |
| 101 |
|
|
*/ |
| 102 |
|
|
#define POPUP_MSG_default 0 |
| 103 |
|
|
#define POPUP_MSG_FWD_received_data (1 << 0) |
| 104 |
|
|
|
| 105 |
|
|
/* |
| 106 |
maya |
3227 |
These are the fields that WOULD go in Tera Term's 'ts' structure, if |
| 107 |
|
|
we could put them there. |
| 108 |
|
|
*/ |
| 109 |
|
|
typedef struct _TS_SSH { |
| 110 |
|
|
BOOL Enabled; |
| 111 |
|
|
int CompressionLevel; /* 0 = NONE, else 1-9 */ |
| 112 |
|
|
char DefaultUserName[256]; |
| 113 |
|
|
|
| 114 |
|
|
/* this next option is a string of digits. Each digit represents a |
| 115 |
|
|
cipher. The first digit is the most preferred cipher, and so on. |
| 116 |
|
|
The digit SSH_CIPHER_NONE signifies that any ciphers after it are |
| 117 |
|
|
disabled. */ |
| 118 |
|
|
char CipherOrder[SSH_CIPHER_MAX+1]; |
| 119 |
|
|
|
| 120 |
|
|
char KnownHostsFiles[2048]; |
| 121 |
|
|
int DefaultAuthMethod; |
| 122 |
|
|
char DefaultRhostsLocalUserName[256]; |
| 123 |
|
|
char DefaultRhostsHostPrivateKeyFile[1024]; |
| 124 |
|
|
char DefaultRSAPrivateKeyFile[1024]; |
| 125 |
|
|
|
| 126 |
|
|
char DefaultForwarding[2048]; |
| 127 |
|
|
BOOL TryDefaultAuth; |
| 128 |
|
|
|
| 129 |
|
|
int LogLevel; /* 0 = NONE, 100 = Verbose */ |
| 130 |
|
|
int WriteBufferSize; |
| 131 |
|
|
|
| 132 |
|
|
int ssh_protocol_version; // SSH version (2004.10.11 yutaka) |
| 133 |
|
|
int ssh_heartbeat_overtime; // SSH heartbeat(keepalive) (2004.12.11 yutaka) |
| 134 |
|
|
// whether password will permanently store on heap memory (2006.8.5 yutaka) |
| 135 |
|
|
int remember_password; |
| 136 |
|
|
|
| 137 |
|
|
// try auth with "none" method for disable unsupported on dialog (2007.9.24 maya) |
| 138 |
|
|
BOOL CheckAuthListFirst; |
| 139 |
|
|
|
| 140 |
|
|
// Enable connection to the server that has RSA key length less than 768 bit (2008.9.11 maya) |
| 141 |
|
|
BOOL EnableRsaShortKeyServer; |
| 142 |
|
|
|
| 143 |
|
|
// Enable Agent forwarding |
| 144 |
|
|
BOOL ForwardAgent; |
| 145 |
maya |
4229 |
|
| 146 |
|
|
// Confirm Agent forwarding |
| 147 |
|
|
BOOL ForwardAgentConfirm; |
| 148 |
yutakapon |
4367 |
|
| 149 |
|
|
// KEX order(derived from teraterm.ini) |
| 150 |
|
|
char KexOrder[KEX_DH_MAX+1]; |
| 151 |
|
|
char HostKeyOrder[KEY_MAX+1]; |
| 152 |
|
|
char MacOrder[HMAC_MAX+1]; |
| 153 |
|
|
char CompOrder[COMP_MAX+1]; |
| 154 |
doda |
4531 |
|
| 155 |
|
|
BOOL VerifyHostKeyDNS; |
| 156 |
doda |
5261 |
|
| 157 |
|
|
int IconID; |
| 158 |
yutakapon |
5620 |
|
| 159 |
|
|
int DisablePopupMessage; |
| 160 |
doda |
5793 |
|
| 161 |
|
|
char X11Display[128]; |
| 162 |
maya |
3227 |
} TS_SSH; |
| 163 |
|
|
|
| 164 |
|
|
typedef struct _TInstVar { |
| 165 |
|
|
PTTSet ts; |
| 166 |
|
|
PComVar cv; |
| 167 |
|
|
|
| 168 |
|
|
/* shared memory for settings across instances. Basically it's |
| 169 |
|
|
a cache for the INI file.*/ |
| 170 |
|
|
TS_SSH FAR * ts_SSH; |
| 171 |
|
|
|
| 172 |
|
|
int fatal_error; |
| 173 |
|
|
int showing_err; |
| 174 |
|
|
char FAR * err_msg; |
| 175 |
|
|
|
| 176 |
|
|
Tconnect Pconnect; |
| 177 |
|
|
Trecv Precv; |
| 178 |
|
|
Tsend Psend; |
| 179 |
|
|
TWSAAsyncSelect PWSAAsyncSelect; |
| 180 |
|
|
TWSAGetLastError PWSAGetLastError; |
| 181 |
|
|
|
| 182 |
|
|
PReadIniFile ReadIniFile; |
| 183 |
|
|
PWriteIniFile WriteIniFile; |
| 184 |
|
|
PParseParam ParseParam; |
| 185 |
|
|
|
| 186 |
doda |
4463 |
HMENU FileMenu; |
| 187 |
|
|
|
| 188 |
maya |
3227 |
SOCKET socket; |
| 189 |
|
|
HWND NotificationWindow; |
| 190 |
|
|
unsigned int notification_msg; |
| 191 |
|
|
long notification_events; |
| 192 |
|
|
HICON OldSmallIcon; |
| 193 |
|
|
HICON OldLargeIcon; |
| 194 |
|
|
|
| 195 |
|
|
BOOL hostdlg_activated; |
| 196 |
|
|
BOOL hostdlg_Enabled; |
| 197 |
|
|
|
| 198 |
|
|
int protocol_major; |
| 199 |
|
|
int protocol_minor; |
| 200 |
|
|
|
| 201 |
|
|
PKTState pkt_state; |
| 202 |
|
|
SSHState ssh_state; |
| 203 |
|
|
AUTHState auth_state; |
| 204 |
|
|
CRYPTState crypt_state; |
| 205 |
|
|
HOSTSState hosts_state; |
| 206 |
|
|
FWDState fwd_state; |
| 207 |
|
|
|
| 208 |
|
|
/* The settings applied to the current session. The user may change |
| 209 |
|
|
the settings but usually we don't want that to affect the session |
| 210 |
|
|
in progress (race conditions). So user setup changes usually |
| 211 |
|
|
modify the 'settings' field below. */ |
| 212 |
|
|
TS_SSH session_settings; |
| 213 |
|
|
|
| 214 |
|
|
/* our copy of the global settings. This is synced up with the shared |
| 215 |
|
|
memory only when we do a ReadIniFile or WriteIniFile |
| 216 |
|
|
(i.e. the user loads or saves setup) */ |
| 217 |
|
|
TS_SSH settings; |
| 218 |
|
|
|
| 219 |
|
|
// SSH2 |
| 220 |
|
|
DH *kexdh; |
| 221 |
|
|
char server_version_string[128]; |
| 222 |
|
|
char client_version_string[128]; |
| 223 |
|
|
buffer_t *my_kex; |
| 224 |
|
|
buffer_t *peer_kex; |
| 225 |
maya |
4378 |
kex_algorithm kex_type; // KEX algorithm |
| 226 |
|
|
ssh_keytype hostkey_type; |
| 227 |
maya |
3227 |
SSHCipher ctos_cipher; |
| 228 |
|
|
SSHCipher stoc_cipher; |
| 229 |
maya |
4378 |
hmac_type ctos_hmac; |
| 230 |
|
|
hmac_type stoc_hmac; |
| 231 |
|
|
compression_type ctos_compression; |
| 232 |
|
|
compression_type stoc_compression; |
| 233 |
maya |
3227 |
int we_need; |
| 234 |
|
|
int key_done; |
| 235 |
|
|
int rekeying; |
| 236 |
|
|
char *session_id; |
| 237 |
|
|
int session_id_len; |
| 238 |
|
|
Newkeys ssh2_keys[MODE_MAX]; |
| 239 |
|
|
EVP_CIPHER_CTX evpcip[MODE_MAX]; |
| 240 |
|
|
int userauth_success; |
| 241 |
|
|
int shell_id; |
| 242 |
|
|
/*int remote_id;*/ |
| 243 |
|
|
int session_nego_status; |
| 244 |
|
|
/* |
| 245 |
|
|
unsigned int local_window; |
| 246 |
|
|
unsigned int local_window_max; |
| 247 |
|
|
unsigned int local_consumed; |
| 248 |
|
|
unsigned int local_maxpacket; |
| 249 |
|
|
unsigned int remote_window; |
| 250 |
|
|
unsigned int remote_maxpacket; |
| 251 |
|
|
*/ |
| 252 |
|
|
int client_key_bits; |
| 253 |
|
|
int server_key_bits; |
| 254 |
|
|
int kexgex_min; |
| 255 |
|
|
int kexgex_bits; |
| 256 |
|
|
int kexgex_max; |
| 257 |
|
|
int ssh2_autologin; |
| 258 |
|
|
int ask4passwd; |
| 259 |
|
|
SSHAuthMethod ssh2_authmethod; |
| 260 |
|
|
char ssh2_username[MAX_PATH]; |
| 261 |
|
|
char ssh2_password[MAX_PATH]; |
| 262 |
|
|
char ssh2_keyfile[MAX_PATH]; |
| 263 |
|
|
time_t ssh_heartbeat_tick; |
| 264 |
|
|
HANDLE ssh_heartbeat_thread; |
| 265 |
|
|
int keyboard_interactive_password_input; |
| 266 |
|
|
int userauth_retry_count; |
| 267 |
|
|
buffer_t *decomp_buffer; |
| 268 |
|
|
char *ssh2_authlist; |
| 269 |
|
|
BOOL tryed_ssh2_authlist; |
| 270 |
|
|
HWND ssh_hearbeat_dialog; |
| 271 |
|
|
|
| 272 |
|
|
/* Pageant �������M�p */ |
| 273 |
|
|
unsigned char *pageant_key; |
| 274 |
|
|
unsigned char *pageant_curkey; |
| 275 |
|
|
int pageant_keylistlen; |
| 276 |
|
|
int pageant_keycount; |
| 277 |
|
|
int pageant_keycurrent; |
| 278 |
|
|
BOOL pageant_keyfinal;// SSH2 PK_OK ������������ TRUE ������ |
| 279 |
|
|
|
| 280 |
|
|
// agent forward |
| 281 |
|
|
BOOL agentfwd_enable; |
| 282 |
doda |
3579 |
|
| 283 |
|
|
BOOL origDisableTCPEchoCR; |
| 284 |
yutakapon |
3631 |
|
| 285 |
|
|
BOOL nocheck_known_hosts; |
| 286 |
maya |
4314 |
|
| 287 |
|
|
EC_KEY *ecdh_client_key; |
| 288 |
doda |
4559 |
|
| 289 |
|
|
int dns_key_check; |
| 290 |
maya |
3227 |
} TInstVar; |
| 291 |
|
|
|
| 292 |
|
|
#define LOG_LEVEL_FATAL 5 |
| 293 |
|
|
#define LOG_LEVEL_ERROR 10 |
| 294 |
|
|
#define LOG_LEVEL_URGENT 20 |
| 295 |
|
|
#define LOG_LEVEL_WARNING 30 |
| 296 |
|
|
#define LOG_LEVEL_VERBOSE 100 |
| 297 |
|
|
#define LOG_LEVEL_SSHDUMP 200 |
| 298 |
|
|
|
| 299 |
|
|
#define SSHv1(pvar) ((pvar)->protocol_major == 1) |
| 300 |
|
|
#define SSHv2(pvar) ((pvar)->protocol_major == 2) |
| 301 |
|
|
|
| 302 |
|
|
void notify_established_secure_connection(PTInstVar pvar); |
| 303 |
maya |
5678 |
void notify_closed_connection(PTInstVar pvar, char FAR * send_msg); |
| 304 |
maya |
3227 |
void notify_nonfatal_error(PTInstVar pvar, char FAR * msg); |
| 305 |
maya |
5678 |
void notify_fatal_error(PTInstVar pvar, char FAR * msg, BOOL send_disconnect); |
| 306 |
maya |
3227 |
void notify_verbose_message(PTInstVar pvar, char FAR * msg, int level); |
| 307 |
|
|
|
| 308 |
|
|
void get_teraterm_dir_relative_name(char FAR * buf, int bufsize, char FAR * basename); |
| 309 |
|
|
int copy_teraterm_dir_relative_path(char FAR * dest, int destsize, char FAR * basename); |
| 310 |
|
|
void get_file_version(char *exefile, int *major, int *minor, int *release, int *build); |
| 311 |
|
|
int uuencode(unsigned char *src, int srclen, unsigned char *target, int targsize); |
| 312 |
yutakapon |
5545 |
void arc4random_buf(void *_buf, size_t n); |
| 313 |
maya |
3227 |
|
| 314 |
|
|
#endif |