diff options
Diffstat (limited to 'other/guess-who/ssh.h')
| -rw-r--r-- | other/guess-who/ssh.h | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/other/guess-who/ssh.h b/other/guess-who/ssh.h new file mode 100644 index 0000000..25e84e3 --- /dev/null +++ b/other/guess-who/ssh.h | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2002,2003 Sebastian Krahmer. | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * 1. Redistributions of source code must retain the above copyright | ||
| 9 | * notice, this list of conditions and the following disclaimer. | ||
| 10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer in the | ||
| 12 | * documentation and/or other materials provided with the distribution. | ||
| 13 | * 3. All advertising materials mentioning features or use of this software | ||
| 14 | * must display the following acknowledgement: | ||
| 15 | * This product includes software developed by Sebastian Krahmer. | ||
| 16 | * 4. The name Sebastian Krahmer may not be used to endorse or promote | ||
| 17 | * products derived from this software without specific prior written | ||
| 18 | * permission. | ||
| 19 | * | ||
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY | ||
| 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE | ||
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | * SUCH DAMAGE. | ||
| 31 | */ | ||
| 32 | #ifndef __ssh_h__ | ||
| 33 | #define __ssh_h__ | ||
| 34 | |||
| 35 | #include <stdio.h> | ||
| 36 | #include <sys/types.h> | ||
| 37 | #include <string> | ||
| 38 | |||
| 39 | extern "C" { | ||
| 40 | #include <openssl/des.h> | ||
| 41 | }; | ||
| 42 | #include <pthread.h> | ||
| 43 | |||
| 44 | |||
| 45 | #define SSH_MSG_DISCONNECT 1 | ||
| 46 | #define SSH_MSG_IGNORE 2 | ||
| 47 | #define SSH_MSG_UNIMPLEMENTED 3 | ||
| 48 | #define SSH_MSG_DEBUG 4 | ||
| 49 | #define SSH_MSG_SERVICE_REQUEST 5 | ||
| 50 | #define SSH_MSG_SERVICE_ACCEPT 6 | ||
| 51 | |||
| 52 | |||
| 53 | #define SSH_MSG_KEXINIT 20 | ||
| 54 | #define SSH_MSG_NEWKEYS 21 | ||
| 55 | |||
| 56 | #define SSH_MSG_KEXDH_INIT 30 | ||
| 57 | #define SSH_MSG_KEXDH_REPLY 31 | ||
| 58 | |||
| 59 | #define SSH_MSG_KEX_DH_GEX_REQUEST_OLD 30 | ||
| 60 | #define SSH_MSG_KEX_DH_GEX_GROUP 31 | ||
| 61 | #define SSH_MSG_KEX_DH_GEX_INIT 32 | ||
| 62 | #define SSH_MSG_KEX_DH_GEX_REPLY 33 | ||
| 63 | #define SSH_MSG_KEX_DH_GEX_REQUEST 34 | ||
| 64 | |||
| 65 | #define SSH_MSG_USERAUTH_REQUEST 50 | ||
| 66 | #define SSH_MSG_USERAUTH_FAILURE 51 | ||
| 67 | #define SSH_MSG_USERAUTH_SUCCESS 52 | ||
| 68 | #define SSH_MSG_USERAUTH_BANNER 53 | ||
| 69 | |||
| 70 | |||
| 71 | #define SSH_MSG_USERAUTH_PK_OK 60 | ||
| 72 | #define SSH_MSG_USERAUTH_PASSWD_CHANGEREQ 60 | ||
| 73 | #define SSH_MSG_USERAUTH_INFO_REQUEST 60 | ||
| 74 | #define SSH_MSG_USERAUTH_INFO_RESPONSE 61 | ||
| 75 | |||
| 76 | |||
| 77 | class SSH2 { | ||
| 78 | private: | ||
| 79 | // socket | ||
| 80 | int peer; | ||
| 81 | |||
| 82 | // packet Seq No. | ||
| 83 | u_int32_t seq; | ||
| 84 | |||
| 85 | // whether crypto is already enabled | ||
| 86 | bool use_crypto; | ||
| 87 | std::string error; | ||
| 88 | |||
| 89 | // the shared secret which is output of DH exchange | ||
| 90 | unsigned char *shared_secret; | ||
| 91 | char d_banner[128]; | ||
| 92 | int shared_secret_len; | ||
| 93 | |||
| 94 | // The keys for sending and receiving respectively | ||
| 95 | des_key_schedule s_key1; | ||
| 96 | des_key_schedule s_key2; | ||
| 97 | des_key_schedule s_key3; | ||
| 98 | |||
| 99 | des_key_schedule r_key1; | ||
| 100 | des_key_schedule r_key2; | ||
| 101 | des_key_schedule r_key3; | ||
| 102 | |||
| 103 | // The IV's for sending and receiving | ||
| 104 | des_cblock s_iv; | ||
| 105 | des_cblock r_iv; | ||
| 106 | |||
| 107 | // mac keys for MAC computation; sedning+receiving | ||
| 108 | unsigned char s_mac[20], r_mac[20]; | ||
| 109 | |||
| 110 | // Data to hash to get session_id | ||
| 111 | unsigned char *to_hash; | ||
| 112 | size_t to_hash_len; | ||
| 113 | |||
| 114 | // could be larger, but we use just SHA1 | ||
| 115 | unsigned char session_id[20]; | ||
| 116 | |||
| 117 | int debug; | ||
| 118 | |||
| 119 | int derive_keys(); | ||
| 120 | |||
| 121 | int hash_helper(const char *, unsigned char[20], unsigned char[20], bool); | ||
| 122 | |||
| 123 | protected: | ||
| 124 | int packet_write(const void *, size_t); | ||
| 125 | |||
| 126 | int packet_read(unsigned char *plain_buf, size_t pblen, size_t *n); | ||
| 127 | public: | ||
| 128 | SSH2() : seq(0), use_crypto(0), | ||
| 129 | shared_secret(NULL), to_hash(NULL), to_hash_len(0), debug(0) {} | ||
| 130 | |||
| 131 | ~SSH2() { free(to_hash); delete [] shared_secret; } | ||
| 132 | |||
| 133 | const char *why() { return error.c_str(); } | ||
| 134 | |||
| 135 | const char *banner() { return d_banner; } | ||
| 136 | |||
| 137 | int set_socket(int s) {peer = s; return s; } | ||
| 138 | |||
| 139 | int get_socket() { return peer; } | ||
| 140 | |||
| 141 | int banner_exchange(); | ||
| 142 | |||
| 143 | int kex_init(); | ||
| 144 | |||
| 145 | int dh_exchange(); | ||
| 146 | |||
| 147 | int newkeys(); | ||
| 148 | |||
| 149 | int doit() {return 0; } | ||
| 150 | |||
| 151 | int userauth_passwd(const char *, const char *); | ||
| 152 | |||
| 153 | int userauth_pubkey(const char *user, const char *keyfile); | ||
| 154 | }; | ||
| 155 | |||
| 156 | |||
| 157 | #endif | ||
| 158 | |||
| 159 | |||
| 160 | |||
