| 1 |
/* |
| 2 |
* Copyright (c) 1998-2001, Robert O'Callahan |
| 3 |
* (C) 2004-2017 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 __SSH_H |
| 36 |
#define __SSH_H |
| 37 |
|
| 38 |
#include "zlib.h" |
| 39 |
#include <openssl/evp.h> |
| 40 |
|
| 41 |
#include "buffer.h" |
| 42 |
#include "config.h" |
| 43 |
#include <sys/types.h> |
| 44 |
#include <sys/stat.h> |
| 45 |
|
| 46 |
#define DEBUG_PRINT_TO_FILE(base, msg, len) { \ |
| 47 |
static int count = 0; \ |
| 48 |
debug_print(count + base, msg, len); \ |
| 49 |
count++; \ |
| 50 |
} |
| 51 |
|
| 52 |
// from OpenSSH |
| 53 |
extern const EVP_CIPHER *evp_aes_128_ctr(void); |
| 54 |
extern const EVP_CIPHER *evp_des3_ctr(void); |
| 55 |
extern const EVP_CIPHER *evp_bf_ctr(void); |
| 56 |
extern const EVP_CIPHER *evp_cast5_ctr(void); |
| 57 |
extern const EVP_CIPHER *evp_camellia_128_ctr(void); |
| 58 |
|
| 59 |
/* Some of this code has been adapted from Ian Goldberg's Pilot SSH */ |
| 60 |
|
| 61 |
typedef enum { |
| 62 |
SSH_MSG_NONE, SSH_MSG_DISCONNECT, SSH_SMSG_PUBLIC_KEY, //2 |
| 63 |
SSH_CMSG_SESSION_KEY, SSH_CMSG_USER, SSH_CMSG_AUTH_RHOSTS, // 5 |
| 64 |
SSH_CMSG_AUTH_RSA, SSH_SMSG_AUTH_RSA_CHALLENGE, |
| 65 |
SSH_CMSG_AUTH_RSA_RESPONSE, SSH_CMSG_AUTH_PASSWORD, |
| 66 |
SSH_CMSG_REQUEST_PTY, // 10 |
| 67 |
SSH_CMSG_WINDOW_SIZE, SSH_CMSG_EXEC_SHELL, |
| 68 |
SSH_CMSG_EXEC_CMD, SSH_SMSG_SUCCESS, SSH_SMSG_FAILURE, |
| 69 |
SSH_CMSG_STDIN_DATA, SSH_SMSG_STDOUT_DATA, SSH_SMSG_STDERR_DATA, |
| 70 |
SSH_CMSG_EOF, SSH_SMSG_EXITSTATUS, |
| 71 |
SSH_MSG_CHANNEL_OPEN_CONFIRMATION, SSH_MSG_CHANNEL_OPEN_FAILURE, |
| 72 |
SSH_MSG_CHANNEL_DATA, SSH_MSG_CHANNEL_INPUT_EOF, |
| 73 |
SSH_MSG_CHANNEL_OUTPUT_CLOSED, SSH_MSG_OBSOLETED0, |
| 74 |
SSH_SMSG_X11_OPEN, SSH_CMSG_PORT_FORWARD_REQUEST, SSH_MSG_PORT_OPEN, |
| 75 |
SSH_CMSG_AGENT_REQUEST_FORWARDING, SSH_SMSG_AGENT_OPEN, |
| 76 |
SSH_MSG_IGNORE, SSH_CMSG_EXIT_CONFIRMATION, |
| 77 |
SSH_CMSG_X11_REQUEST_FORWARDING, SSH_CMSG_AUTH_RHOSTS_RSA, |
| 78 |
SSH_MSG_DEBUG, SSH_CMSG_REQUEST_COMPRESSION, |
| 79 |
SSH_CMSG_MAX_PACKET_SIZE, SSH_CMSG_AUTH_TIS, |
| 80 |
SSH_SMSG_AUTH_TIS_CHALLENGE, SSH_CMSG_AUTH_TIS_RESPONSE, |
| 81 |
SSH_CMSG_AUTH_KERBEROS, SSH_SMSG_AUTH_KERBEROS_RESPONSE |
| 82 |
} SSHMessage; |
| 83 |
|
| 84 |
typedef enum { |
| 85 |
// SSH1 |
| 86 |
SSH_CIPHER_NONE, SSH_CIPHER_IDEA, SSH_CIPHER_DES, SSH_CIPHER_3DES, |
| 87 |
SSH_CIPHER_TSS, SSH_CIPHER_RC4, SSH_CIPHER_BLOWFISH, |
| 88 |
// SSH2 |
| 89 |
SSH2_CIPHER_3DES_CBC, SSH2_CIPHER_AES128_CBC, |
| 90 |
SSH2_CIPHER_AES192_CBC, SSH2_CIPHER_AES256_CBC, |
| 91 |
SSH2_CIPHER_BLOWFISH_CBC, SSH2_CIPHER_AES128_CTR, |
| 92 |
SSH2_CIPHER_AES192_CTR, SSH2_CIPHER_AES256_CTR, |
| 93 |
SSH2_CIPHER_ARCFOUR, SSH2_CIPHER_ARCFOUR128, SSH2_CIPHER_ARCFOUR256, |
| 94 |
SSH2_CIPHER_CAST128_CBC, |
| 95 |
SSH2_CIPHER_3DES_CTR, SSH2_CIPHER_BLOWFISH_CTR, SSH2_CIPHER_CAST128_CTR, |
| 96 |
SSH2_CIPHER_CAMELLIA128_CBC, SSH2_CIPHER_CAMELLIA192_CBC, SSH2_CIPHER_CAMELLIA256_CBC, |
| 97 |
SSH2_CIPHER_CAMELLIA128_CTR, SSH2_CIPHER_CAMELLIA192_CTR, SSH2_CIPHER_CAMELLIA256_CTR, |
| 98 |
SSH2_CIPHER_AES128_GCM, SSH2_CIPHER_AES256_GCM, |
| 99 |
SSH_CIPHER_MAX = SSH2_CIPHER_AES256_GCM, |
| 100 |
} SSHCipher; |
| 101 |
|
| 102 |
typedef enum { |
| 103 |
SSH_AUTH_NONE, SSH_AUTH_RHOSTS, SSH_AUTH_RSA, SSH_AUTH_PASSWORD, |
| 104 |
SSH_AUTH_RHOSTS_RSA, SSH_AUTH_TIS, SSH_AUTH_KERBEROS, |
| 105 |
SSH_AUTH_PAGEANT = 16, |
| 106 |
SSH_AUTH_MAX = SSH_AUTH_PAGEANT, |
| 107 |
} SSHAuthMethod; |
| 108 |
|
| 109 |
typedef enum { |
| 110 |
SSH_GENERIC_AUTHENTICATION, SSH_TIS_AUTHENTICATION |
| 111 |
} SSHAuthMode; |
| 112 |
|
| 113 |
#define SSH_PROTOFLAG_SCREEN_NUMBER 1 |
| 114 |
#define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2 |
| 115 |
|
| 116 |
enum channel_type { |
| 117 |
TYPE_SHELL, TYPE_PORTFWD, TYPE_SCP, TYPE_SFTP, TYPE_AGENT, TYPE_SUBSYSTEM_GEN, |
| 118 |
}; |
| 119 |
|
| 120 |
// for SSH1 |
| 121 |
#define SSH_MAX_SEND_PACKET_SIZE 250000 |
| 122 |
|
| 123 |
// for SSH2 |
| 124 |
/* default window/packet sizes for tcp/x11-fwd-channel */ |
| 125 |
// changed CHAN_SES_WINDOW_DEFAULT from 32KB to 128KB. (2007.10.29 maya) |
| 126 |
#define CHAN_SES_PACKET_DEFAULT (32*1024) |
| 127 |
#define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT) |
| 128 |
#define CHAN_TCP_PACKET_DEFAULT (32*1024) |
| 129 |
#define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT) |
| 130 |
#if 0 // unused |
| 131 |
#define CHAN_X11_PACKET_DEFAULT (16*1024) |
| 132 |
#define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT) |
| 133 |
#endif |
| 134 |
|
| 135 |
|
| 136 |
/* SSH2 constants */ |
| 137 |
|
| 138 |
/* SSH2 messages */ |
| 139 |
typedef enum { |
| 140 |
// Transport layer protocol |
| 141 |
// 1..19 Transport layer generic (RFC 4253) |
| 142 |
SSH2_MSG_DISCONNECT = 1, |
| 143 |
SSH2_MSG_IGNORE = 2, |
| 144 |
SSH2_MSG_UNIMPLEMENTED = 3, |
| 145 |
SSH2_MSG_DEBUG = 4, |
| 146 |
SSH2_MSG_SERVICE_REQUEST = 5, |
| 147 |
SSH2_MSG_SERVICE_ACCEPT = 6, |
| 148 |
|
| 149 |
// 20..29 Algorithm negotiation (RFC 4253) |
| 150 |
SSH2_MSG_KEXINIT = 20, |
| 151 |
SSH2_MSG_NEWKEYS = 21, |
| 152 |
|
| 153 |
// 30..49 Key excahnge method specific |
| 154 |
// Diffie-Hellman Key Exchange (RFC 4253) |
| 155 |
SSH2_MSG_KEXDH_INIT = 30, |
| 156 |
SSH2_MSG_KEXDH_REPLY = 31, |
| 157 |
|
| 158 |
// RFC 4419 - Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol |
| 159 |
SSH2_MSG_KEX_DH_GEX_GROUP = 31, |
| 160 |
SSH2_MSG_KEX_DH_GEX_INIT = 32, |
| 161 |
SSH2_MSG_KEX_DH_GEX_REPLY = 33, |
| 162 |
SSH2_MSG_KEX_DH_GEX_REQUEST = 34, |
| 163 |
|
| 164 |
// RFC 5656 - Elliptic Curve Algorithm Integration in the Secure Shell Transport Layer |
| 165 |
SSH2_MSG_KEX_ECDH_INIT = 30, |
| 166 |
SSH2_MSG_KEX_ECDH_REPLY = 31, |
| 167 |
|
| 168 |
// User authentication protocol |
| 169 |
// 50..59 User authentication generic (RFC 4252) |
| 170 |
SSH2_MSG_USERAUTH_REQUEST = 50, |
| 171 |
SSH2_MSG_USERAUTH_FAILURE = 51, |
| 172 |
SSH2_MSG_USERAUTH_SUCCESS = 52, |
| 173 |
SSH2_MSG_USERAUTH_BANNER = 53, |
| 174 |
|
| 175 |
// Public key authentication (RFC 4252) |
| 176 |
SSH2_MSG_USERAUTH_PK_OK = 60, |
| 177 |
|
| 178 |
// Password authentication (RFC 4252) |
| 179 |
SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ = 60, |
| 180 |
|
| 181 |
// RFC 4256 - Generic Message Exchange Authentication for the Secure Shell Protocol (SSH) |
| 182 |
// Keyboard-interactive authentication |
| 183 |
SSH2_MSG_USERAUTH_INFO_REQUEST = 60, |
| 184 |
SSH2_MSG_USERAUTH_INFO_RESPONSE = 61, |
| 185 |
|
| 186 |
// Connection protocol |
| 187 |
// 80..89 Connection protocol generic (RFC 4254) |
| 188 |
SSH2_MSG_GLOBAL_REQUEST = 80, |
| 189 |
SSH2_MSG_REQUEST_SUCCESS = 81, |
| 190 |
SSH2_MSG_REQUEST_FAILURE = 82, |
| 191 |
|
| 192 |
// 90..127 Channel related messages (RFC 4254) |
| 193 |
SSH2_MSG_CHANNEL_OPEN = 90, |
| 194 |
SSH2_MSG_CHANNEL_OPEN_CONFIRMATION = 91, |
| 195 |
SSH2_MSG_CHANNEL_OPEN_FAILURE = 92, |
| 196 |
SSH2_MSG_CHANNEL_WINDOW_ADJUST = 93, |
| 197 |
SSH2_MSG_CHANNEL_DATA = 94, |
| 198 |
SSH2_MSG_CHANNEL_EXTENDED_DATA = 95, |
| 199 |
SSH2_MSG_CHANNEL_EOF = 96, |
| 200 |
SSH2_MSG_CHANNEL_CLOSE = 97, |
| 201 |
SSH2_MSG_CHANNEL_REQUEST = 98, |
| 202 |
SSH2_MSG_CHANNEL_SUCCESS = 99, |
| 203 |
SSH2_MSG_CHANNEL_FAILURE = 100 |
| 204 |
|
| 205 |
// Reserved for client protocols |
| 206 |
// 128..191 Reserved |
| 207 |
|
| 208 |
// Local extensions: |
| 209 |
// 192..255 Local extensions |
| 210 |
|
| 211 |
} SSH2Message; |
| 212 |
|
| 213 |
/* SSH2 miscellaneous constants */ |
| 214 |
typedef enum { |
| 215 |
SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1, |
| 216 |
SSH2_DISCONNECT_PROTOCOL_ERROR, |
| 217 |
SSH2_DISCONNECT_KEY_EXCHANGE_FAILED, |
| 218 |
SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED, |
| 219 |
SSH2_DISCONNECT_MAC_ERROR, |
| 220 |
SSH2_DISCONNECT_COMPRESSION_ERROR, |
| 221 |
SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE, |
| 222 |
SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED, |
| 223 |
SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE, |
| 224 |
SSH2_DISCONNECT_CONNECTION_LOST, |
| 225 |
SSH2_DISCONNECT_BY_APPLICATION, |
| 226 |
SSH2_DISCONNECT_TOO_MANY_CONNECTIONS, |
| 227 |
SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER, |
| 228 |
SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE, |
| 229 |
SSH2_DISCONNECT_ILLEGAL_USER_NAME |
| 230 |
} SSH2DisconnectMessage; |
| 231 |
|
| 232 |
typedef enum { |
| 233 |
SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED = 1, |
| 234 |
SSH2_OPEN_CONNECT_FAILED, |
| 235 |
SSH2_OPEN_UNKNOWN_CHANNEL_TYPE, |
| 236 |
SSH2_OPEN_RESOURCE_SHORTAGE |
| 237 |
} SSH2ChannelFailReason; |
| 238 |
|
| 239 |
// Terminal Modes |
| 240 |
typedef enum { |
| 241 |
SSH2_TTY_OP_END = 0, |
| 242 |
SSH2_TTY_KEY_VINTR = 1, |
| 243 |
SSH2_TTY_KEY_VQUIT = 2, |
| 244 |
SSH2_TTY_KEY_VERASE = 3, |
| 245 |
SSH2_TTY_KEY_VKILL = 4, |
| 246 |
SSH2_TTY_KEY_VEOF = 5, |
| 247 |
SSH2_TTY_KEY_VEOL = 6, |
| 248 |
SSH2_TTY_KEY_VEOL2 = 7, |
| 249 |
SSH2_TTY_KEY_VSTART = 8, |
| 250 |
SSH2_TTY_KEY_VSTOP = 9, |
| 251 |
SSH2_TTY_KEY_VSUSP = 10, |
| 252 |
SSH2_TTY_KEY_VDSUSP = 11, |
| 253 |
SSH2_TTY_KEY_VREPRINT = 12, |
| 254 |
SSH2_TTY_KEY_VWERASE = 13, |
| 255 |
SSH2_TTY_KEY_VLNEXT = 14, |
| 256 |
SSH2_TTY_KEY_VFLUSH = 15, |
| 257 |
SSH2_TTY_KEY_VSWTCH = 16, |
| 258 |
SSH2_TTY_KEY_VSTATUS = 17, |
| 259 |
SSH2_TTY_KEY_VDISCARD = 18, |
| 260 |
SSH2_TTY_OP_IGNPAR = 30, |
| 261 |
SSH2_TTY_OP_PARMRK = 31, |
| 262 |
SSH2_TTY_OP_INPCK = 32, |
| 263 |
SSH2_TTY_OP_ISTRIP = 33, |
| 264 |
SSH2_TTY_OP_INLCR = 34, |
| 265 |
SSH2_TTY_OP_IGNCR = 35, |
| 266 |
SSH2_TTY_OP_ICRNL = 36, |
| 267 |
SSH2_TTY_OP_IUCLC = 37, |
| 268 |
SSH2_TTY_OP_IXON = 38, |
| 269 |
SSH2_TTY_OP_IXANY = 39, |
| 270 |
SSH2_TTY_OP_IXOFF = 40, |
| 271 |
SSH2_TTY_OP_IMAXBEL = 41, |
| 272 |
SSH2_TTY_OP_ISIG = 50, |
| 273 |
SSH2_TTY_OP_ICANON = 51, |
| 274 |
SSH2_TTY_OP_XCASE = 52, |
| 275 |
SSH2_TTY_OP_ECHO = 53, |
| 276 |
SSH2_TTY_OP_ECHOE = 54, |
| 277 |
SSH2_TTY_OP_ECHOK = 55, |
| 278 |
SSH2_TTY_OP_ECHONL = 56, |
| 279 |
SSH2_TTY_OP_NOFLSH = 57, |
| 280 |
SSH2_TTY_OP_TOSTOP = 58, |
| 281 |
SSH2_TTY_OP_IEXTEN = 59, |
| 282 |
SSH2_TTY_OP_ECHOCTL = 60, |
| 283 |
SSH2_TTY_OP_ECHOKE = 61, |
| 284 |
SSH2_TTY_OP_PENDIN = 62, |
| 285 |
SSH2_TTY_OP_OPOST = 70, |
| 286 |
SSH2_TTY_OP_OLCUC = 71, |
| 287 |
SSH2_TTY_OP_ONLCR = 72, |
| 288 |
SSH2_TTY_OP_OCRNL = 73, |
| 289 |
SSH2_TTY_OP_ONOCR = 74, |
| 290 |
SSH2_TTY_OP_ONLRET = 75, |
| 291 |
SSH2_TTY_OP_CS7 = 90, |
| 292 |
SSH2_TTY_OP_CS8 = 91, |
| 293 |
SSH2_TTY_OP_PARENB = 92, |
| 294 |
SSH2_TTY_OP_PARODD = 93, |
| 295 |
SSH2_TTY_OP_ISPEED = 128, |
| 296 |
SSH2_TTY_OP_OSPEED = 129 |
| 297 |
} SSH2TTYMode; |
| 298 |
|
| 299 |
|
| 300 |
// �N���C�A���g�����T�[�o������������ |
| 301 |
enum kex_init_proposals { |
| 302 |
PROPOSAL_KEX_ALGS, |
| 303 |
PROPOSAL_SERVER_HOST_KEY_ALGS, |
| 304 |
PROPOSAL_ENC_ALGS_CTOS, |
| 305 |
PROPOSAL_ENC_ALGS_STOC, |
| 306 |
PROPOSAL_MAC_ALGS_CTOS, |
| 307 |
PROPOSAL_MAC_ALGS_STOC, |
| 308 |
PROPOSAL_COMP_ALGS_CTOS, |
| 309 |
PROPOSAL_COMP_ALGS_STOC, |
| 310 |
PROPOSAL_LANG_CTOS, |
| 311 |
PROPOSAL_LANG_STOC, |
| 312 |
PROPOSAL_MAX |
| 313 |
}; |
| 314 |
|
| 315 |
#define KEX_DEFAULT_KEX "" |
| 316 |
#define KEX_DEFAULT_PK_ALG "" |
| 317 |
#define KEX_DEFAULT_ENCRYPT "" |
| 318 |
#define KEX_DEFAULT_MAC "" |
| 319 |
#define KEX_DEFAULT_COMP "" |
| 320 |
#define KEX_DEFAULT_LANG "" |
| 321 |
|
| 322 |
static char *myproposal[PROPOSAL_MAX] = { |
| 323 |
KEX_DEFAULT_KEX, |
| 324 |
KEX_DEFAULT_PK_ALG, |
| 325 |
KEX_DEFAULT_ENCRYPT, |
| 326 |
KEX_DEFAULT_ENCRYPT, |
| 327 |
KEX_DEFAULT_MAC, |
| 328 |
KEX_DEFAULT_MAC, |
| 329 |
KEX_DEFAULT_COMP, |
| 330 |
KEX_DEFAULT_COMP, |
| 331 |
KEX_DEFAULT_LANG, |
| 332 |
KEX_DEFAULT_LANG, |
| 333 |
}; |
| 334 |
|
| 335 |
|
| 336 |
typedef enum { |
| 337 |
KEY_NONE, |
| 338 |
KEY_RSA1, |
| 339 |
KEY_RSA, |
| 340 |
KEY_DSA, |
| 341 |
KEY_ECDSA256, |
| 342 |
KEY_ECDSA384, |
| 343 |
KEY_ECDSA521, |
| 344 |
KEY_ED25519, |
| 345 |
KEY_UNSPEC, |
| 346 |
KEY_MAX = KEY_UNSPEC, |
| 347 |
} ssh_keytype; |
| 348 |
#define isFixedLengthKey(type) ((type) >= KEY_DSA && (type) <= KEY_ED25519) |
| 349 |
|
| 350 |
typedef struct ssh2_host_key { |
| 351 |
ssh_keytype type; |
| 352 |
char *name; |
| 353 |
} ssh2_host_key_t; |
| 354 |
|
| 355 |
static ssh2_host_key_t ssh2_host_key[] = { |
| 356 |
{KEY_RSA1, "ssh-rsa1"}, // for SSH1 only |
| 357 |
{KEY_RSA, "ssh-rsa"}, // RFC4253 |
| 358 |
{KEY_DSA, "ssh-dss"}, // RFC4253 |
| 359 |
{KEY_ECDSA256, "ecdsa-sha2-nistp256"}, // RFC5656 |
| 360 |
{KEY_ECDSA384, "ecdsa-sha2-nistp384"}, // RFC5656 |
| 361 |
{KEY_ECDSA521, "ecdsa-sha2-nistp521"}, // RFC5656 |
| 362 |
{KEY_ED25519, "ssh-ed25519"}, // draft-bjh21-ssh-ed25519-02 |
| 363 |
{KEY_UNSPEC, "ssh-unknown"}, |
| 364 |
{KEY_NONE, NULL}, |
| 365 |
}; |
| 366 |
|
| 367 |
/* Minimum modulus size (n) for RSA keys. */ |
| 368 |
#define SSH_RSA_MINIMUM_MODULUS_SIZE 768 |
| 369 |
|
| 370 |
#define SSH_KEYGEN_DEFAULT_BITS 2048 |
| 371 |
#define SSH_RSA_MINIMUM_KEY_SIZE 768 |
| 372 |
#define SSH_DSA_MINIMUM_KEY_SIZE 1024 |
| 373 |
|
| 374 |
#define SSH_KEYGEN_MINIMUM_ROUNDS 1 |
| 375 |
#define SSH_KEYGEN_MAXIMUM_ROUNDS INT_MAX |
| 376 |
|
| 377 |
|
| 378 |
typedef struct ssh2_cipher { |
| 379 |
SSHCipher cipher; |
| 380 |
char *name; |
| 381 |
int block_size; |
| 382 |
int key_len; |
| 383 |
int discard_len; |
| 384 |
int iv_len; |
| 385 |
int auth_len; |
| 386 |
const EVP_CIPHER *(*func)(void); |
| 387 |
} ssh2_cipher_t; |
| 388 |
|
| 389 |
static ssh2_cipher_t ssh2_ciphers[] = { |
| 390 |
{SSH2_CIPHER_3DES_CBC, "3des-cbc", 8, 24, 0, 0, 0, EVP_des_ede3_cbc}, // RFC4253 |
| 391 |
{SSH2_CIPHER_AES128_CBC, "aes128-cbc", 16, 16, 0, 0, 0, EVP_aes_128_cbc}, // RFC4253 |
| 392 |
{SSH2_CIPHER_AES192_CBC, "aes192-cbc", 16, 24, 0, 0, 0, EVP_aes_192_cbc}, // RFC4253 |
| 393 |
{SSH2_CIPHER_AES256_CBC, "aes256-cbc", 16, 32, 0, 0, 0, EVP_aes_256_cbc}, // RFC4253 |
| 394 |
{SSH2_CIPHER_BLOWFISH_CBC, "blowfish-cbc", 8, 16, 0, 0, 0, EVP_bf_cbc}, // RFC4253 |
| 395 |
{SSH2_CIPHER_AES128_CTR, "aes128-ctr", 16, 16, 0, 0, 0, evp_aes_128_ctr}, // RFC4344 |
| 396 |
{SSH2_CIPHER_AES192_CTR, "aes192-ctr", 16, 24, 0, 0, 0, evp_aes_128_ctr}, // RFC4344 |
| 397 |
{SSH2_CIPHER_AES256_CTR, "aes256-ctr", 16, 32, 0, 0, 0, evp_aes_128_ctr}, // RFC4344 |
| 398 |
{SSH2_CIPHER_ARCFOUR, "arcfour", 8, 16, 0, 0, 0, EVP_rc4}, // RFC4253 |
| 399 |
{SSH2_CIPHER_ARCFOUR128, "arcfour128", 8, 16, 1536, 0, 0, EVP_rc4}, // RFC4345 |
| 400 |
{SSH2_CIPHER_ARCFOUR256, "arcfour256", 8, 32, 1536, 0, 0, EVP_rc4}, // RFC4345 |
| 401 |
{SSH2_CIPHER_CAST128_CBC, "cast128-cbc", 8, 16, 0, 0, 0, EVP_cast5_cbc}, // RFC4253 |
| 402 |
{SSH2_CIPHER_3DES_CTR, "3des-ctr", 8, 24, 0, 0, 0, evp_des3_ctr}, // RFC4344 |
| 403 |
{SSH2_CIPHER_BLOWFISH_CTR, "blowfish-ctr", 8, 32, 0, 0, 0, evp_bf_ctr}, // RFC4344 |
| 404 |
{SSH2_CIPHER_CAST128_CTR, "cast128-ctr", 8, 16, 0, 0, 0, evp_cast5_ctr}, // RFC4344 |
| 405 |
{SSH2_CIPHER_CAMELLIA128_CBC, "camellia128-cbc", 16, 16, 0, 0, 0, EVP_camellia_128_cbc}, // draft-kanno-secsh-camellia-02 |
| 406 |
{SSH2_CIPHER_CAMELLIA192_CBC, "camellia192-cbc", 16, 24, 0, 0, 0, EVP_camellia_192_cbc}, // draft-kanno-secsh-camellia-02 |
| 407 |
{SSH2_CIPHER_CAMELLIA256_CBC, "camellia256-cbc", 16, 32, 0, 0, 0, EVP_camellia_256_cbc}, // draft-kanno-secsh-camellia-02 |
| 408 |
{SSH2_CIPHER_CAMELLIA128_CTR, "camellia128-ctr", 16, 16, 0, 0, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02 |
| 409 |
{SSH2_CIPHER_CAMELLIA192_CTR, "camellia192-ctr", 16, 24, 0, 0, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02 |
| 410 |
{SSH2_CIPHER_CAMELLIA256_CTR, "camellia256-ctr", 16, 32, 0, 0, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02 |
| 411 |
#ifdef WITH_CAMELLIA_PRIVATE |
| 412 |
{SSH2_CIPHER_CAMELLIA128_CBC, "camellia128-cbc@openssh.org", 16, 16, 0, 0, 0, EVP_camellia_128_cbc}, |
| 413 |
{SSH2_CIPHER_CAMELLIA192_CBC, "camellia192-cbc@openssh.org", 16, 24, 0, 0, 0, EVP_camellia_192_cbc}, |
| 414 |
{SSH2_CIPHER_CAMELLIA256_CBC, "camellia256-cbc@openssh.org", 16, 32, 0, 0, 0, EVP_camellia_256_cbc}, |
| 415 |
{SSH2_CIPHER_CAMELLIA128_CTR, "camellia128-ctr@openssh.org", 16, 16, 0, 0, 0, evp_camellia_128_ctr}, |
| 416 |
{SSH2_CIPHER_CAMELLIA192_CTR, "camellia192-ctr@openssh.org", 16, 24, 0, 0, 0, evp_camellia_128_ctr}, |
| 417 |
{SSH2_CIPHER_CAMELLIA256_CTR, "camellia256-ctr@openssh.org", 16, 32, 0, 0, 0, evp_camellia_128_ctr}, |
| 418 |
#endif // WITH_CAMELLIA_PRIVATE |
| 419 |
{SSH2_CIPHER_AES128_GCM, "aes128-gcm@openssh.com", 16, 16, 0, 12, 16, EVP_aes_128_gcm}, // not RFC5647, PROTOCOL of OpenSSH |
| 420 |
{SSH2_CIPHER_AES256_GCM, "aes256-gcm@openssh.com", 16, 32, 0, 12, 16, EVP_aes_256_gcm}, // not RFC5647, PROTOCOL of OpenSSH |
| 421 |
{SSH_CIPHER_NONE, NULL, 0, 0, 0, 0, 0, NULL}, |
| 422 |
}; |
| 423 |
|
| 424 |
|
| 425 |
typedef enum { |
| 426 |
KEX_DH_NONE, /* disabled line */ |
| 427 |
KEX_DH_GRP1_SHA1, |
| 428 |
KEX_DH_GRP14_SHA1, |
| 429 |
KEX_DH_GEX_SHA1, |
| 430 |
KEX_DH_GEX_SHA256, |
| 431 |
KEX_ECDH_SHA2_256, |
| 432 |
KEX_ECDH_SHA2_384, |
| 433 |
KEX_ECDH_SHA2_521, |
| 434 |
KEX_DH_GRP14_SHA256, |
| 435 |
KEX_DH_GRP16_SHA512, |
| 436 |
KEX_DH_GRP18_SHA512, |
| 437 |
KEX_DH_UNKNOWN, |
| 438 |
KEX_DH_MAX = KEX_DH_UNKNOWN, |
| 439 |
} kex_algorithm; |
| 440 |
|
| 441 |
typedef struct ssh2_kex_algorithm { |
| 442 |
kex_algorithm kextype; |
| 443 |
char *name; |
| 444 |
const EVP_MD *(*evp_md)(void); |
| 445 |
} ssh2_kex_algorithm_t; |
| 446 |
|
| 447 |
static ssh2_kex_algorithm_t ssh2_kex_algorithms[] = { |
| 448 |
{KEX_DH_GRP1_SHA1, "diffie-hellman-group1-sha1", EVP_sha1}, // RFC4253 |
| 449 |
{KEX_DH_GRP14_SHA1, "diffie-hellman-group14-sha1", EVP_sha1}, // RFC4253 |
| 450 |
{KEX_DH_GEX_SHA1, "diffie-hellman-group-exchange-sha1", EVP_sha1}, // RFC4419 |
| 451 |
{KEX_DH_GEX_SHA256, "diffie-hellman-group-exchange-sha256", EVP_sha256}, // RFC4419 |
| 452 |
{KEX_ECDH_SHA2_256, "ecdh-sha2-nistp256", EVP_sha256}, // RFC5656 |
| 453 |
{KEX_ECDH_SHA2_384, "ecdh-sha2-nistp384", EVP_sha384}, // RFC5656 |
| 454 |
{KEX_ECDH_SHA2_521, "ecdh-sha2-nistp521", EVP_sha512}, // RFC5656 |
| 455 |
{KEX_DH_GRP14_SHA256, "diffie-hellman-group14-sha256", EVP_sha256}, // draft-baushke-ssh-dh-group-sha2-04 |
| 456 |
{KEX_DH_GRP16_SHA512, "diffie-hellman-group16-sha512", EVP_sha512}, // draft-baushke-ssh-dh-group-sha2-04 |
| 457 |
{KEX_DH_GRP18_SHA512, "diffie-hellman-group18-sha512", EVP_sha512}, // draft-baushke-ssh-dh-group-sha2-04 |
| 458 |
{KEX_DH_NONE , NULL, NULL}, |
| 459 |
}; |
| 460 |
|
| 461 |
|
| 462 |
typedef enum { |
| 463 |
HMAC_NONE, /* disabled line */ |
| 464 |
HMAC_SHA1, |
| 465 |
HMAC_MD5, |
| 466 |
HMAC_SHA1_96, |
| 467 |
HMAC_MD5_96, |
| 468 |
HMAC_RIPEMD160, |
| 469 |
HMAC_SHA2_256, |
| 470 |
HMAC_SHA2_256_96, |
| 471 |
HMAC_SHA2_512, |
| 472 |
HMAC_SHA2_512_96, |
| 473 |
HMAC_SHA1_EtM, |
| 474 |
HMAC_MD5_EtM, |
| 475 |
HMAC_SHA1_96_EtM, |
| 476 |
HMAC_MD5_96_EtM, |
| 477 |
HMAC_RIPEMD160_EtM, |
| 478 |
HMAC_SHA2_256_EtM, |
| 479 |
HMAC_SHA2_512_EtM, |
| 480 |
HMAC_UNKNOWN, |
| 481 |
HMAC_MAX = HMAC_UNKNOWN, |
| 482 |
} hmac_type; |
| 483 |
|
| 484 |
typedef struct ssh2_mac { |
| 485 |
hmac_type type; |
| 486 |
char *name; |
| 487 |
const EVP_MD *(*evp_md)(void); |
| 488 |
int truncatebits; |
| 489 |
int etm; |
| 490 |
} ssh2_mac_t; |
| 491 |
|
| 492 |
static ssh2_mac_t ssh2_macs[] = { |
| 493 |
{HMAC_SHA1, "hmac-sha1", EVP_sha1, 0, 0}, // RFC4253 |
| 494 |
{HMAC_MD5, "hmac-md5", EVP_md5, 0, 0}, // RFC4253 |
| 495 |
{HMAC_SHA1_96, "hmac-sha1-96", EVP_sha1, 96, 0}, // RFC4253 |
| 496 |
{HMAC_MD5_96, "hmac-md5-96", EVP_md5, 96, 0}, // RFC4253 |
| 497 |
{HMAC_RIPEMD160, "hmac-ripemd160@openssh.com", EVP_ripemd160, 0, 0}, |
| 498 |
{HMAC_SHA2_256, "hmac-sha2-256", EVP_sha256, 0, 0}, // RFC6668 |
| 499 |
// {HMAC_SHA2_256_96, "hmac-sha2-256-96", EVP_sha256, 96, 0}, // draft-dbider-sha2-mac-for-ssh-05, deleted at 06 |
| 500 |
{HMAC_SHA2_512, "hmac-sha2-512", EVP_sha512, 0, 0}, // RFC6668 |
| 501 |
// {HMAC_SHA2_512_96, "hmac-sha2-512-96", EVP_sha512, 96, 0}, // draft-dbider-sha2-mac-for-ssh-05, deleted at 06 |
| 502 |
{HMAC_SHA1_EtM, "hmac-sha1-etm@openssh.com", EVP_sha1, 0, 1}, |
| 503 |
{HMAC_MD5_EtM, "hmac-md5-etm@openssh.com", EVP_md5, 0, 1}, |
| 504 |
{HMAC_SHA1_96_EtM, "hmac-sha1-96-etm@openssh.com", EVP_sha1, 96, 1}, |
| 505 |
{HMAC_MD5_96_EtM, "hmac-md5-96-etm@openssh.com", EVP_md5, 96, 1}, |
| 506 |
{HMAC_RIPEMD160_EtM,"hmac-ripemd160-etm@openssh.com",EVP_ripemd160, 0, 1}, |
| 507 |
{HMAC_SHA2_256_EtM, "hmac-sha2-256-etm@openssh.com", EVP_sha256, 0, 1}, |
| 508 |
{HMAC_SHA2_512_EtM, "hmac-sha2-512-etm@openssh.com", EVP_sha512, 0, 1}, |
| 509 |
{HMAC_NONE, NULL, NULL, 0, 0}, |
| 510 |
}; |
| 511 |
|
| 512 |
|
| 513 |
typedef enum { |
| 514 |
COMP_NONE, /* disabled line */ |
| 515 |
COMP_NOCOMP, |
| 516 |
COMP_ZLIB, |
| 517 |
COMP_DELAYED, |
| 518 |
COMP_UNKNOWN, |
| 519 |
COMP_MAX = COMP_UNKNOWN, |
| 520 |
} compression_type; |
| 521 |
|
| 522 |
typedef struct ssh2_comp { |
| 523 |
compression_type type; |
| 524 |
char *name; |
| 525 |
} ssh2_comp_t; |
| 526 |
|
| 527 |
static ssh2_comp_t ssh2_comps[] = { |
| 528 |
{COMP_NOCOMP, "none"}, // RFC4253 |
| 529 |
{COMP_ZLIB, "zlib"}, // RFC4253 |
| 530 |
{COMP_DELAYED, "zlib@openssh.com"}, |
| 531 |
{COMP_NONE, NULL}, |
| 532 |
}; |
| 533 |
|
| 534 |
|
| 535 |
struct Enc { |
| 536 |
u_char *key; |
| 537 |
u_char *iv; |
| 538 |
unsigned int key_len; |
| 539 |
unsigned int block_size; |
| 540 |
unsigned int iv_len; |
| 541 |
unsigned int auth_len; |
| 542 |
}; |
| 543 |
|
| 544 |
struct Mac { |
| 545 |
char *name; |
| 546 |
int enabled; |
| 547 |
const EVP_MD *md; |
| 548 |
unsigned int mac_len; |
| 549 |
u_char *key; |
| 550 |
unsigned int key_len; |
| 551 |
int etm; |
| 552 |
}; |
| 553 |
|
| 554 |
struct Comp { |
| 555 |
int type; |
| 556 |
int enabled; |
| 557 |
char *name; |
| 558 |
}; |
| 559 |
|
| 560 |
typedef struct { |
| 561 |
struct Enc enc; |
| 562 |
struct Mac mac; |
| 563 |
struct Comp comp; |
| 564 |
} SSHKeys; |
| 565 |
|
| 566 |
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) |
| 567 |
|
| 568 |
enum kex_modes { |
| 569 |
MODE_IN, |
| 570 |
MODE_OUT, |
| 571 |
MODE_MAX |
| 572 |
}; |
| 573 |
|
| 574 |
|
| 575 |
// �z�X�g�L�[(SSH1, SSH2����)���f�[�^�\�� (2006.3.21 yutaka) |
| 576 |
typedef struct Key { |
| 577 |
// host key type |
| 578 |
ssh_keytype type; |
| 579 |
// SSH2 RSA |
| 580 |
RSA *rsa; |
| 581 |
// SSH2 DSA |
| 582 |
DSA *dsa; |
| 583 |
// SSH2 ECDSA |
| 584 |
EC_KEY *ecdsa; |
| 585 |
// SSH1 RSA |
| 586 |
int bits; |
| 587 |
unsigned char *exp; |
| 588 |
unsigned char *mod; |
| 589 |
// SSH2 ED25519 |
| 590 |
unsigned char *ed25519_sk; |
| 591 |
unsigned char *ed25519_pk; |
| 592 |
int bcrypt_kdf; |
| 593 |
} Key; |
| 594 |
|
| 595 |
// fingerprint������ |
| 596 |
enum fp_rep { |
| 597 |
SSH_FP_DEFAULT = 0, |
| 598 |
SSH_FP_HEX, |
| 599 |
SSH_FP_BASE64, |
| 600 |
SSH_FP_BUBBLEBABBLE, |
| 601 |
SSH_FP_RANDOMART |
| 602 |
}; |
| 603 |
/* |
| 604 |
enum fp_type { |
| 605 |
SSH_FP_MD5, |
| 606 |
SSH_FP_SHA1, |
| 607 |
SSH_FP_SHA256 |
| 608 |
}; |
| 609 |
*/ |
| 610 |
typedef enum { |
| 611 |
SSH_DIGEST_MD5, |
| 612 |
SSH_DIGEST_RIPEMD160, |
| 613 |
SSH_DIGEST_SHA1, |
| 614 |
SSH_DIGEST_SHA256, |
| 615 |
SSH_DIGEST_SHA384, |
| 616 |
SSH_DIGEST_SHA512, |
| 617 |
SSH_DIGEST_MAX, |
| 618 |
} digest_algorithm; |
| 619 |
|
| 620 |
typedef struct ssh_digest { |
| 621 |
digest_algorithm id; |
| 622 |
char *name; |
| 623 |
} ssh_digest_t; |
| 624 |
|
| 625 |
/* NB. Indexed directly by algorithm number */ |
| 626 |
static ssh_digest_t ssh_digests[] = { |
| 627 |
{ SSH_DIGEST_MD5, "MD5" }, |
| 628 |
{ SSH_DIGEST_RIPEMD160, "RIPEMD160" }, |
| 629 |
{ SSH_DIGEST_SHA1, "SHA1" }, |
| 630 |
{ SSH_DIGEST_SHA256, "SHA256" }, |
| 631 |
{ SSH_DIGEST_SHA384, "SHA384" }, |
| 632 |
{ SSH_DIGEST_SHA512, "SHA512" }, |
| 633 |
{ SSH_DIGEST_MAX, NULL }, |
| 634 |
}; |
| 635 |
|
| 636 |
enum scp_dir { |
| 637 |
TOREMOTE, FROMREMOTE, |
| 638 |
}; |
| 639 |
|
| 640 |
/* The packet handler returns TRUE to keep the handler in place, |
| 641 |
FALSE to remove the handler. */ |
| 642 |
typedef BOOL (* SSHPacketHandler)(PTInstVar pvar); |
| 643 |
|
| 644 |
typedef struct _SSHPacketHandlerItem SSHPacketHandlerItem; |
| 645 |
struct _SSHPacketHandlerItem { |
| 646 |
SSHPacketHandler handler; |
| 647 |
/* Circular list of handlers for given message */ |
| 648 |
SSHPacketHandlerItem *next_for_message; |
| 649 |
SSHPacketHandlerItem *last_for_message; |
| 650 |
/* Circular list of handlers in set */ |
| 651 |
SSHPacketHandlerItem *next_in_set; |
| 652 |
int active_for_message; |
| 653 |
}; |
| 654 |
|
| 655 |
typedef struct { |
| 656 |
char *hostname; |
| 657 |
|
| 658 |
int server_protocol_flags; |
| 659 |
char *server_ID; |
| 660 |
|
| 661 |
/* This buffer is used to hold the outgoing data, and encrypted in-place |
| 662 |
here if necessary. */ |
| 663 |
unsigned char *outbuf; |
| 664 |
long outbuflen; |
| 665 |
/* This buffer is used by the SSH protocol processing to store uncompressed |
| 666 |
packet data for compression. User data is never streamed through here; |
| 667 |
it is compressed directly from the user's buffer. */ |
| 668 |
unsigned char *precompress_outbuf; |
| 669 |
long precompress_outbuflen; |
| 670 |
/* this is the length of the packet data, including the type header */ |
| 671 |
long outgoing_packet_len; |
| 672 |
|
| 673 |
/* This buffer is used by the SSH protocol processing to store decompressed |
| 674 |
packet data. User data is never streamed through here; it is decompressed |
| 675 |
directly to the user's buffer. */ |
| 676 |
unsigned char *postdecompress_inbuf; |
| 677 |
long postdecompress_inbuflen; |
| 678 |
|
| 679 |
unsigned char *payload; |
| 680 |
long payload_grabbed; |
| 681 |
long payloadlen; |
| 682 |
long payload_datastart; |
| 683 |
long payload_datalen; |
| 684 |
|
| 685 |
uint32 receiver_sequence_number; |
| 686 |
uint32 sender_sequence_number; |
| 687 |
|
| 688 |
z_stream compress_stream; |
| 689 |
z_stream decompress_stream; |
| 690 |
BOOL compressing; |
| 691 |
BOOL decompressing; |
| 692 |
int compression_level; |
| 693 |
|
| 694 |
SSHPacketHandlerItem *packet_handlers[256]; |
| 695 |
int status_flags; |
| 696 |
|
| 697 |
int win_cols; |
| 698 |
int win_rows; |
| 699 |
|
| 700 |
unsigned short tcpport; |
| 701 |
} SSHState; |
| 702 |
|
| 703 |
#define STATUS_DONT_SEND_USER_NAME 0x01 |
| 704 |
#define STATUS_EXPECTING_COMPRESSION_RESPONSE 0x02 |
| 705 |
#define STATUS_DONT_SEND_CREDENTIALS 0x04 |
| 706 |
#define STATUS_HOST_OK 0x08 |
| 707 |
#define STATUS_INTERACTIVE 0x10 |
| 708 |
#define STATUS_IN_PARTIAL_ID_STRING 0x20 |
| 709 |
|
| 710 |
void SSH_init(PTInstVar pvar); |
| 711 |
void SSH_open(PTInstVar pvar); |
| 712 |
void SSH_notify_disconnecting(PTInstVar pvar, char *reason); |
| 713 |
/* SSH_handle_server_ID returns TRUE iff a valid ID string has been |
| 714 |
received. If it returns FALSE, we need to keep looking for another |
| 715 |
ID string. */ |
| 716 |
BOOL SSH_handle_server_ID(PTInstVar pvar, char *ID, int ID_len); |
| 717 |
/* SSH_handle_packet requires NO PAYLOAD on entry. |
| 718 |
'len' is the size of the packet: payload + padding (+ CRC for SSHv1) |
| 719 |
'padding' is the size of the padding. |
| 720 |
'data' points to the start of the packet data (the length field) |
| 721 |
*/ |
| 722 |
void SSH1_handle_packet(PTInstVar pvar, char *data, unsigned int len, unsigned int padding); |
| 723 |
void SSH2_handle_packet(PTInstVar pvar, char *data, unsigned int len, unsigned int aadlen, unsigned int authlen); |
| 724 |
void SSH_notify_win_size(PTInstVar pvar, int cols, int rows); |
| 725 |
void SSH_notify_user_name(PTInstVar pvar); |
| 726 |
void SSH_notify_cred(PTInstVar pvar); |
| 727 |
void SSH_notify_host_OK(PTInstVar pvar); |
| 728 |
void SSH_send(PTInstVar pvar, unsigned char const *buf, unsigned int buflen); |
| 729 |
/* SSH_extract_payload returns number of bytes extracted */ |
| 730 |
int SSH_extract_payload(PTInstVar pvar, unsigned char *dest, int len); |
| 731 |
void SSH_end(PTInstVar pvar); |
| 732 |
|
| 733 |
void SSH_get_server_ID_info(PTInstVar pvar, char *dest, int len); |
| 734 |
void SSH_get_protocol_version_info(PTInstVar pvar, char *dest, int len); |
| 735 |
void SSH_get_compression_info(PTInstVar pvar, char *dest, int len); |
| 736 |
void SSH_get_mac_info(PTInstVar pvar, char *dest, int len); |
| 737 |
|
| 738 |
/* len must be <= SSH_MAX_SEND_PACKET_SIZE */ |
| 739 |
void SSH_channel_send(PTInstVar pvar, int channel_num, |
| 740 |
uint32 remote_channel_num, |
| 741 |
unsigned char *buf, int len, int retry); |
| 742 |
void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num); |
| 743 |
void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num); |
| 744 |
void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num); |
| 745 |
void SSH_channel_input_eof(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num); |
| 746 |
void SSH_request_forwarding(PTInstVar pvar, char *bind_address, int from_server_port, |
| 747 |
char *to_local_host, int to_local_port); |
| 748 |
void SSH_cancel_request_forwarding(PTInstVar pvar, char *bind_address, int from_server_port, int reply); |
| 749 |
void SSH_request_X11_forwarding(PTInstVar pvar, |
| 750 |
char *auth_protocol, unsigned char *auth_data, int auth_data_len, int screen_num); |
| 751 |
void SSH_open_channel(PTInstVar pvar, uint32 local_channel_num, |
| 752 |
char *to_remote_host, int to_remote_port, |
| 753 |
char *originator, unsigned short originator_port); |
| 754 |
|
| 755 |
int SSH_start_scp(PTInstVar pvar, char *sendfile, char *dstfile); |
| 756 |
int SSH_start_scp_receive(PTInstVar pvar, char *filename); |
| 757 |
int SSH_scp_transaction(PTInstVar pvar, char *sendfile, char *dstfile, enum scp_dir direction); |
| 758 |
int SSH_sftp_transaction(PTInstVar pvar); |
| 759 |
|
| 760 |
/* auxiliary SSH2 interfaces for pkt.c */ |
| 761 |
unsigned int SSH_get_min_packet_size(PTInstVar pvar); |
| 762 |
/* data is guaranteed to be at least SSH_get_min_packet_size bytes long |
| 763 |
at least 5 bytes must be decrypted */ |
| 764 |
void SSH_predecrpyt_packet(PTInstVar pvar, char *data); |
| 765 |
unsigned int SSH_get_clear_MAC_size(PTInstVar pvar); |
| 766 |
unsigned int SSH_get_authdata_size(PTInstVar pvar, int direction); |
| 767 |
|
| 768 |
#define SSH_is_any_payload(pvar) ((pvar)->ssh_state.payload_datalen > 0) |
| 769 |
#define SSH_get_host_name(pvar) ((pvar)->ssh_state.hostname) |
| 770 |
#define SSH_get_compression_level(pvar) ((pvar)->ssh_state.compressing ? (pvar)->ts_SSH_CompressionLevel : 0) |
| 771 |
|
| 772 |
void SSH2_send_kexinit(PTInstVar pvar); |
| 773 |
BOOL do_SSH2_userauth(PTInstVar pvar); |
| 774 |
BOOL do_SSH2_authrequest(PTInstVar pvar); |
| 775 |
void debug_print(int no, char *msg, int len); |
| 776 |
int get_cipher_block_size(SSHCipher cipher); |
| 777 |
int get_cipher_key_len(SSHCipher cipher); |
| 778 |
int get_cipher_iv_len(SSHCipher cipher); |
| 779 |
int get_cipher_auth_len(SSHCipher cipher); |
| 780 |
SSHCipher get_cipher_by_name(char *name); |
| 781 |
char* get_kex_algorithm_name(kex_algorithm kextype); |
| 782 |
const EVP_CIPHER* get_cipher_EVP_CIPHER(SSHCipher cipher); |
| 783 |
const EVP_MD* get_kex_algorithm_EVP_MD(kex_algorithm kextype); |
| 784 |
char* get_ssh2_mac_name(hmac_type type); |
| 785 |
const EVP_MD* get_ssh2_mac_EVP_MD(hmac_type type); |
| 786 |
int get_ssh2_mac_truncatebits(hmac_type type); |
| 787 |
char* get_ssh2_comp_name(compression_type type); |
| 788 |
char* get_ssh_keytype_name(ssh_keytype type); |
| 789 |
char* get_digest_algorithm_name(digest_algorithm id); |
| 790 |
int get_cipher_discard_len(SSHCipher cipher); |
| 791 |
void ssh_heartbeat_lock_initialize(void); |
| 792 |
void ssh_heartbeat_lock_finalize(void); |
| 793 |
void ssh_heartbeat_lock(void); |
| 794 |
void ssh_heartbeat_unlock(void); |
| 795 |
void halt_ssh_heartbeat_thread(PTInstVar pvar); |
| 796 |
void ssh2_channel_free(void); |
| 797 |
BOOL handle_SSH2_userauth_msg60(PTInstVar pvar); |
| 798 |
BOOL handle_SSH2_userauth_inforeq(PTInstVar pvar); |
| 799 |
BOOL handle_SSH2_userauth_pkok(PTInstVar pvar); |
| 800 |
BOOL handle_SSH2_userauth_passwd_changereq(PTInstVar pvar); |
| 801 |
void SSH2_update_compression_myproposal(PTInstVar pvar); |
| 802 |
void SSH2_update_cipher_myproposal(PTInstVar pvar); |
| 803 |
void SSH2_update_kex_myproposal(PTInstVar pvar); |
| 804 |
void SSH2_update_host_key_myproposal(PTInstVar pvar); |
| 805 |
void SSH2_update_hmac_myproposal(PTInstVar pvar); |
| 806 |
int SSH_notify_break_signal(PTInstVar pvar); |
| 807 |
|
| 808 |
/// |
| 809 |
enum scp_state { |
| 810 |
SCP_INIT, SCP_TIMESTAMP, SCP_FILEINFO, SCP_DATA, SCP_CLOSING, |
| 811 |
}; |
| 812 |
|
| 813 |
typedef struct bufchain { |
| 814 |
buffer_t *msg; |
| 815 |
struct bufchain *next; |
| 816 |
} bufchain_t; |
| 817 |
|
| 818 |
typedef struct PacketList { |
| 819 |
char *buf; |
| 820 |
unsigned int buflen; |
| 821 |
struct PacketList *next; |
| 822 |
} PacketList_t; |
| 823 |
|
| 824 |
typedef struct scp { |
| 825 |
enum scp_dir dir; // transfer direction |
| 826 |
enum scp_state state; // SCP state |
| 827 |
char localfile[MAX_PATH]; // local filename |
| 828 |
char localfilefull[MAX_PATH]; // local filename fullpath |
| 829 |
char remotefile[MAX_PATH]; // remote filename |
| 830 |
FILE *localfp; // file pointer for local file |
| 831 |
struct __stat64 filestat; // file status information |
| 832 |
HWND progress_window; |
| 833 |
HANDLE thread; |
| 834 |
unsigned int thread_id; |
| 835 |
PTInstVar pvar; |
| 836 |
// for receiving file |
| 837 |
long long filetotalsize; |
| 838 |
long long filercvsize; |
| 839 |
DWORD filemtime; |
| 840 |
DWORD fileatime; |
| 841 |
PacketList_t *pktlist_head; |
| 842 |
PacketList_t *pktlist_tail; |
| 843 |
} scp_t; |
| 844 |
|
| 845 |
enum sftp_state { |
| 846 |
SFTP_INIT, SFTP_CONNECTED, SFTP_REALPATH, |
| 847 |
}; |
| 848 |
|
| 849 |
typedef struct sftp { |
| 850 |
enum sftp_state state; |
| 851 |
HWND console_window; |
| 852 |
unsigned int transfer_buflen; |
| 853 |
unsigned int num_requests; |
| 854 |
unsigned int version; |
| 855 |
unsigned int msg_id; |
| 856 |
#define SFTP_EXT_POSIX_RENAME 0x00000001 |
| 857 |
#define SFTP_EXT_STATVFS 0x00000002 |
| 858 |
#define SFTP_EXT_FSTATVFS 0x00000004 |
| 859 |
#define SFTP_EXT_HARDLINK 0x00000008 |
| 860 |
unsigned int exts; |
| 861 |
unsigned long long limit_kbps; |
| 862 |
//struct bwlimit bwlimit_in, bwlimit_out; |
| 863 |
char path[1024]; |
| 864 |
} sftp_t; |
| 865 |
|
| 866 |
typedef struct channel { |
| 867 |
int used; |
| 868 |
int self_id; |
| 869 |
int remote_id; |
| 870 |
unsigned int local_window; |
| 871 |
unsigned int local_window_max; |
| 872 |
unsigned int local_consumed; |
| 873 |
unsigned int local_maxpacket; |
| 874 |
unsigned int remote_window; |
| 875 |
unsigned int remote_maxpacket; |
| 876 |
enum channel_type type; |
| 877 |
int local_num; |
| 878 |
bufchain_t *bufchain; |
| 879 |
scp_t scp; |
| 880 |
buffer_t *agent_msg; |
| 881 |
int agent_request_len; |
| 882 |
sftp_t sftp; |
| 883 |
#define SSH_CHANNEL_STATE_CLOSE_SENT 0x00000001 |
| 884 |
unsigned int state; |
| 885 |
} Channel_t; |
| 886 |
|
| 887 |
unsigned char *begin_send_packet(PTInstVar pvar, int type, int len); |
| 888 |
void finish_send_packet_special(PTInstVar pvar, int skip_compress); |
| 889 |
void SSH2_send_channel_data(PTInstVar pvar, Channel_t *c, unsigned char *buf, unsigned int buflen, int retry); |
| 890 |
|
| 891 |
#define finish_send_packet(pvar) finish_send_packet_special((pvar), 0) |
| 892 |
#define get_payload_uint32(pvar, offset) get_uint32_MSBfirst((pvar)->ssh_state.payload + (offset)) |
| 893 |
#define get_uint32(buf) get_uint32_MSBfirst((buf)) |
| 894 |
#define set_uint32(buf, v) set_uint32_MSBfirst((buf), (v)) |
| 895 |
#define get_mpint_len(pvar, offset) ((get_ushort16_MSBfirst((pvar)->ssh_state.payload + (offset)) + 7) >> 3) |
| 896 |
#define get_ushort16(buf) get_ushort16_MSBfirst((buf)) |
| 897 |
/// |
| 898 |
|
| 899 |
/* Global request confirmation callbacks */ |
| 900 |
typedef void global_confirm_cb(PTInstVar pvar, int type, unsigned int seq, void *ctx); |
| 901 |
void client_register_global_confirm(global_confirm_cb *cb, void *ctx); |
| 902 |
|
| 903 |
/* Global request success/failure callbacks */ |
| 904 |
struct global_confirm { |
| 905 |
global_confirm_cb *cb; |
| 906 |
void *ctx; |
| 907 |
int ref_count; |
| 908 |
}; |
| 909 |
|
| 910 |
#endif |