Damien Miller | ce98654 | 2013-07-18 16:12:44 +1000 | [diff] [blame] | 1 | /* $OpenBSD: packet.h,v 1.59 2013/07/12 00:19:59 djm Exp $ */ |
Ben Lindstrom | 05764b9 | 2002-03-05 01:53:02 +0000 | [diff] [blame] | 2 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 3 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 5 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 6 | * All rights reserved |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 7 | * Interface for the packet protocol functions. |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 8 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 9 | * As far as I am concerned, the code I have written for this software |
| 10 | * can be used freely for any purpose. Any derived versions of this |
| 11 | * software must be clearly marked as such, and if the derived work is |
| 12 | * incompatible with the protocol description in the RFC file, it must be |
| 13 | * called by a name other than "ssh" or "Secure Shell". |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 14 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 15 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 16 | #ifndef PACKET_H |
| 17 | #define PACKET_H |
| 18 | |
Damien Miller | 99bd21e | 2006-03-15 11:11:28 +1100 | [diff] [blame] | 19 | #include <termios.h> |
| 20 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 21 | #include <openssl/bn.h> |
Darren Tucker | 8ccb739 | 2010-09-10 12:28:24 +1000 | [diff] [blame] | 22 | #ifdef OPENSSL_HAS_ECC |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 23 | #include <openssl/ec.h> |
Darren Tucker | 8ccb739 | 2010-09-10 12:28:24 +1000 | [diff] [blame] | 24 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 25 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 26 | void packet_set_connection(int, int); |
Darren Tucker | 3fc464e | 2008-06-13 06:42:45 +1000 | [diff] [blame] | 27 | void packet_set_timeout(int, int); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 28 | void packet_set_nonblocking(void); |
| 29 | int packet_get_connection_in(void); |
| 30 | int packet_get_connection_out(void); |
| 31 | void packet_close(void); |
| 32 | void packet_set_encryption_key(const u_char *, u_int, int); |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 33 | u_int packet_get_encryption_key(u_char *); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 34 | void packet_set_protocol_flags(u_int); |
| 35 | u_int packet_get_protocol_flags(void); |
| 36 | void packet_start_compression(int); |
Damien Miller | 0dac6fb | 2010-11-20 15:19:38 +1100 | [diff] [blame] | 37 | void packet_set_interactive(int, int, int); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 38 | int packet_is_interactive(void); |
Damien Miller | 9786e6e | 2005-07-26 21:54:56 +1000 | [diff] [blame] | 39 | void packet_set_server(void); |
| 40 | void packet_set_authenticated(void); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 41 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 42 | void packet_start(u_char); |
| 43 | void packet_put_char(int ch); |
| 44 | void packet_put_int(u_int value); |
Darren Tucker | 761c389 | 2009-06-21 18:16:26 +1000 | [diff] [blame] | 45 | void packet_put_int64(u_int64_t value); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 46 | void packet_put_bignum(BIGNUM * value); |
| 47 | void packet_put_bignum2(BIGNUM * value); |
Darren Tucker | 8ccb739 | 2010-09-10 12:28:24 +1000 | [diff] [blame] | 48 | #ifdef OPENSSL_HAS_ECC |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 49 | void packet_put_ecpoint(const EC_GROUP *, const EC_POINT *); |
Darren Tucker | 8ccb739 | 2010-09-10 12:28:24 +1000 | [diff] [blame] | 50 | #endif |
Damien Miller | 5a6b4fe | 2001-12-21 14:56:54 +1100 | [diff] [blame] | 51 | void packet_put_string(const void *buf, u_int len); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 52 | void packet_put_cstring(const char *str); |
Damien Miller | 5a6b4fe | 2001-12-21 14:56:54 +1100 | [diff] [blame] | 53 | void packet_put_raw(const void *buf, u_int len); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 54 | void packet_send(void); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 55 | |
Damien Miller | dff5099 | 2002-01-22 23:16:32 +1100 | [diff] [blame] | 56 | int packet_read(void); |
| 57 | void packet_read_expect(int type); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 58 | void packet_process_incoming(const char *buf, u_int len); |
Damien Miller | dff5099 | 2002-01-22 23:16:32 +1100 | [diff] [blame] | 59 | int packet_read_seqnr(u_int32_t *seqnr_p); |
| 60 | int packet_read_poll_seqnr(u_int32_t *seqnr_p); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 61 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 62 | u_int packet_get_char(void); |
| 63 | u_int packet_get_int(void); |
Darren Tucker | 761c389 | 2009-06-21 18:16:26 +1000 | [diff] [blame] | 64 | u_int64_t packet_get_int64(void); |
Damien Miller | d432ccf | 2002-01-22 23:14:44 +1100 | [diff] [blame] | 65 | void packet_get_bignum(BIGNUM * value); |
| 66 | void packet_get_bignum2(BIGNUM * value); |
Darren Tucker | 8ccb739 | 2010-09-10 12:28:24 +1000 | [diff] [blame] | 67 | #ifdef OPENSSL_HAS_ECC |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 68 | void packet_get_ecpoint(const EC_GROUP *, EC_POINT *); |
Darren Tucker | 8ccb739 | 2010-09-10 12:28:24 +1000 | [diff] [blame] | 69 | #endif |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 70 | void *packet_get_raw(u_int *length_ptr); |
Damien Miller | 5a6b4fe | 2001-12-21 14:56:54 +1100 | [diff] [blame] | 71 | void *packet_get_string(u_int *length_ptr); |
Damien Miller | da108ec | 2010-08-31 22:36:39 +1000 | [diff] [blame] | 72 | char *packet_get_cstring(u_int *length_ptr); |
Damien Miller | db255ca | 2008-05-19 14:59:37 +1000 | [diff] [blame] | 73 | void *packet_get_string_ptr(u_int *length_ptr); |
Damien Miller | ce98654 | 2013-07-18 16:12:44 +1000 | [diff] [blame] | 74 | void packet_disconnect(const char *fmt,...) __attribute__((noreturn)) __attribute__((format(printf, 1, 2))); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 75 | void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 76 | |
Ben Lindstrom | f6027d3 | 2002-03-22 01:42:04 +0000 | [diff] [blame] | 77 | void set_newkeys(int mode); |
| 78 | int packet_get_keyiv_len(int); |
| 79 | void packet_get_keyiv(int, u_char *, u_int); |
| 80 | int packet_get_keycontext(int, u_char *); |
| 81 | void packet_set_keycontext(int, u_char *); |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 82 | void packet_get_state(int, u_int32_t *, u_int64_t *, u_int32_t *, u_int64_t *); |
| 83 | void packet_set_state(int, u_int32_t, u_int64_t, u_int32_t, u_int64_t); |
Ben Lindstrom | f6027d3 | 2002-03-22 01:42:04 +0000 | [diff] [blame] | 84 | int packet_get_ssh1_cipher(void); |
| 85 | void packet_set_iv(int, u_char *); |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 86 | void *packet_get_newkeys(int); |
Ben Lindstrom | f6027d3 | 2002-03-22 01:42:04 +0000 | [diff] [blame] | 87 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 88 | void packet_write_poll(void); |
| 89 | void packet_write_wait(void); |
| 90 | int packet_have_data_to_write(void); |
| 91 | int packet_not_very_much_data_to_write(void); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 92 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 93 | int packet_connection_is_on_socket(void); |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 94 | int packet_remaining(void); |
| 95 | void packet_send_ignore(int); |
Damien Miller | 9f64390 | 2001-11-12 11:02:52 +1100 | [diff] [blame] | 96 | void packet_add_padding(u_char); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 97 | |
Ben Lindstrom | 4cc240d | 2001-07-04 04:46:56 +0000 | [diff] [blame] | 98 | void tty_make_modes(int, struct termios *); |
| 99 | void tty_parse_modes(int, int *); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 100 | |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 101 | void packet_set_alive_timeouts(int); |
| 102 | int packet_inc_alive_timeouts(void); |
Darren Tucker | 1f8311c | 2004-05-13 16:39:33 +1000 | [diff] [blame] | 103 | int packet_set_maxsize(u_int); |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 104 | u_int packet_get_maxsize(void); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 105 | |
Damien Miller | 48b03fc | 2002-01-22 23:11:40 +1100 | [diff] [blame] | 106 | /* don't allow remaining bytes after the end of the message */ |
| 107 | #define packet_check_eom() \ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 108 | do { \ |
| 109 | int _len = packet_remaining(); \ |
| 110 | if (_len > 0) { \ |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 111 | logit("Packet integrity error (%d bytes remaining) at %s:%d", \ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 112 | _len ,__FILE__, __LINE__); \ |
| 113 | packet_disconnect("Packet integrity error."); \ |
| 114 | } \ |
| 115 | } while (0) |
| 116 | |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 117 | int packet_need_rekeying(void); |
Darren Tucker | c53c2af | 2013-05-16 20:28:16 +1000 | [diff] [blame] | 118 | void packet_set_rekey_limits(u_int32_t, time_t); |
| 119 | time_t packet_get_rekey_timeout(void); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 120 | |
Darren Tucker | e841eb0 | 2009-07-06 07:11:13 +1000 | [diff] [blame] | 121 | void packet_backup_state(void); |
| 122 | void packet_restore_state(void); |
| 123 | |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 124 | void *packet_get_input(void); |
| 125 | void *packet_get_output(void); |
| 126 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 127 | #endif /* PACKET_H */ |