| 1 |
/* |
| 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 __SSH_H |
| 35 |
#define __SSH_H |
| 36 |
|
| 37 |
#include "zlib.h" |
| 38 |
#include <openssl/evp.h> |
| 39 |
|
| 40 |
|
| 41 |
#define DEBUG_PRINT_TO_FILE(base, msg, len) { \ |
| 42 |
static int count = 0; \ |
| 43 |
debug_print(count + base, msg, len); \ |
| 44 |
count++; \ |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
// yutaka |
| 49 |
#define SSH2_USE |
| 50 |
|
| 51 |
|
| 52 |
/* Some of this code has been adapted from Ian Goldberg's Pilot SSH */ |
| 53 |
|
| 54 |
typedef enum { |
| 55 |
SSH_MSG_NONE, SSH_MSG_DISCONNECT, SSH_SMSG_PUBLIC_KEY, //2 |
| 56 |
SSH_CMSG_SESSION_KEY, SSH_CMSG_USER, SSH_CMSG_AUTH_RHOSTS, // 5 |
| 57 |
SSH_CMSG_AUTH_RSA, SSH_SMSG_AUTH_RSA_CHALLENGE, |
| 58 |
SSH_CMSG_AUTH_RSA_RESPONSE, SSH_CMSG_AUTH_PASSWORD, |
| 59 |
SSH_CMSG_REQUEST_PTY, // 10 |
| 60 |
SSH_CMSG_WINDOW_SIZE, SSH_CMSG_EXEC_SHELL, |
| 61 |
SSH_CMSG_EXEC_CMD, SSH_SMSG_SUCCESS, SSH_SMSG_FAILURE, |
| 62 |
SSH_CMSG_STDIN_DATA, SSH_SMSG_STDOUT_DATA, SSH_SMSG_STDERR_DATA, |
| 63 |
SSH_CMSG_EOF, SSH_SMSG_EXITSTATUS, |
| 64 |
SSH_MSG_CHANNEL_OPEN_CONFIRMATION, SSH_MSG_CHANNEL_OPEN_FAILURE, |
| 65 |
SSH_MSG_CHANNEL_DATA, SSH_MSG_CHANNEL_INPUT_EOF, |
| 66 |
SSH_MSG_CHANNEL_OUTPUT_CLOSED, SSH_MSG_OBSOLETED0, |
| 67 |
SSH_SMSG_X11_OPEN, SSH_CMSG_PORT_FORWARD_REQUEST, SSH_MSG_PORT_OPEN, |
| 68 |
SSH_CMSG_AGENT_REQUEST_FORWARDING, SSH_SMSG_AGENT_OPEN, |
| 69 |
SSH_MSG_IGNORE, SSH_CMSG_EXIT_CONFIRMATION, |
| 70 |
SSH_CMSG_X11_REQUEST_FORWARDING, SSH_CMSG_AUTH_RHOSTS_RSA, |
| 71 |
SSH_MSG_DEBUG, SSH_CMSG_REQUEST_COMPRESSION, |
| 72 |
SSH_CMSG_MAX_PACKET_SIZE, SSH_CMSG_AUTH_TIS, |
| 73 |
SSH_SMSG_AUTH_TIS_CHALLENGE, SSH_CMSG_AUTH_TIS_RESPONSE, |
| 74 |
SSH_CMSG_AUTH_KERBEROS, SSH_SMSG_AUTH_KERBEROS_RESPONSE |
| 75 |
} SSHMessage; |
| 76 |
|
| 77 |
typedef enum { |
| 78 |
SSH_CIPHER_NONE, SSH_CIPHER_IDEA, SSH_CIPHER_DES, SSH_CIPHER_3DES, |
| 79 |
SSH_CIPHER_TSS, SSH_CIPHER_RC4, SSH_CIPHER_BLOWFISH, |
| 80 |
// for SSH2 |
| 81 |
SSH2_CIPHER_3DES_CBC, SSH2_CIPHER_AES128_CBC, |
| 82 |
SSH2_CIPHER_AES192_CBC,SSH2_CIPHER_AES256_CBC, |
| 83 |
SSH2_CIPHER_BLOWFISH_CBC, |
| 84 |
} SSHCipher; |
| 85 |
|
| 86 |
#define SSH_CIPHER_MAX SSH2_CIPHER_BLOWFISH_CBC |
| 87 |
|
| 88 |
typedef enum { |
| 89 |
SSH_AUTH_NONE, SSH_AUTH_RHOSTS, SSH_AUTH_RSA, SSH_AUTH_PASSWORD, |
| 90 |
SSH_AUTH_RHOSTS_RSA, SSH_AUTH_TIS, SSH_AUTH_KERBEROS, |
| 91 |
SSH_AUTH_PAGEANT = 16, |
| 92 |
} SSHAuthMethod; |
| 93 |
|
| 94 |
#define SSH_AUTH_MAX SSH_AUTH_PAGEANT |
| 95 |
|
| 96 |
typedef enum { |
| 97 |
SSH_GENERIC_AUTHENTICATION, SSH_TIS_AUTHENTICATION |
| 98 |
} SSHAuthMode; |
| 99 |
|
| 100 |
#define SSH_PROTOFLAG_SCREEN_NUMBER 1 |
| 101 |
#define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2 |
| 102 |
|
| 103 |
// for SSH1 |
| 104 |
#define SSH_MAX_SEND_PACKET_SIZE 250000 |
| 105 |
|
| 106 |
// for SSH2 |
| 107 |
/* default window/packet sizes for tcp/x11-fwd-channel */ |
| 108 |
// changed CHAN_SES_WINDOW_DEFAULT from 32KB to 128KB. (2007.10.29 maya) |
| 109 |
#define CHAN_SES_PACKET_DEFAULT (32*1024) |
| 110 |
#define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT) |
| 111 |
#define CHAN_TCP_PACKET_DEFAULT (32*1024) |
| 112 |
#define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT) |
| 113 |
#if 0 // unused |
| 114 |
#define CHAN_X11_PACKET_DEFAULT (16*1024) |
| 115 |
#define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT) |
| 116 |
#endif |
| 117 |
|
| 118 |
|
| 119 |
/* SSH2 constants */ |
| 120 |
|
| 121 |
/* SSH2 messages */ |
| 122 |
#define SSH2_MSG_DISCONNECT 1 |
| 123 |
#define SSH2_MSG_IGNORE 2 |
| 124 |
#define SSH2_MSG_UNIMPLEMENTED 3 |
| 125 |
#define SSH2_MSG_DEBUG 4 |
| 126 |
#define SSH2_MSG_SERVICE_REQUEST 5 |
| 127 |
#define SSH2_MSG_SERVICE_ACCEPT 6 |
| 128 |
|
| 129 |
#define SSH2_MSG_KEXINIT 20 |
| 130 |
#define SSH2_MSG_NEWKEYS 21 |
| 131 |
|
| 132 |
#define SSH2_MSG_KEXDH_INIT 30 |
| 133 |
#define SSH2_MSG_KEXDH_REPLY 31 |
| 134 |
|
| 135 |
#define SSH2_MSG_KEX_DH_GEX_GROUP 31 |
| 136 |
#define SSH2_MSG_KEX_DH_GEX_INIT 32 |
| 137 |
#define SSH2_MSG_KEX_DH_GEX_REPLY 33 |
| 138 |
#define SSH2_MSG_KEX_DH_GEX_REQUEST 34 |
| 139 |
|
| 140 |
#define SSH2_MSG_USERAUTH_REQUEST 50 |
| 141 |
#define SSH2_MSG_USERAUTH_FAILURE 51 |
| 142 |
#define SSH2_MSG_USERAUTH_SUCCESS 52 |
| 143 |
#define SSH2_MSG_USERAUTH_BANNER 53 |
| 144 |
|
| 145 |
#define SSH2_MSG_USERAUTH_PK_OK 60 |
| 146 |
#define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60 |
| 147 |
#define SSH2_MSG_USERAUTH_INFO_REQUEST 60 |
| 148 |
#define SSH2_MSG_USERAUTH_INFO_RESPONSE 61 |
| 149 |
|
| 150 |
#define SSH2_MSG_GLOBAL_REQUEST 80 |
| 151 |
#define SSH2_MSG_REQUEST_SUCCESS 81 |
| 152 |
#define SSH2_MSG_REQUEST_FAILURE 82 |
| 153 |
#define SSH2_MSG_CHANNEL_OPEN 90 |
| 154 |
#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91 |
| 155 |
#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92 |
| 156 |
#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93 |
| 157 |
#define SSH2_MSG_CHANNEL_DATA 94 |
| 158 |
#define SSH2_MSG_CHANNEL_EXTENDED_DATA 95 |
| 159 |
#define SSH2_MSG_CHANNEL_EOF 96 |
| 160 |
#define SSH2_MSG_CHANNEL_CLOSE 97 |
| 161 |
#define SSH2_MSG_CHANNEL_REQUEST 98 |
| 162 |
#define SSH2_MSG_CHANNEL_SUCCESS 99 |
| 163 |
#define SSH2_MSG_CHANNEL_FAILURE 100 |
| 164 |
|
| 165 |
/* SSH2 miscellaneous constants */ |
| 166 |
#define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1 |
| 167 |
#define SSH2_DISCONNECT_PROTOCOL_ERROR 2 |
| 168 |
#define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED 3 |
| 169 |
#define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4 |
| 170 |
#define SSH2_DISCONNECT_MAC_ERROR 5 |
| 171 |
#define SSH2_DISCONNECT_COMPRESSION_ERROR 6 |
| 172 |
#define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE 7 |
| 173 |
#define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8 |
| 174 |
#define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9 |
| 175 |
#define SSH2_DISCONNECT_CONNECTION_LOST 10 |
| 176 |
#define SSH2_DISCONNECT_BY_APPLICATION 11 |
| 177 |
|
| 178 |
#define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED 1 |
| 179 |
#define SSH2_OPEN_CONNECT_FAILED 2 |
| 180 |
#define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE 3 |
| 181 |
#define SSH2_OPEN_RESOURCE_SHORTAGE 4 |
| 182 |
|
| 183 |
// �L�[�����A���S���Y�� |
| 184 |
#define KEX_DH1 "diffie-hellman-group1-sha1" |
| 185 |
#define KEX_DH14 "diffie-hellman-group14-sha1" |
| 186 |
#define KEX_DHGEX "diffie-hellman-group-exchange-sha1" |
| 187 |
|
| 188 |
// support of "Compression delayed" (2006.6.23 maya) |
| 189 |
enum compression_algorithm { |
| 190 |
COMP_NONE, |
| 191 |
COMP_ZLIB, |
| 192 |
COMP_DELAYED, |
| 193 |
COMP_UNKNOWN |
| 194 |
}; |
| 195 |
|
| 196 |
enum kex_exchange { |
| 197 |
KEX_DH_GRP1_SHA1, |
| 198 |
KEX_DH_GRP14_SHA1, |
| 199 |
KEX_DH_GEX_SHA1, |
| 200 |
KEX_MAX |
| 201 |
}; |
| 202 |
|
| 203 |
enum hostkey_type { |
| 204 |
KEY_RSA1, |
| 205 |
KEY_RSA, |
| 206 |
KEY_DSA, |
| 207 |
KEY_UNSPEC, |
| 208 |
}; |
| 209 |
|
| 210 |
// ���L���C���f�b�N�X�� ssh2_macs[] ���������������B |
| 211 |
enum hmac_type { |
| 212 |
HMAC_SHA1, |
| 213 |
HMAC_MD5, |
| 214 |
HMAC_UNKNOWN |
| 215 |
}; |
| 216 |
|
| 217 |
#define KEX_DEFAULT_KEX "diffie-hellman-group-exchange-sha1," \ |
| 218 |
"diffie-hellman-group14-sha1," \ |
| 219 |
"diffie-hellman-group1-sha1" |
| 220 |
#define KEX_DEFAULT_PK_ALG "ssh-rsa,ssh-dss" |
| 221 |
#define KEX_DEFAULT_ENCRYPT "aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc" |
| 222 |
#define KEX_DEFAULT_MAC "hmac-sha1,hmac-md5" |
| 223 |
// support of "Compression delayed" (2006.6.23 maya) |
| 224 |
#define KEX_DEFAULT_COMP "none,zlib@openssh.com,zlib" |
| 225 |
#define KEX_DEFAULT_LANG "" |
| 226 |
|
| 227 |
/* Minimum modulus size (n) for RSA keys. */ |
| 228 |
#define SSH_RSA_MINIMUM_MODULUS_SIZE 768 |
| 229 |
|
| 230 |
enum kex_init_proposals { |
| 231 |
PROPOSAL_KEX_ALGS, |
| 232 |
PROPOSAL_SERVER_HOST_KEY_ALGS, |
| 233 |
PROPOSAL_ENC_ALGS_CTOS, |
| 234 |
PROPOSAL_ENC_ALGS_STOC, |
| 235 |
PROPOSAL_MAC_ALGS_CTOS, |
| 236 |
PROPOSAL_MAC_ALGS_STOC, |
| 237 |
PROPOSAL_COMP_ALGS_CTOS, |
| 238 |
PROPOSAL_COMP_ALGS_STOC, |
| 239 |
PROPOSAL_LANG_CTOS, |
| 240 |
PROPOSAL_LANG_STOC, |
| 241 |
PROPOSAL_MAX |
| 242 |
}; |
| 243 |
|
| 244 |
|
| 245 |
// �N���C�A���g�����T�[�o������������ |
| 246 |
#ifdef SSH2_DEBUG |
| 247 |
static char *myproposal[PROPOSAL_MAX] = { |
| 248 |
// KEX_DEFAULT_KEX, |
| 249 |
"diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1", |
| 250 |
KEX_DEFAULT_PK_ALG, |
| 251 |
// "ssh-dss,ssh-rsa", |
| 252 |
KEX_DEFAULT_ENCRYPT, |
| 253 |
KEX_DEFAULT_ENCRYPT, |
| 254 |
"hmac-md5,hmac-sha1", |
| 255 |
"hmac-md5,hmac-sha1", |
| 256 |
// "hmac-sha1", |
| 257 |
// "hmac-sha1", |
| 258 |
// KEX_DEFAULT_MAC, |
| 259 |
// KEX_DEFAULT_MAC, |
| 260 |
KEX_DEFAULT_COMP, |
| 261 |
KEX_DEFAULT_COMP, |
| 262 |
KEX_DEFAULT_LANG, |
| 263 |
KEX_DEFAULT_LANG, |
| 264 |
}; |
| 265 |
#else |
| 266 |
static char *myproposal[PROPOSAL_MAX] = { |
| 267 |
KEX_DEFAULT_KEX, |
| 268 |
KEX_DEFAULT_PK_ALG, |
| 269 |
KEX_DEFAULT_ENCRYPT, |
| 270 |
KEX_DEFAULT_ENCRYPT, |
| 271 |
KEX_DEFAULT_MAC, |
| 272 |
KEX_DEFAULT_MAC, |
| 273 |
KEX_DEFAULT_COMP, |
| 274 |
KEX_DEFAULT_COMP, |
| 275 |
KEX_DEFAULT_LANG, |
| 276 |
KEX_DEFAULT_LANG, |
| 277 |
}; |
| 278 |
#endif |
| 279 |
|
| 280 |
|
| 281 |
typedef struct ssh2_cipher { |
| 282 |
SSHCipher cipher; |
| 283 |
char *name; |
| 284 |
int block_size; |
| 285 |
int key_len; |
| 286 |
const EVP_CIPHER *(*func)(void); |
| 287 |
} ssh2_cipher_t; |
| 288 |
|
| 289 |
static ssh2_cipher_t ssh2_ciphers[] = { |
| 290 |
{SSH2_CIPHER_3DES_CBC, "3des-cbc", 8, 24, EVP_des_ede3_cbc}, |
| 291 |
{SSH2_CIPHER_AES128_CBC, "aes128-cbc", 16, 16, EVP_aes_128_cbc}, |
| 292 |
{SSH2_CIPHER_AES192_CBC, "aes192-cbc", 16, 24, EVP_aes_192_cbc}, |
| 293 |
{SSH2_CIPHER_AES256_CBC, "aes256-cbc", 16, 32, EVP_aes_256_cbc}, |
| 294 |
{SSH2_CIPHER_BLOWFISH_CBC, "blowfish-cbc", 8, 16, EVP_bf_cbc}, |
| 295 |
{SSH_CIPHER_NONE, NULL, 0, 0, NULL}, |
| 296 |
}; |
| 297 |
|
| 298 |
|
| 299 |
typedef struct ssh2_mac { |
| 300 |
char *name; |
| 301 |
const EVP_MD *(*func)(void); |
| 302 |
int truncatebits; |
| 303 |
} ssh2_mac_t; |
| 304 |
|
| 305 |
static ssh2_mac_t ssh2_macs[] = { |
| 306 |
{"hmac-sha1", EVP_sha1, 0}, |
| 307 |
{"hmac-md5", EVP_md5, 0}, |
| 308 |
{NULL, NULL, 0}, |
| 309 |
}; |
| 310 |
|
| 311 |
static char *ssh_comp[] = { |
| 312 |
"none", |
| 313 |
"zlib", |
| 314 |
"zlib@openssh.com", |
| 315 |
}; |
| 316 |
|
| 317 |
|
| 318 |
struct Enc { |
| 319 |
u_char *key; |
| 320 |
u_char *iv; |
| 321 |
unsigned int key_len; |
| 322 |
unsigned int block_size; |
| 323 |
}; |
| 324 |
|
| 325 |
struct Mac { |
| 326 |
char *name; |
| 327 |
int enabled; |
| 328 |
const EVP_MD *md; |
| 329 |
int mac_len; |
| 330 |
u_char *key; |
| 331 |
int key_len; |
| 332 |
}; |
| 333 |
|
| 334 |
struct Comp { |
| 335 |
int type; |
| 336 |
int enabled; |
| 337 |
char *name; |
| 338 |
}; |
| 339 |
|
| 340 |
typedef struct { |
| 341 |
struct Enc enc; |
| 342 |
struct Mac mac; |
| 343 |
struct Comp comp; |
| 344 |
} Newkeys; |
| 345 |
|
| 346 |
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) |
| 347 |
|
| 348 |
enum kex_modes { |
| 349 |
MODE_IN, |
| 350 |
MODE_OUT, |
| 351 |
MODE_MAX |
| 352 |
}; |
| 353 |
|
| 354 |
|
| 355 |
// �z�X�g�L�[(SSH1, SSH2����)���f�[�^�\�� (2006.3.21 yutaka) |
| 356 |
typedef struct Key { |
| 357 |
// host key type |
| 358 |
enum hostkey_type type; |
| 359 |
// SSH2 RSA |
| 360 |
RSA *rsa; |
| 361 |
// SSH2 DSA |
| 362 |
DSA *dsa; |
| 363 |
// SSH1 RSA |
| 364 |
int bits; |
| 365 |
unsigned char *exp; |
| 366 |
unsigned char *mod; |
| 367 |
} Key; |
| 368 |
|
| 369 |
// fingerprint������ |
| 370 |
enum fp_rep { |
| 371 |
SSH_FP_HEX, |
| 372 |
SSH_FP_BUBBLEBABBLE, |
| 373 |
SSH_FP_RANDOMART |
| 374 |
}; |
| 375 |
|
| 376 |
enum scp_dir { |
| 377 |
TOLOCAL, FROMREMOTE, |
| 378 |
}; |
| 379 |
|
| 380 |
/* The packet handler returns TRUE to keep the handler in place, |
| 381 |
FALSE to remove the handler. */ |
| 382 |
typedef BOOL (* SSHPacketHandler)(PTInstVar pvar); |
| 383 |
|
| 384 |
typedef struct _SSHPacketHandlerItem SSHPacketHandlerItem; |
| 385 |
struct _SSHPacketHandlerItem { |
| 386 |
SSHPacketHandler handler; |
| 387 |
/* Circular list of handlers for given message */ |
| 388 |
SSHPacketHandlerItem FAR * next_for_message; |
| 389 |
SSHPacketHandlerItem FAR * last_for_message; |
| 390 |
/* Circular list of handlers in set */ |
| 391 |
SSHPacketHandlerItem FAR * next_in_set; |
| 392 |
int active_for_message; |
| 393 |
}; |
| 394 |
|
| 395 |
typedef struct { |
| 396 |
char FAR * hostname; |
| 397 |
|
| 398 |
int server_protocol_flags; |
| 399 |
char FAR * server_ID; |
| 400 |
|
| 401 |
/* This buffer is used to hold the outgoing data, and encrypted in-place |
| 402 |
here if necessary. */ |
| 403 |
unsigned char FAR * outbuf; |
| 404 |
long outbuflen; |
| 405 |
/* This buffer is used by the SSH protocol processing to store uncompressed |
| 406 |
packet data for compression. User data is never streamed through here; |
| 407 |
it is compressed directly from the user's buffer. */ |
| 408 |
unsigned char FAR * precompress_outbuf; |
| 409 |
long precompress_outbuflen; |
| 410 |
/* this is the length of the packet data, including the type header */ |
| 411 |
long outgoing_packet_len; |
| 412 |
|
| 413 |
/* This buffer is used by the SSH protocol processing to store decompressed |
| 414 |
packet data. User data is never streamed through here; it is decompressed |
| 415 |
directly to the user's buffer. */ |
| 416 |
unsigned char FAR * postdecompress_inbuf; |
| 417 |
long postdecompress_inbuflen; |
| 418 |
|
| 419 |
unsigned char FAR * payload; |
| 420 |
long payload_grabbed; |
| 421 |
long payloadlen; |
| 422 |
long payload_datastart; |
| 423 |
long payload_datalen; |
| 424 |
|
| 425 |
uint32 receiver_sequence_number; |
| 426 |
uint32 sender_sequence_number; |
| 427 |
|
| 428 |
z_stream compress_stream; |
| 429 |
z_stream decompress_stream; |
| 430 |
BOOL compressing; |
| 431 |
BOOL decompressing; |
| 432 |
int compression_level; |
| 433 |
|
| 434 |
SSHPacketHandlerItem FAR * packet_handlers[256]; |
| 435 |
int status_flags; |
| 436 |
|
| 437 |
int win_cols; |
| 438 |
int win_rows; |
| 439 |
|
| 440 |
unsigned short tcpport; |
| 441 |
} SSHState; |
| 442 |
|
| 443 |
#define STATUS_DONT_SEND_USER_NAME 0x01 |
| 444 |
#define STATUS_EXPECTING_COMPRESSION_RESPONSE 0x02 |
| 445 |
#define STATUS_DONT_SEND_CREDENTIALS 0x04 |
| 446 |
#define STATUS_HOST_OK 0x08 |
| 447 |
#define STATUS_INTERACTIVE 0x10 |
| 448 |
#define STATUS_IN_PARTIAL_ID_STRING 0x20 |
| 449 |
|
| 450 |
void SSH_init(PTInstVar pvar); |
| 451 |
void SSH_open(PTInstVar pvar); |
| 452 |
void SSH_notify_disconnecting(PTInstVar pvar, char FAR * reason); |
| 453 |
/* SSH_handle_server_ID returns TRUE iff a valid ID string has been |
| 454 |
received. If it returns FALSE, we need to keep looking for another |
| 455 |
ID string. */ |
| 456 |
BOOL SSH_handle_server_ID(PTInstVar pvar, char FAR * ID, int ID_len); |
| 457 |
/* SSH_handle_packet requires NO PAYLOAD on entry. |
| 458 |
'len' is the size of the packet: payload + padding (+ CRC for SSHv1) |
| 459 |
'padding' is the size of the padding. |
| 460 |
'data' points to the start of the packet data (the length field) |
| 461 |
*/ |
| 462 |
void SSH_handle_packet(PTInstVar pvar, char FAR * data, int len, int padding); |
| 463 |
void SSH_notify_win_size(PTInstVar pvar, int cols, int rows); |
| 464 |
void SSH_notify_user_name(PTInstVar pvar); |
| 465 |
void SSH_notify_cred(PTInstVar pvar); |
| 466 |
void SSH_notify_host_OK(PTInstVar pvar); |
| 467 |
void SSH_send(PTInstVar pvar, unsigned char const FAR * buf, unsigned int buflen); |
| 468 |
/* SSH_extract_payload returns number of bytes extracted */ |
| 469 |
int SSH_extract_payload(PTInstVar pvar, unsigned char FAR * dest, int len); |
| 470 |
void SSH_end(PTInstVar pvar); |
| 471 |
|
| 472 |
void SSH_get_server_ID_info(PTInstVar pvar, char FAR * dest, int len); |
| 473 |
void SSH_get_protocol_version_info(PTInstVar pvar, char FAR * dest, int len); |
| 474 |
void SSH_get_compression_info(PTInstVar pvar, char FAR * dest, int len); |
| 475 |
|
| 476 |
/* len must be <= SSH_MAX_SEND_PACKET_SIZE */ |
| 477 |
void SSH_channel_send(PTInstVar pvar, int channel_num, |
| 478 |
uint32 remote_channel_num, |
| 479 |
unsigned char FAR * buf, int len); |
| 480 |
void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num); |
| 481 |
void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num); |
| 482 |
void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num); |
| 483 |
void SSH_channel_input_eof(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num); |
| 484 |
void SSH_request_forwarding(PTInstVar pvar, int from_server_port, |
| 485 |
char FAR * to_local_host, int to_local_port); |
| 486 |
void SSH_request_X11_forwarding(PTInstVar pvar, |
| 487 |
char FAR * auth_protocol, unsigned char FAR * auth_data, int auth_data_len, int screen_num); |
| 488 |
void SSH_open_channel(PTInstVar pvar, uint32 local_channel_num, |
| 489 |
char FAR * to_remote_host, int to_remote_port, |
| 490 |
char FAR * originator, unsigned short originator_port); |
| 491 |
|
| 492 |
int SSH_start_scp(PTInstVar pvar, char *sendfile, char *dstfile); |
| 493 |
int SSH_start_scp_receive(PTInstVar pvar, char *filename); |
| 494 |
int SSH_scp_transaction(PTInstVar pvar, char *sendfile, char *dstfile, enum scp_dir direction); |
| 495 |
int SSH_sftp_transaction(PTInstVar pvar); |
| 496 |
|
| 497 |
/* auxiliary SSH2 interfaces for pkt.c */ |
| 498 |
int SSH_get_min_packet_size(PTInstVar pvar); |
| 499 |
/* data is guaranteed to be at least SSH_get_min_packet_size bytes long |
| 500 |
at least 5 bytes must be decrypted */ |
| 501 |
void SSH_predecrpyt_packet(PTInstVar pvar, char FAR * data); |
| 502 |
int SSH_get_clear_MAC_size(PTInstVar pvar); |
| 503 |
|
| 504 |
#define SSH_is_any_payload(pvar) ((pvar)->ssh_state.payload_datalen > 0) |
| 505 |
#define SSH_get_host_name(pvar) ((pvar)->ssh_state.hostname) |
| 506 |
#define SSH_get_compression_level(pvar) ((pvar)->ssh_state.compressing ? (pvar)->ts_SSH_CompressionLevel : 0) |
| 507 |
|
| 508 |
void SSH2_send_kexinit(PTInstVar pvar); |
| 509 |
BOOL do_SSH2_userauth(PTInstVar pvar); |
| 510 |
BOOL do_SSH2_authrequest(PTInstVar pvar); |
| 511 |
void debug_print(int no, char *msg, int len); |
| 512 |
int get_cipher_block_size(SSHCipher cipher); |
| 513 |
int get_cipher_key_len(SSHCipher cipher); |
| 514 |
const EVP_CIPHER* get_cipher_EVP_CIPHER(SSHCipher cipher); |
| 515 |
void ssh_heartbeat_lock_initialize(void); |
| 516 |
void ssh_heartbeat_lock_finalize(void); |
| 517 |
void ssh_heartbeat_lock(void); |
| 518 |
void ssh_heartbeat_unlock(void); |
| 519 |
void halt_ssh_heartbeat_thread(PTInstVar pvar); |
| 520 |
void ssh2_channel_free(void); |
| 521 |
BOOL handle_SSH2_userauth_inforeq(PTInstVar pvar); |
| 522 |
void SSH2_update_compression_myproposal(PTInstVar pvar); |
| 523 |
void SSH2_update_cipher_myproposal(PTInstVar pvar); |
| 524 |
|
| 525 |
enum hostkey_type get_keytype_from_name(char *name); |
| 526 |
char *get_sshname_from_key(Key *key); |
| 527 |
int key_to_blob(Key *key, char **blobp, int *lenp); |
| 528 |
Key *key_from_blob(char *data, int blen); |
| 529 |
void key_free(Key *key); |
| 530 |
RSA *duplicate_RSA(RSA *src); |
| 531 |
DSA *duplicate_DSA(DSA *src); |
| 532 |
char *key_fingerprint(Key *key, enum fp_rep dgst_rep); |
| 533 |
|
| 534 |
#endif |