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