blob: f8edf851c210b5c3d3e383d3d6b09308ef945f9a [file] [log] [blame]
Damien Millerce986542013-07-18 16:12:44 +10001/* $OpenBSD: packet.h,v 1.59 2013/07/12 00:19:59 djm Exp $ */
Ben Lindstrom05764b92002-03-05 01:53:02 +00002
Damien Millerd4a8b7e1999-10-27 13:42:43 +10003/*
Damien Miller95def091999-11-25 00:26:21 +11004 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11005 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11007 * Interface for the packet protocol functions.
Damien Miller4af51302000-04-16 11:18:38 +10008 *
Damien Millere4340be2000-09-16 13:29:08 +11009 * 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 Miller95def091999-11-25 00:26:21 +110014 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016#ifndef PACKET_H
17#define PACKET_H
18
Damien Miller99bd21e2006-03-15 11:11:28 +110019#include <termios.h>
20
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021#include <openssl/bn.h>
Darren Tucker8ccb7392010-09-10 12:28:24 +100022#ifdef OPENSSL_HAS_ECC
Damien Millereb8b60e2010-08-31 22:41:14 +100023#include <openssl/ec.h>
Darren Tucker8ccb7392010-09-10 12:28:24 +100024#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100025
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000026void packet_set_connection(int, int);
Darren Tucker3fc464e2008-06-13 06:42:45 +100027void packet_set_timeout(int, int);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000028void packet_set_nonblocking(void);
29int packet_get_connection_in(void);
30int packet_get_connection_out(void);
31void packet_close(void);
32void packet_set_encryption_key(const u_char *, u_int, int);
Ben Lindstrom402c6cc2002-06-21 00:43:42 +000033u_int packet_get_encryption_key(u_char *);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000034void packet_set_protocol_flags(u_int);
35u_int packet_get_protocol_flags(void);
36void packet_start_compression(int);
Damien Miller0dac6fb2010-11-20 15:19:38 +110037void packet_set_interactive(int, int, int);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000038int packet_is_interactive(void);
Damien Miller9786e6e2005-07-26 21:54:56 +100039void packet_set_server(void);
40void packet_set_authenticated(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100041
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000042void packet_start(u_char);
43void packet_put_char(int ch);
44void packet_put_int(u_int value);
Darren Tucker761c3892009-06-21 18:16:26 +100045void packet_put_int64(u_int64_t value);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000046void packet_put_bignum(BIGNUM * value);
47void packet_put_bignum2(BIGNUM * value);
Darren Tucker8ccb7392010-09-10 12:28:24 +100048#ifdef OPENSSL_HAS_ECC
Damien Millereb8b60e2010-08-31 22:41:14 +100049void packet_put_ecpoint(const EC_GROUP *, const EC_POINT *);
Darren Tucker8ccb7392010-09-10 12:28:24 +100050#endif
Damien Miller5a6b4fe2001-12-21 14:56:54 +110051void packet_put_string(const void *buf, u_int len);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000052void packet_put_cstring(const char *str);
Damien Miller5a6b4fe2001-12-21 14:56:54 +110053void packet_put_raw(const void *buf, u_int len);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000054void packet_send(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100055
Damien Millerdff50992002-01-22 23:16:32 +110056int packet_read(void);
57void packet_read_expect(int type);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000058void packet_process_incoming(const char *buf, u_int len);
Damien Millerdff50992002-01-22 23:16:32 +110059int packet_read_seqnr(u_int32_t *seqnr_p);
60int packet_read_poll_seqnr(u_int32_t *seqnr_p);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100061
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000062u_int packet_get_char(void);
63u_int packet_get_int(void);
Darren Tucker761c3892009-06-21 18:16:26 +100064u_int64_t packet_get_int64(void);
Damien Millerd432ccf2002-01-22 23:14:44 +110065void packet_get_bignum(BIGNUM * value);
66void packet_get_bignum2(BIGNUM * value);
Darren Tucker8ccb7392010-09-10 12:28:24 +100067#ifdef OPENSSL_HAS_ECC
Damien Millereb8b60e2010-08-31 22:41:14 +100068void packet_get_ecpoint(const EC_GROUP *, EC_POINT *);
Darren Tucker8ccb7392010-09-10 12:28:24 +100069#endif
Damien Millereccb9de2005-06-17 12:59:34 +100070void *packet_get_raw(u_int *length_ptr);
Damien Miller5a6b4fe2001-12-21 14:56:54 +110071void *packet_get_string(u_int *length_ptr);
Damien Millerda108ec2010-08-31 22:36:39 +100072char *packet_get_cstring(u_int *length_ptr);
Damien Millerdb255ca2008-05-19 14:59:37 +100073void *packet_get_string_ptr(u_int *length_ptr);
Damien Millerce986542013-07-18 16:12:44 +100074void packet_disconnect(const char *fmt,...) __attribute__((noreturn)) __attribute__((format(printf, 1, 2)));
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000075void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
Damien Millerd4a8b7e1999-10-27 13:42:43 +100076
Ben Lindstromf6027d32002-03-22 01:42:04 +000077void set_newkeys(int mode);
78int packet_get_keyiv_len(int);
79void packet_get_keyiv(int, u_char *, u_int);
80int packet_get_keycontext(int, u_char *);
81void packet_set_keycontext(int, u_char *);
Damien Millerb61f3fc2008-07-11 17:36:48 +100082void packet_get_state(int, u_int32_t *, u_int64_t *, u_int32_t *, u_int64_t *);
83void packet_set_state(int, u_int32_t, u_int64_t, u_int32_t, u_int64_t);
Ben Lindstromf6027d32002-03-22 01:42:04 +000084int packet_get_ssh1_cipher(void);
85void packet_set_iv(int, u_char *);
Darren Tuckerf7288d72009-06-21 18:12:20 +100086void *packet_get_newkeys(int);
Ben Lindstromf6027d32002-03-22 01:42:04 +000087
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000088void packet_write_poll(void);
89void packet_write_wait(void);
90int packet_have_data_to_write(void);
91int packet_not_very_much_data_to_write(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100092
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000093int packet_connection_is_on_socket(void);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000094int packet_remaining(void);
95void packet_send_ignore(int);
Damien Miller9f643902001-11-12 11:02:52 +110096void packet_add_padding(u_char);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100097
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000098void tty_make_modes(int, struct termios *);
99void tty_parse_modes(int, int *);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000100
Darren Tuckerf7288d72009-06-21 18:12:20 +1000101void packet_set_alive_timeouts(int);
102int packet_inc_alive_timeouts(void);
Darren Tucker1f8311c2004-05-13 16:39:33 +1000103int packet_set_maxsize(u_int);
Darren Tuckerf7288d72009-06-21 18:12:20 +1000104u_int packet_get_maxsize(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000105
Damien Miller48b03fc2002-01-22 23:11:40 +1100106/* don't allow remaining bytes after the end of the message */
107#define packet_check_eom() \
Damien Miller4af51302000-04-16 11:18:38 +1000108do { \
109 int _len = packet_remaining(); \
110 if (_len > 0) { \
Damien Miller996acd22003-04-09 20:59:48 +1000111 logit("Packet integrity error (%d bytes remaining) at %s:%d", \
Damien Miller4af51302000-04-16 11:18:38 +1000112 _len ,__FILE__, __LINE__); \
113 packet_disconnect("Packet integrity error."); \
114 } \
115} while (0)
116
Damien Millera5539d22003-04-09 20:50:06 +1000117int packet_need_rekeying(void);
Darren Tuckerc53c2af2013-05-16 20:28:16 +1000118void packet_set_rekey_limits(u_int32_t, time_t);
119time_t packet_get_rekey_timeout(void);
Damien Millera5539d22003-04-09 20:50:06 +1000120
Darren Tuckere841eb02009-07-06 07:11:13 +1000121void packet_backup_state(void);
122void packet_restore_state(void);
123
Darren Tuckerf7288d72009-06-21 18:12:20 +1000124void *packet_get_input(void);
125void *packet_get_output(void);
126
Damien Miller95def091999-11-25 00:26:21 +1100127#endif /* PACKET_H */