| 1 |
maya |
3227 |
/* |
| 2 |
|
|
Copyright (c) 1998-2001, Robert O'Callahan |
| 3 |
|
|
All rights reserved. |
| 4 |
|
|
|
| 5 |
|
|
Redistribution and use in source and binary forms, with or without modification, |
| 6 |
|
|
are permitted provided that the following conditions are met: |
| 7 |
|
|
|
| 8 |
|
|
Redistributions of source code must retain the above copyright notice, this list of |
| 9 |
|
|
conditions and the following disclaimer. |
| 10 |
|
|
|
| 11 |
|
|
Redistributions in binary form must reproduce the above copyright notice, this list |
| 12 |
|
|
of conditions and the following disclaimer in the documentation and/or other materials |
| 13 |
|
|
provided with the distribution. |
| 14 |
|
|
|
| 15 |
|
|
The name of Robert O'Callahan may not be used to endorse or promote products derived from |
| 16 |
|
|
this software without specific prior written permission. |
| 17 |
|
|
|
| 18 |
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND |
| 19 |
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 21 |
|
|
THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 |
|
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 |
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 |
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 |
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
|
|
*/ |
| 28 |
|
|
|
| 29 |
|
|
/* |
| 30 |
|
|
This code is copyright (C) 1998-1999 Robert O'Callahan. |
| 31 |
|
|
See LICENSE.TXT for the license. |
| 32 |
|
|
*/ |
| 33 |
|
|
|
| 34 |
|
|
#ifndef __SSH_H |
| 35 |
|
|
#define __SSH_H |
| 36 |
|
|
|
| 37 |
|
|
#include "zlib.h" |
| 38 |
|
|
#include <openssl/evp.h> |
| 39 |
|
|
|
| 40 |
|
|
#include "buffer.h" |
| 41 |
doda |
4433 |
#include "config.h" |
| 42 |
yutakapon |
4926 |
#include <sys/types.h> |
| 43 |
|
|
#include <sys/stat.h> |
| 44 |
maya |
3227 |
|
| 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 |
doda |
3850 |
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 |
doda |
4433 |
extern const EVP_CIPHER *evp_camellia_128_ctr(void); |
| 57 |
maya |
3227 |
|
| 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 |
doda |
3850 |
SSH2_CIPHER_3DES_CTR, SSH2_CIPHER_BLOWFISH_CTR, SSH2_CIPHER_CAST128_CTR, |
| 94 |
doda |
4433 |
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 |
maya |
3227 |
} 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 |
maya |
4378 |
SSH_AUTH_MAX = SSH_AUTH_PAGEANT, |
| 104 |
maya |
3227 |
} 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 |
maya |
4314 |
#define SSH2_MSG_KEX_ECDH_INIT 30 |
| 155 |
|
|
#define SSH2_MSG_KEX_ECDH_REPLY 31 |
| 156 |
|
|
|
| 157 |
maya |
3227 |
#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 |
maya |
5669 |
#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 |
maya |
3227 |
|
| 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 |
doda |
5587 |
// 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 |
maya |
3227 |
|
| 262 |
doda |
5587 |
|
| 263 |
maya |
4378 |
// �N���C�A���g�����T�[�o������������ |
| 264 |
maya |
3227 |
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 |
maya |
4378 |
#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 |
maya |
3227 |
|
| 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 |
maya |
4378 |
typedef enum { |
| 300 |
|
|
KEY_NONE, |
| 301 |
|
|
KEY_RSA1, |
| 302 |
|
|
KEY_RSA, |
| 303 |
|
|
KEY_DSA, |
| 304 |
|
|
KEY_ECDSA256, |
| 305 |
|
|
KEY_ECDSA384, |
| 306 |
|
|
KEY_ECDSA521, |
| 307 |
yutakapon |
5545 |
KEY_ED25519, |
| 308 |
maya |
4378 |
KEY_UNSPEC, |
| 309 |
|
|
KEY_MAX = KEY_UNSPEC, |
| 310 |
|
|
} ssh_keytype; |
| 311 |
yutakapon |
5545 |
#define isFixedLengthKey(type) ((type) >= KEY_DSA && (type) <= KEY_ED25519) |
| 312 |
maya |
4378 |
|
| 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 |
maya |
4592 |
{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 |
maya |
6270 |
{KEY_ED25519, "ssh-ed25519"}, // draft-bjh21-ssh-ed25519-02 |
| 326 |
maya |
4378 |
{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 |
maya |
5765 |
#define SSH_KEYGEN_MINIMUM_ROUNDS 1 |
| 338 |
|
|
#define SSH_KEYGEN_MAXIMUM_ROUNDS INT_MAX |
| 339 |
maya |
4378 |
|
| 340 |
maya |
5765 |
|
| 341 |
maya |
3227 |
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 |
maya |
4592 |
{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 |
doda |
4433 |
#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 |
maya |
4301 |
{SSH_CIPHER_NONE, NULL, 0, 0, 0, NULL}, |
| 381 |
maya |
3227 |
}; |
| 382 |
|
|
|
| 383 |
|
|
|
| 384 |
maya |
4378 |
typedef enum { |
| 385 |
yutakapon |
4367 |
KEX_DH_NONE, /* disabled line */ |
| 386 |
maya |
4301 |
KEX_DH_GRP1_SHA1, |
| 387 |
|
|
KEX_DH_GRP14_SHA1, |
| 388 |
|
|
KEX_DH_GEX_SHA1, |
| 389 |
|
|
KEX_DH_GEX_SHA256, |
| 390 |
maya |
4314 |
KEX_ECDH_SHA2_256, |
| 391 |
|
|
KEX_ECDH_SHA2_384, |
| 392 |
|
|
KEX_ECDH_SHA2_521, |
| 393 |
doda |
6263 |
KEX_DH_GRP14_SHA256, |
| 394 |
doda |
6310 |
KEX_DH_GRP16_SHA512, |
| 395 |
|
|
KEX_DH_GRP18_SHA512, |
| 396 |
maya |
4301 |
KEX_DH_UNKNOWN, |
| 397 |
yutakapon |
4367 |
KEX_DH_MAX = KEX_DH_UNKNOWN, |
| 398 |
maya |
4378 |
} kex_algorithm; |
| 399 |
maya |
4301 |
|
| 400 |
|
|
typedef struct ssh2_kex_algorithm { |
| 401 |
maya |
4378 |
kex_algorithm kextype; |
| 402 |
maya |
4301 |
char *name; |
| 403 |
|
|
const EVP_MD *(*evp_md)(void); |
| 404 |
|
|
} ssh2_kex_algorithm_t; |
| 405 |
|
|
|
| 406 |
|
|
static ssh2_kex_algorithm_t ssh2_kex_algorithms[] = { |
| 407 |
maya |
4592 |
{KEX_DH_GRP1_SHA1, "diffie-hellman-group1-sha1", EVP_sha1}, // RFC4253 |
| 408 |
|
|
{KEX_DH_GRP14_SHA1, "diffie-hellman-group14-sha1", EVP_sha1}, // RFC4253 |
| 409 |
|
|
{KEX_DH_GEX_SHA1, "diffie-hellman-group-exchange-sha1", EVP_sha1}, // RFC4419 |
| 410 |
|
|
{KEX_DH_GEX_SHA256, "diffie-hellman-group-exchange-sha256", EVP_sha256}, // RFC4419 |
| 411 |
|
|
{KEX_ECDH_SHA2_256, "ecdh-sha2-nistp256", EVP_sha256}, // RFC5656 |
| 412 |
|
|
{KEX_ECDH_SHA2_384, "ecdh-sha2-nistp384", EVP_sha384}, // RFC5656 |
| 413 |
|
|
{KEX_ECDH_SHA2_521, "ecdh-sha2-nistp521", EVP_sha512}, // RFC5656 |
| 414 |
doda |
6310 |
{KEX_DH_GRP14_SHA256, "diffie-hellman-group14-sha256", EVP_sha256}, // draft-baushke-ssh-dh-group-sha2-04 |
| 415 |
|
|
{KEX_DH_GRP16_SHA512, "diffie-hellman-group16-sha512", EVP_sha512}, // draft-baushke-ssh-dh-group-sha2-04 |
| 416 |
|
|
{KEX_DH_GRP18_SHA512, "diffie-hellman-group18-sha512", EVP_sha512}, // draft-baushke-ssh-dh-group-sha2-04 |
| 417 |
maya |
4378 |
{KEX_DH_NONE , NULL, NULL}, |
| 418 |
maya |
4301 |
}; |
| 419 |
|
|
|
| 420 |
|
|
|
| 421 |
maya |
4378 |
typedef enum { |
| 422 |
|
|
HMAC_NONE, /* disabled line */ |
| 423 |
maya |
4301 |
HMAC_SHA1, |
| 424 |
|
|
HMAC_MD5, |
| 425 |
doda |
4422 |
HMAC_SHA1_96, |
| 426 |
|
|
HMAC_MD5_96, |
| 427 |
doda |
4423 |
HMAC_RIPEMD160, |
| 428 |
doda |
4425 |
HMAC_SHA2_256, |
| 429 |
|
|
HMAC_SHA2_256_96, |
| 430 |
|
|
HMAC_SHA2_512, |
| 431 |
|
|
HMAC_SHA2_512_96, |
| 432 |
yutakapon |
4367 |
HMAC_UNKNOWN, |
| 433 |
|
|
HMAC_MAX = HMAC_UNKNOWN, |
| 434 |
maya |
4378 |
} hmac_type; |
| 435 |
maya |
4301 |
|
| 436 |
maya |
3227 |
typedef struct ssh2_mac { |
| 437 |
maya |
4378 |
hmac_type type; |
| 438 |
maya |
3227 |
char *name; |
| 439 |
maya |
4378 |
const EVP_MD *(*evp_md)(void); |
| 440 |
maya |
3227 |
int truncatebits; |
| 441 |
|
|
} ssh2_mac_t; |
| 442 |
|
|
|
| 443 |
|
|
static ssh2_mac_t ssh2_macs[] = { |
| 444 |
maya |
4592 |
{HMAC_SHA1, "hmac-sha1", EVP_sha1, 0}, // RFC4253 |
| 445 |
|
|
{HMAC_MD5, "hmac-md5", EVP_md5, 0}, // RFC4253 |
| 446 |
|
|
{HMAC_SHA1_96, "hmac-sha1-96", EVP_sha1, 96}, // RFC4253 |
| 447 |
|
|
{HMAC_MD5_96, "hmac-md5-96", EVP_md5, 96}, // RFC4253 |
| 448 |
doda |
4425 |
{HMAC_RIPEMD160, "hmac-ripemd160@openssh.com", EVP_ripemd160, 0}, |
| 449 |
maya |
4980 |
{HMAC_SHA2_256, "hmac-sha2-256", EVP_sha256, 0}, // RFC6668 |
| 450 |
doda |
5016 |
// {HMAC_SHA2_256_96, "hmac-sha2-256-96", EVP_sha256, 96}, // draft-dbider-sha2-mac-for-ssh-05, deleted at 06 |
| 451 |
maya |
4980 |
{HMAC_SHA2_512, "hmac-sha2-512", EVP_sha512, 0}, // RFC6668 |
| 452 |
doda |
5016 |
// {HMAC_SHA2_512_96, "hmac-sha2-512-96", EVP_sha512, 96}, // draft-dbider-sha2-mac-for-ssh-05, deleted at 06 |
| 453 |
doda |
4425 |
{HMAC_NONE, NULL, NULL, 0}, |
| 454 |
maya |
3227 |
}; |
| 455 |
|
|
|
| 456 |
maya |
4301 |
|
| 457 |
maya |
4378 |
typedef enum { |
| 458 |
|
|
COMP_NONE, /* disabled line */ |
| 459 |
|
|
COMP_NOCOMP, |
| 460 |
maya |
4301 |
COMP_ZLIB, |
| 461 |
|
|
COMP_DELAYED, |
| 462 |
yutakapon |
4367 |
COMP_UNKNOWN, |
| 463 |
|
|
COMP_MAX = COMP_UNKNOWN, |
| 464 |
maya |
4378 |
} compression_type; |
| 465 |
maya |
3227 |
|
| 466 |
maya |
4378 |
typedef struct ssh2_comp { |
| 467 |
|
|
compression_type type; |
| 468 |
maya |
4301 |
char *name; |
| 469 |
maya |
4378 |
} ssh2_comp_t; |
| 470 |
maya |
3227 |
|
| 471 |
maya |
4378 |
static ssh2_comp_t ssh2_comps[] = { |
| 472 |
maya |
4592 |
{COMP_NOCOMP, "none"}, // RFC4253 |
| 473 |
|
|
{COMP_ZLIB, "zlib"}, // RFC4253 |
| 474 |
maya |
4301 |
{COMP_DELAYED, "zlib@openssh.com"}, |
| 475 |
maya |
4378 |
{COMP_NONE, NULL}, |
| 476 |
maya |
4301 |
}; |
| 477 |
|
|
|
| 478 |
|
|
|
| 479 |
maya |
3227 |
struct Enc { |
| 480 |
|
|
u_char *key; |
| 481 |
|
|
u_char *iv; |
| 482 |
|
|
unsigned int key_len; |
| 483 |
|
|
unsigned int block_size; |
| 484 |
|
|
}; |
| 485 |
|
|
|
| 486 |
|
|
struct Mac { |
| 487 |
|
|
char *name; |
| 488 |
|
|
int enabled; |
| 489 |
|
|
const EVP_MD *md; |
| 490 |
|
|
int mac_len; |
| 491 |
|
|
u_char *key; |
| 492 |
|
|
int key_len; |
| 493 |
|
|
}; |
| 494 |
|
|
|
| 495 |
|
|
struct Comp { |
| 496 |
|
|
int type; |
| 497 |
|
|
int enabled; |
| 498 |
|
|
char *name; |
| 499 |
|
|
}; |
| 500 |
|
|
|
| 501 |
|
|
typedef struct { |
| 502 |
|
|
struct Enc enc; |
| 503 |
|
|
struct Mac mac; |
| 504 |
|
|
struct Comp comp; |
| 505 |
|
|
} Newkeys; |
| 506 |
|
|
|
| 507 |
|
|
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) |
| 508 |
|
|
|
| 509 |
|
|
enum kex_modes { |
| 510 |
|
|
MODE_IN, |
| 511 |
|
|
MODE_OUT, |
| 512 |
|
|
MODE_MAX |
| 513 |
|
|
}; |
| 514 |
|
|
|
| 515 |
|
|
|
| 516 |
|
|
// �z�X�g�L�[(SSH1, SSH2����)���f�[�^�\�� (2006.3.21 yutaka) |
| 517 |
|
|
typedef struct Key { |
| 518 |
|
|
// host key type |
| 519 |
maya |
4378 |
ssh_keytype type; |
| 520 |
maya |
3227 |
// SSH2 RSA |
| 521 |
|
|
RSA *rsa; |
| 522 |
|
|
// SSH2 DSA |
| 523 |
|
|
DSA *dsa; |
| 524 |
maya |
4321 |
// SSH2 ECDSA |
| 525 |
|
|
EC_KEY *ecdsa; |
| 526 |
maya |
3227 |
// SSH1 RSA |
| 527 |
|
|
int bits; |
| 528 |
|
|
unsigned char *exp; |
| 529 |
|
|
unsigned char *mod; |
| 530 |
yutakapon |
5545 |
// SSH2 ED25519 |
| 531 |
|
|
unsigned char *ed25519_sk; |
| 532 |
|
|
unsigned char *ed25519_pk; |
| 533 |
|
|
int bcrypt_kdf; |
| 534 |
maya |
3227 |
} Key; |
| 535 |
|
|
|
| 536 |
|
|
// fingerprint������ |
| 537 |
|
|
enum fp_rep { |
| 538 |
maya |
6118 |
SSH_FP_DEFAULT = 0, |
| 539 |
maya |
3227 |
SSH_FP_HEX, |
| 540 |
maya |
6118 |
SSH_FP_BASE64, |
| 541 |
maya |
3227 |
SSH_FP_BUBBLEBABBLE, |
| 542 |
|
|
SSH_FP_RANDOMART |
| 543 |
|
|
}; |
| 544 |
maya |
6120 |
/* |
| 545 |
doda |
4531 |
enum fp_type { |
| 546 |
doda |
4539 |
SSH_FP_MD5, |
| 547 |
doda |
4531 |
SSH_FP_SHA1, |
| 548 |
doda |
4539 |
SSH_FP_SHA256 |
| 549 |
doda |
4531 |
}; |
| 550 |
maya |
6120 |
*/ |
| 551 |
|
|
typedef enum { |
| 552 |
|
|
SSH_DIGEST_MD5, |
| 553 |
|
|
SSH_DIGEST_RIPEMD160, |
| 554 |
|
|
SSH_DIGEST_SHA1, |
| 555 |
|
|
SSH_DIGEST_SHA256, |
| 556 |
|
|
SSH_DIGEST_SHA384, |
| 557 |
|
|
SSH_DIGEST_SHA512, |
| 558 |
|
|
SSH_DIGEST_MAX, |
| 559 |
|
|
} digest_algorithm; |
| 560 |
doda |
4531 |
|
| 561 |
maya |
6120 |
typedef struct ssh_digest { |
| 562 |
|
|
digest_algorithm id; |
| 563 |
maya |
6157 |
char *name; |
| 564 |
maya |
6120 |
} ssh_digest_t; |
| 565 |
|
|
|
| 566 |
|
|
/* NB. Indexed directly by algorithm number */ |
| 567 |
|
|
static ssh_digest_t ssh_digests[] = { |
| 568 |
maya |
6157 |
{ SSH_DIGEST_MD5, "MD5" }, |
| 569 |
|
|
{ SSH_DIGEST_RIPEMD160, "RIPEMD160" }, |
| 570 |
|
|
{ SSH_DIGEST_SHA1, "SHA1" }, |
| 571 |
|
|
{ SSH_DIGEST_SHA256, "SHA256" }, |
| 572 |
|
|
{ SSH_DIGEST_SHA384, "SHA384" }, |
| 573 |
|
|
{ SSH_DIGEST_SHA512, "SHA512" }, |
| 574 |
|
|
{ SSH_DIGEST_MAX, NULL }, |
| 575 |
maya |
6120 |
}; |
| 576 |
|
|
|
| 577 |
maya |
3227 |
enum scp_dir { |
| 578 |
r850 |
3375 |
TOREMOTE, FROMREMOTE, |
| 579 |
maya |
3227 |
}; |
| 580 |
|
|
|
| 581 |
|
|
/* The packet handler returns TRUE to keep the handler in place, |
| 582 |
|
|
FALSE to remove the handler. */ |
| 583 |
|
|
typedef BOOL (* SSHPacketHandler)(PTInstVar pvar); |
| 584 |
|
|
|
| 585 |
|
|
typedef struct _SSHPacketHandlerItem SSHPacketHandlerItem; |
| 586 |
|
|
struct _SSHPacketHandlerItem { |
| 587 |
|
|
SSHPacketHandler handler; |
| 588 |
|
|
/* Circular list of handlers for given message */ |
| 589 |
|
|
SSHPacketHandlerItem FAR * next_for_message; |
| 590 |
|
|
SSHPacketHandlerItem FAR * last_for_message; |
| 591 |
|
|
/* Circular list of handlers in set */ |
| 592 |
|
|
SSHPacketHandlerItem FAR * next_in_set; |
| 593 |
|
|
int active_for_message; |
| 594 |
|
|
}; |
| 595 |
|
|
|
| 596 |
|
|
typedef struct { |
| 597 |
|
|
char FAR * hostname; |
| 598 |
|
|
|
| 599 |
|
|
int server_protocol_flags; |
| 600 |
|
|
char FAR * server_ID; |
| 601 |
|
|
|
| 602 |
|
|
/* This buffer is used to hold the outgoing data, and encrypted in-place |
| 603 |
|
|
here if necessary. */ |
| 604 |
|
|
unsigned char FAR * outbuf; |
| 605 |
|
|
long outbuflen; |
| 606 |
|
|
/* This buffer is used by the SSH protocol processing to store uncompressed |
| 607 |
|
|
packet data for compression. User data is never streamed through here; |
| 608 |
|
|
it is compressed directly from the user's buffer. */ |
| 609 |
|
|
unsigned char FAR * precompress_outbuf; |
| 610 |
|
|
long precompress_outbuflen; |
| 611 |
|
|
/* this is the length of the packet data, including the type header */ |
| 612 |
|
|
long outgoing_packet_len; |
| 613 |
|
|
|
| 614 |
|
|
/* This buffer is used by the SSH protocol processing to store decompressed |
| 615 |
|
|
packet data. User data is never streamed through here; it is decompressed |
| 616 |
|
|
directly to the user's buffer. */ |
| 617 |
|
|
unsigned char FAR * postdecompress_inbuf; |
| 618 |
|
|
long postdecompress_inbuflen; |
| 619 |
|
|
|
| 620 |
|
|
unsigned char FAR * payload; |
| 621 |
|
|
long payload_grabbed; |
| 622 |
|
|
long payloadlen; |
| 623 |
|
|
long payload_datastart; |
| 624 |
|
|
long payload_datalen; |
| 625 |
|
|
|
| 626 |
|
|
uint32 receiver_sequence_number; |
| 627 |
|
|
uint32 sender_sequence_number; |
| 628 |
|
|
|
| 629 |
|
|
z_stream compress_stream; |
| 630 |
|
|
z_stream decompress_stream; |
| 631 |
|
|
BOOL compressing; |
| 632 |
|
|
BOOL decompressing; |
| 633 |
|
|
int compression_level; |
| 634 |
|
|
|
| 635 |
|
|
SSHPacketHandlerItem FAR * packet_handlers[256]; |
| 636 |
|
|
int status_flags; |
| 637 |
|
|
|
| 638 |
|
|
int win_cols; |
| 639 |
|
|
int win_rows; |
| 640 |
|
|
|
| 641 |
|
|
unsigned short tcpport; |
| 642 |
|
|
} SSHState; |
| 643 |
|
|
|
| 644 |
|
|
#define STATUS_DONT_SEND_USER_NAME 0x01 |
| 645 |
|
|
#define STATUS_EXPECTING_COMPRESSION_RESPONSE 0x02 |
| 646 |
|
|
#define STATUS_DONT_SEND_CREDENTIALS 0x04 |
| 647 |
|
|
#define STATUS_HOST_OK 0x08 |
| 648 |
|
|
#define STATUS_INTERACTIVE 0x10 |
| 649 |
|
|
#define STATUS_IN_PARTIAL_ID_STRING 0x20 |
| 650 |
|
|
|
| 651 |
|
|
void SSH_init(PTInstVar pvar); |
| 652 |
|
|
void SSH_open(PTInstVar pvar); |
| 653 |
|
|
void SSH_notify_disconnecting(PTInstVar pvar, char FAR * reason); |
| 654 |
|
|
/* SSH_handle_server_ID returns TRUE iff a valid ID string has been |
| 655 |
|
|
received. If it returns FALSE, we need to keep looking for another |
| 656 |
|
|
ID string. */ |
| 657 |
|
|
BOOL SSH_handle_server_ID(PTInstVar pvar, char FAR * ID, int ID_len); |
| 658 |
|
|
/* SSH_handle_packet requires NO PAYLOAD on entry. |
| 659 |
|
|
'len' is the size of the packet: payload + padding (+ CRC for SSHv1) |
| 660 |
|
|
'padding' is the size of the padding. |
| 661 |
|
|
'data' points to the start of the packet data (the length field) |
| 662 |
|
|
*/ |
| 663 |
|
|
void SSH_handle_packet(PTInstVar pvar, char FAR * data, int len, int padding); |
| 664 |
|
|
void SSH_notify_win_size(PTInstVar pvar, int cols, int rows); |
| 665 |
|
|
void SSH_notify_user_name(PTInstVar pvar); |
| 666 |
|
|
void SSH_notify_cred(PTInstVar pvar); |
| 667 |
|
|
void SSH_notify_host_OK(PTInstVar pvar); |
| 668 |
|
|
void SSH_send(PTInstVar pvar, unsigned char const FAR * buf, unsigned int buflen); |
| 669 |
|
|
/* SSH_extract_payload returns number of bytes extracted */ |
| 670 |
|
|
int SSH_extract_payload(PTInstVar pvar, unsigned char FAR * dest, int len); |
| 671 |
|
|
void SSH_end(PTInstVar pvar); |
| 672 |
|
|
|
| 673 |
|
|
void SSH_get_server_ID_info(PTInstVar pvar, char FAR * dest, int len); |
| 674 |
|
|
void SSH_get_protocol_version_info(PTInstVar pvar, char FAR * dest, int len); |
| 675 |
|
|
void SSH_get_compression_info(PTInstVar pvar, char FAR * dest, int len); |
| 676 |
maya |
6144 |
void SSH_get_mac_info(PTInstVar pvar, char FAR * dest, int len); |
| 677 |
maya |
3227 |
|
| 678 |
|
|
/* len must be <= SSH_MAX_SEND_PACKET_SIZE */ |
| 679 |
|
|
void SSH_channel_send(PTInstVar pvar, int channel_num, |
| 680 |
|
|
uint32 remote_channel_num, |
| 681 |
yutakapon |
5039 |
unsigned char FAR * buf, int len, int retry); |
| 682 |
maya |
3227 |
void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num); |
| 683 |
|
|
void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num); |
| 684 |
|
|
void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num); |
| 685 |
|
|
void SSH_channel_input_eof(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num); |
| 686 |
maya |
3808 |
void SSH_request_forwarding(PTInstVar pvar, char FAR * bind_address, int from_server_port, |
| 687 |
|
|
char FAR * to_local_host, int to_local_port); |
| 688 |
maya |
4987 |
void SSH_cancel_request_forwarding(PTInstVar pvar, char FAR * bind_address, int from_server_port, int reply); |
| 689 |
maya |
3227 |
void SSH_request_X11_forwarding(PTInstVar pvar, |
| 690 |
|
|
char FAR * auth_protocol, unsigned char FAR * auth_data, int auth_data_len, int screen_num); |
| 691 |
|
|
void SSH_open_channel(PTInstVar pvar, uint32 local_channel_num, |
| 692 |
|
|
char FAR * to_remote_host, int to_remote_port, |
| 693 |
|
|
char FAR * originator, unsigned short originator_port); |
| 694 |
|
|
|
| 695 |
|
|
int SSH_start_scp(PTInstVar pvar, char *sendfile, char *dstfile); |
| 696 |
|
|
int SSH_start_scp_receive(PTInstVar pvar, char *filename); |
| 697 |
|
|
int SSH_scp_transaction(PTInstVar pvar, char *sendfile, char *dstfile, enum scp_dir direction); |
| 698 |
|
|
int SSH_sftp_transaction(PTInstVar pvar); |
| 699 |
|
|
|
| 700 |
|
|
/* auxiliary SSH2 interfaces for pkt.c */ |
| 701 |
|
|
int SSH_get_min_packet_size(PTInstVar pvar); |
| 702 |
|
|
/* data is guaranteed to be at least SSH_get_min_packet_size bytes long |
| 703 |
|
|
at least 5 bytes must be decrypted */ |
| 704 |
|
|
void SSH_predecrpyt_packet(PTInstVar pvar, char FAR * data); |
| 705 |
|
|
int SSH_get_clear_MAC_size(PTInstVar pvar); |
| 706 |
|
|
|
| 707 |
|
|
#define SSH_is_any_payload(pvar) ((pvar)->ssh_state.payload_datalen > 0) |
| 708 |
|
|
#define SSH_get_host_name(pvar) ((pvar)->ssh_state.hostname) |
| 709 |
|
|
#define SSH_get_compression_level(pvar) ((pvar)->ssh_state.compressing ? (pvar)->ts_SSH_CompressionLevel : 0) |
| 710 |
|
|
|
| 711 |
|
|
void SSH2_send_kexinit(PTInstVar pvar); |
| 712 |
|
|
BOOL do_SSH2_userauth(PTInstVar pvar); |
| 713 |
|
|
BOOL do_SSH2_authrequest(PTInstVar pvar); |
| 714 |
|
|
void debug_print(int no, char *msg, int len); |
| 715 |
|
|
int get_cipher_block_size(SSHCipher cipher); |
| 716 |
|
|
int get_cipher_key_len(SSHCipher cipher); |
| 717 |
yutakapon |
5545 |
SSHCipher get_cipher_by_name(char *name); |
| 718 |
maya |
4378 |
char* get_kex_algorithm_name(kex_algorithm kextype); |
| 719 |
maya |
3227 |
const EVP_CIPHER* get_cipher_EVP_CIPHER(SSHCipher cipher); |
| 720 |
maya |
4378 |
const EVP_MD* get_kex_algorithm_EVP_MD(kex_algorithm kextype); |
| 721 |
|
|
char* get_ssh2_mac_name(hmac_type type); |
| 722 |
|
|
const EVP_MD* get_ssh2_mac_EVP_MD(hmac_type type); |
| 723 |
|
|
int get_ssh2_mac_truncatebits(hmac_type type); |
| 724 |
|
|
char* get_ssh2_comp_name(compression_type type); |
| 725 |
|
|
char* get_ssh_keytype_name(ssh_keytype type); |
| 726 |
maya |
6120 |
char* get_digest_algorithm_name(digest_algorithm id); |
| 727 |
maya |
3227 |
int get_cipher_discard_len(SSHCipher cipher); |
| 728 |
|
|
void ssh_heartbeat_lock_initialize(void); |
| 729 |
|
|
void ssh_heartbeat_lock_finalize(void); |
| 730 |
|
|
void ssh_heartbeat_lock(void); |
| 731 |
|
|
void ssh_heartbeat_unlock(void); |
| 732 |
|
|
void halt_ssh_heartbeat_thread(PTInstVar pvar); |
| 733 |
|
|
void ssh2_channel_free(void); |
| 734 |
|
|
BOOL handle_SSH2_userauth_inforeq(PTInstVar pvar); |
| 735 |
yutakapon |
4152 |
BOOL handle_SSH2_userauth_passwd_changereq(PTInstVar pvar); |
| 736 |
maya |
3227 |
void SSH2_update_compression_myproposal(PTInstVar pvar); |
| 737 |
|
|
void SSH2_update_cipher_myproposal(PTInstVar pvar); |
| 738 |
yutakapon |
4367 |
void SSH2_update_kex_myproposal(PTInstVar pvar); |
| 739 |
|
|
void SSH2_update_host_key_myproposal(PTInstVar pvar); |
| 740 |
|
|
void SSH2_update_hmac_myproposal(PTInstVar pvar); |
| 741 |
yutakapon |
4106 |
int SSH_notify_break_signal(PTInstVar pvar); |
| 742 |
maya |
3227 |
|
| 743 |
yutakapon |
4926 |
/// |
| 744 |
|
|
enum scp_state { |
| 745 |
|
|
SCP_INIT, SCP_TIMESTAMP, SCP_FILEINFO, SCP_DATA, SCP_CLOSING, |
| 746 |
|
|
}; |
| 747 |
|
|
|
| 748 |
|
|
typedef struct bufchain { |
| 749 |
|
|
buffer_t *msg; |
| 750 |
|
|
struct bufchain *next; |
| 751 |
|
|
} bufchain_t; |
| 752 |
|
|
|
| 753 |
|
|
typedef struct scp { |
| 754 |
|
|
enum scp_dir dir; // transfer direction |
| 755 |
|
|
enum scp_state state; // SCP state |
| 756 |
|
|
char localfile[MAX_PATH]; // local filename |
| 757 |
|
|
char localfilefull[MAX_PATH]; // local filename fullpath |
| 758 |
|
|
char remotefile[MAX_PATH]; // remote filename |
| 759 |
|
|
FILE *localfp; // file pointer for local file |
| 760 |
|
|
struct __stat64 filestat; // file status information |
| 761 |
|
|
HWND progress_window; |
| 762 |
|
|
HANDLE thread; |
| 763 |
|
|
unsigned int thread_id; |
| 764 |
|
|
PTInstVar pvar; |
| 765 |
|
|
// for receiving file |
| 766 |
|
|
long long filetotalsize; |
| 767 |
|
|
long long filercvsize; |
| 768 |
maya |
5607 |
DWORD filemtime; |
| 769 |
|
|
DWORD fileatime; |
| 770 |
yutakapon |
4926 |
} scp_t; |
| 771 |
|
|
|
| 772 |
|
|
enum sftp_state { |
| 773 |
yutakapon |
4930 |
SFTP_INIT, SFTP_CONNECTED, SFTP_REALPATH, |
| 774 |
yutakapon |
4926 |
}; |
| 775 |
|
|
|
| 776 |
|
|
typedef struct sftp { |
| 777 |
|
|
enum sftp_state state; |
| 778 |
yutakapon |
4930 |
HWND console_window; |
| 779 |
yutakapon |
4929 |
unsigned int transfer_buflen; |
| 780 |
|
|
unsigned int num_requests; |
| 781 |
|
|
unsigned int version; |
| 782 |
|
|
unsigned int msg_id; |
| 783 |
|
|
#define SFTP_EXT_POSIX_RENAME 0x00000001 |
| 784 |
|
|
#define SFTP_EXT_STATVFS 0x00000002 |
| 785 |
|
|
#define SFTP_EXT_FSTATVFS 0x00000004 |
| 786 |
|
|
#define SFTP_EXT_HARDLINK 0x00000008 |
| 787 |
|
|
unsigned int exts; |
| 788 |
|
|
unsigned long long limit_kbps; |
| 789 |
|
|
//struct bwlimit bwlimit_in, bwlimit_out; |
| 790 |
yutakapon |
4930 |
char path[1024]; |
| 791 |
yutakapon |
4926 |
} sftp_t; |
| 792 |
|
|
|
| 793 |
|
|
typedef struct channel { |
| 794 |
|
|
int used; |
| 795 |
|
|
int self_id; |
| 796 |
|
|
int remote_id; |
| 797 |
|
|
unsigned int local_window; |
| 798 |
|
|
unsigned int local_window_max; |
| 799 |
|
|
unsigned int local_consumed; |
| 800 |
|
|
unsigned int local_maxpacket; |
| 801 |
|
|
unsigned int remote_window; |
| 802 |
|
|
unsigned int remote_maxpacket; |
| 803 |
|
|
enum channel_type type; |
| 804 |
|
|
int local_num; |
| 805 |
|
|
bufchain_t *bufchain; |
| 806 |
|
|
scp_t scp; |
| 807 |
|
|
buffer_t *agent_msg; |
| 808 |
|
|
int agent_request_len; |
| 809 |
|
|
sftp_t sftp; |
| 810 |
maya |
5422 |
#define SSH_CHANNEL_STATE_CLOSE_SENT 0x00000001 |
| 811 |
|
|
unsigned int state; |
| 812 |
yutakapon |
4926 |
} Channel_t; |
| 813 |
|
|
|
| 814 |
|
|
unsigned char FAR *begin_send_packet(PTInstVar pvar, int type, int len); |
| 815 |
|
|
void finish_send_packet_special(PTInstVar pvar, int skip_compress); |
| 816 |
yutakapon |
5039 |
void SSH2_send_channel_data(PTInstVar pvar, Channel_t *c, unsigned char FAR * buf, unsigned int buflen, int retry); |
| 817 |
yutakapon |
4926 |
|
| 818 |
|
|
#define finish_send_packet(pvar) finish_send_packet_special((pvar), 0) |
| 819 |
|
|
#define get_payload_uint32(pvar, offset) get_uint32_MSBfirst((pvar)->ssh_state.payload + (offset)) |
| 820 |
|
|
#define get_uint32(buf) get_uint32_MSBfirst((buf)) |
| 821 |
|
|
#define set_uint32(buf, v) set_uint32_MSBfirst((buf), (v)) |
| 822 |
|
|
#define get_mpint_len(pvar, offset) ((get_ushort16_MSBfirst((pvar)->ssh_state.payload + (offset)) + 7) >> 3) |
| 823 |
|
|
#define get_ushort16(buf) get_ushort16_MSBfirst((buf)) |
| 824 |
|
|
/// |
| 825 |
|
|
|
| 826 |
doda |
5916 |
/* Global request confirmation callbacks */ |
| 827 |
|
|
typedef void global_confirm_cb(PTInstVar pvar, int type, unsigned int seq, void *ctx); |
| 828 |
|
|
void client_register_global_confirm(global_confirm_cb *cb, void *ctx); |
| 829 |
|
|
|
| 830 |
|
|
/* Global request success/failure callbacks */ |
| 831 |
|
|
struct global_confirm { |
| 832 |
|
|
global_confirm_cb *cb; |
| 833 |
|
|
void *ctx; |
| 834 |
|
|
int ref_count; |
| 835 |
yutakapon |
5850 |
}; |
| 836 |
|
|
|
| 837 |
maya |
3227 |
#endif |