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