summaryrefslogtreecommitdiff
path: root/packet.h
diff options
context:
space:
mode:
authormarkus@openbsd.org <markus@openbsd.org>2015-01-19 19:52:16 +0000
committerDamien Miller <djm@mindrot.org>2015-01-20 09:13:01 +1100
commit091c302829210c41e7f57c3f094c7b9c054306f0 (patch)
tree800de5dc85b877a85d1f269ae5bb09b0dc3fa7a7 /packet.h
parent4e62cc68ce4ba20245d208b252e74e91d3785b74 (diff)
upstream commit
update packet.c & isolate, introduce struct ssh a) switch packet.c to buffer api and isolate per-connection info into struct ssh b) (de)serialization of the state is moved from monitor to packet.c c) the old packet.c API is implemented in opacket.[ch] d) compress.c/h is removed and integrated into packet.c with and ok djm@
Diffstat (limited to 'packet.h')
-rw-r--r--packet.h240
1 files changed, 138 insertions, 102 deletions
diff --git a/packet.h b/packet.h
index e7b5fcba9..0d691979c 100644
--- a/packet.h
+++ b/packet.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.h,v 1.61 2014/05/03 17:20:34 markus Exp $ */ 1/* $OpenBSD: packet.h,v 1.62 2015/01/19 19:52:16 markus Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -18,111 +18,147 @@
18 18
19#include <termios.h> 19#include <termios.h>
20 20
21#include <openssl/bn.h> 21#ifdef WITH_OPENSSL
22#ifdef OPENSSL_HAS_ECC 22# include <openssl/bn.h>
23#include <openssl/ec.h> 23# ifdef OPENSSL_HAS_ECC
24# include <openssl/ec.h>
25# endif
24#endif 26#endif
25 27#include <sys/signal.h>
26void packet_set_connection(int, int); 28#include <sys/queue.h>
27void packet_set_timeout(int, int); 29
28void packet_set_nonblocking(void); 30struct kex;
29int packet_get_connection_in(void); 31struct sshkey;
30int packet_get_connection_out(void); 32struct sshbuf;
31void packet_close(void); 33struct session_state; /* private session data */
32void packet_set_encryption_key(const u_char *, u_int, int); 34
33u_int packet_get_encryption_key(u_char *); 35struct ssh {
34void packet_set_protocol_flags(u_int); 36 /* Session state */
35u_int packet_get_protocol_flags(void); 37 struct session_state *state;
36void packet_start_compression(int); 38
37void packet_set_interactive(int, int, int); 39 /* Key exchange */
38int packet_is_interactive(void); 40 struct kex *kex;
39void packet_set_server(void); 41
40void packet_set_authenticated(void); 42 /* cached remote ip address and port*/
41 43 char *remote_ipaddr;
42void packet_start(u_char); 44 int remote_port;
43void packet_put_char(int ch); 45
44void packet_put_int(u_int value); 46 /* datafellows */
45void packet_put_int64(u_int64_t value); 47 int compat;
46void packet_put_bignum(BIGNUM * value); 48};
47void packet_put_bignum2(BIGNUM * value); 49
48#ifdef OPENSSL_HAS_ECC 50struct ssh *ssh_alloc_session_state(void);
49void packet_put_ecpoint(const EC_GROUP *, const EC_POINT *); 51struct ssh *ssh_packet_set_connection(struct ssh *, int, int);
50#endif 52void ssh_packet_set_timeout(struct ssh *, int, int);
51void packet_put_string(const void *buf, u_int len); 53int ssh_packet_stop_discard(struct ssh *);
52void packet_put_cstring(const char *str); 54int ssh_packet_connection_af(struct ssh *);
53void packet_put_raw(const void *buf, u_int len); 55void ssh_packet_set_nonblocking(struct ssh *);
54void packet_send(void); 56int ssh_packet_get_connection_in(struct ssh *);
55 57int ssh_packet_get_connection_out(struct ssh *);
56int packet_read(void); 58void ssh_packet_close(struct ssh *);
57void packet_read_expect(int type); 59void ssh_packet_set_encryption_key(struct ssh *, const u_char *, u_int, int);
58void packet_process_incoming(const char *buf, u_int len); 60void ssh_packet_set_protocol_flags(struct ssh *, u_int);
59int packet_read_seqnr(u_int32_t *seqnr_p); 61u_int ssh_packet_get_protocol_flags(struct ssh *);
60int packet_read_poll_seqnr(u_int32_t *seqnr_p); 62int ssh_packet_start_compression(struct ssh *, int);
61 63void ssh_packet_set_tos(struct ssh *, int);
62u_int packet_get_char(void); 64void ssh_packet_set_interactive(struct ssh *, int, int, int);
63u_int packet_get_int(void); 65int ssh_packet_is_interactive(struct ssh *);
64u_int64_t packet_get_int64(void); 66void ssh_packet_set_server(struct ssh *);
65void packet_get_bignum(BIGNUM * value); 67void ssh_packet_set_authenticated(struct ssh *);
66void packet_get_bignum2(BIGNUM * value); 68
67#ifdef OPENSSL_HAS_ECC 69int ssh_packet_send1(struct ssh *);
68void packet_get_ecpoint(const EC_GROUP *, EC_POINT *); 70int ssh_packet_send2_wrapped(struct ssh *);
69#endif 71int ssh_packet_send2(struct ssh *);
70void *packet_get_raw(u_int *length_ptr); 72
71void *packet_get_string(u_int *length_ptr); 73int ssh_packet_read(struct ssh *);
72char *packet_get_cstring(u_int *length_ptr); 74void ssh_packet_read_expect(struct ssh *, int type);
73const void *packet_get_string_ptr(u_int *length_ptr); 75int ssh_packet_read_poll(struct ssh *);
74void packet_disconnect(const char *fmt,...) __attribute__((noreturn)) __attribute__((format(printf, 1, 2))); 76int ssh_packet_read_poll1(struct ssh *, u_char *);
75void packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); 77int ssh_packet_read_poll2(struct ssh *, u_char *, u_int32_t *seqnr_p);
76 78void ssh_packet_process_incoming(struct ssh *, const char *buf, u_int len);
77void set_newkeys(int mode); 79int ssh_packet_read_seqnr(struct ssh *, u_char *, u_int32_t *seqnr_p);
78int packet_get_keyiv_len(int); 80int ssh_packet_read_poll_seqnr(struct ssh *, u_char *, u_int32_t *seqnr_p);
79void packet_get_keyiv(int, u_char *, u_int); 81
80int packet_get_keycontext(int, u_char *); 82const void *ssh_packet_get_string_ptr(struct ssh *, u_int *length_ptr);
81void packet_set_keycontext(int, u_char *); 83void ssh_packet_disconnect(struct ssh *, const char *fmt, ...)
82void packet_get_state(int, u_int32_t *, u_int64_t *, u_int32_t *, u_int64_t *); 84 __attribute__((format(printf, 2, 3)))
83void packet_set_state(int, u_int32_t, u_int64_t, u_int32_t, u_int64_t); 85 __attribute__((noreturn));
84int packet_get_ssh1_cipher(void); 86void ssh_packet_send_debug(struct ssh *, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
85void packet_set_iv(int, u_char *); 87
86void *packet_get_newkeys(int); 88int ssh_set_newkeys(struct ssh *, int mode);
87 89void ssh_packet_get_bytes(struct ssh *, u_int64_t *, u_int64_t *);
88void packet_write_poll(void); 90
89void packet_write_wait(void); 91typedef void *(ssh_packet_comp_alloc_func)(void *, u_int, u_int);
90int packet_have_data_to_write(void); 92typedef void (ssh_packet_comp_free_func)(void *, void *);
91int packet_not_very_much_data_to_write(void); 93void ssh_packet_set_compress_hooks(struct ssh *, void *,
92 94 ssh_packet_comp_alloc_func *, ssh_packet_comp_free_func *);
93int packet_connection_is_on_socket(void); 95
94int packet_remaining(void); 96void ssh_packet_write_poll(struct ssh *);
95void packet_send_ignore(int); 97void ssh_packet_write_wait(struct ssh *);
96void packet_add_padding(u_char); 98int ssh_packet_have_data_to_write(struct ssh *);
99int ssh_packet_not_very_much_data_to_write(struct ssh *);
100
101int ssh_packet_connection_is_on_socket(struct ssh *);
102int ssh_packet_remaining(struct ssh *);
103void ssh_packet_send_ignore(struct ssh *, int);
97 104
98void tty_make_modes(int, struct termios *); 105void tty_make_modes(int, struct termios *);
99void tty_parse_modes(int, int *); 106void tty_parse_modes(int, int *);
100 107
101void packet_set_alive_timeouts(int); 108void ssh_packet_set_alive_timeouts(struct ssh *, int);
102int packet_inc_alive_timeouts(void); 109int ssh_packet_inc_alive_timeouts(struct ssh *);
103int packet_set_maxsize(u_int); 110int ssh_packet_set_maxsize(struct ssh *, u_int);
104u_int packet_get_maxsize(void); 111u_int ssh_packet_get_maxsize(struct ssh *);
105 112
106/* don't allow remaining bytes after the end of the message */ 113int ssh_packet_get_state(struct ssh *, struct sshbuf *);
107#define packet_check_eom() \ 114int ssh_packet_set_state(struct ssh *, struct sshbuf *);
108do { \ 115
109 int _len = packet_remaining(); \ 116const char *ssh_remote_ipaddr(struct ssh *);
110 if (_len > 0) { \ 117
111 logit("Packet integrity error (%d bytes remaining) at %s:%d", \ 118int ssh_packet_need_rekeying(struct ssh *);
112 _len ,__FILE__, __LINE__); \ 119void ssh_packet_set_rekey_limits(struct ssh *, u_int32_t, time_t);
113 packet_disconnect("Packet integrity error."); \ 120time_t ssh_packet_get_rekey_timeout(struct ssh *);
114 } \ 121
115} while (0) 122/* XXX FIXME */
116 123void ssh_packet_backup_state(struct ssh *, struct ssh *);
117int packet_need_rekeying(void); 124void ssh_packet_restore_state(struct ssh *, struct ssh *);
118void packet_set_rekey_limits(u_int32_t, time_t); 125
119time_t packet_get_rekey_timeout(void); 126void *ssh_packet_get_input(struct ssh *);
120 127void *ssh_packet_get_output(struct ssh *);
121void packet_backup_state(void); 128
122void packet_restore_state(void); 129/* new API */
123void packet_set_postauth(void); 130int sshpkt_start(struct ssh *ssh, u_char type);
124 131int sshpkt_send(struct ssh *ssh);
125void *packet_get_input(void); 132int sshpkt_disconnect(struct ssh *, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
126void *packet_get_output(void); 133int sshpkt_add_padding(struct ssh *, u_char);
134
135int sshpkt_put(struct ssh *ssh, const void *v, size_t len);
136int sshpkt_putb(struct ssh *ssh, const struct sshbuf *b);
137int sshpkt_put_u8(struct ssh *ssh, u_char val);
138int sshpkt_put_u32(struct ssh *ssh, u_int32_t val);
139int sshpkt_put_u64(struct ssh *ssh, u_int64_t val);
140int sshpkt_put_string(struct ssh *ssh, const void *v, size_t len);
141int sshpkt_put_cstring(struct ssh *ssh, const void *v);
142int sshpkt_put_stringb(struct ssh *ssh, const struct sshbuf *v);
143int sshpkt_put_ec(struct ssh *ssh, const EC_POINT *v, const EC_GROUP *g);
144int sshpkt_put_bignum1(struct ssh *ssh, const BIGNUM *v);
145int sshpkt_put_bignum2(struct ssh *ssh, const BIGNUM *v);
146
147int sshpkt_get(struct ssh *ssh, void *valp, size_t len);
148int sshpkt_get_u8(struct ssh *ssh, u_char *valp);
149int sshpkt_get_u32(struct ssh *ssh, u_int32_t *valp);
150int sshpkt_get_u64(struct ssh *ssh, u_int64_t *valp);
151int sshpkt_get_string(struct ssh *ssh, u_char **valp, size_t *lenp);
152int sshpkt_get_string_direct(struct ssh *ssh, const u_char **valp, size_t *lenp);
153int sshpkt_get_cstring(struct ssh *ssh, char **valp, size_t *lenp);
154int sshpkt_get_ec(struct ssh *ssh, EC_POINT *v, const EC_GROUP *g);
155int sshpkt_get_bignum1(struct ssh *ssh, BIGNUM *v);
156int sshpkt_get_bignum2(struct ssh *ssh, BIGNUM *v);
157int sshpkt_get_end(struct ssh *ssh);
158const u_char *sshpkt_ptr(struct ssh *, size_t *lenp);
159
160/* OLD API */
161extern struct ssh *active_state;
162#include "opacket.h"
127 163
128#endif /* PACKET_H */ 164#endif /* PACKET_H */