summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in2
-rw-r--r--dispatch.h9
-rw-r--r--opacket.c321
-rw-r--r--opacket.h154
4 files changed, 2 insertions, 484 deletions
diff --git a/Makefile.in b/Makefile.in
index 6ffccb482..2d2de7b49 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -88,7 +88,7 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
88 canohost.o channels.o cipher.o cipher-aes.o cipher-aesctr.o \ 88 canohost.o channels.o cipher.o cipher-aes.o cipher-aesctr.o \
89 cipher-ctr.o cleanup.o \ 89 cipher-ctr.o cleanup.o \
90 compat.o crc32.o fatal.o hostfile.o \ 90 compat.o crc32.o fatal.o hostfile.o \
91 log.o match.o moduli.o nchan.o packet.o opacket.o \ 91 log.o match.o moduli.o nchan.o packet.o \
92 readpass.o ttymodes.o xmalloc.o addrmatch.o \ 92 readpass.o ttymodes.o xmalloc.o addrmatch.o \
93 atomicio.o dispatch.o mac.o uuencode.o misc.o utf8.o \ 93 atomicio.o dispatch.o mac.o uuencode.o misc.o utf8.o \
94 monitor_fdpass.o rijndael.o ssh-dss.o ssh-ecdsa.o ssh-rsa.o dh.o \ 94 monitor_fdpass.o rijndael.o ssh-dss.o ssh-ecdsa.o ssh-rsa.o dh.o \
diff --git a/dispatch.h b/dispatch.h
index 17a6f3db6..a22d7749f 100644
--- a/dispatch.h
+++ b/dispatch.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dispatch.h,v 1.14 2017/05/31 07:00:13 markus Exp $ */ 1/* $OpenBSD: dispatch.h,v 1.15 2019/01/19 21:45:31 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -46,11 +46,4 @@ void ssh_dispatch_range(struct ssh *, u_int, u_int, dispatch_fn *);
46int ssh_dispatch_run(struct ssh *, int, volatile sig_atomic_t *); 46int ssh_dispatch_run(struct ssh *, int, volatile sig_atomic_t *);
47void ssh_dispatch_run_fatal(struct ssh *, int, volatile sig_atomic_t *); 47void ssh_dispatch_run_fatal(struct ssh *, int, volatile sig_atomic_t *);
48 48
49#define dispatch_init(dflt) \
50 ssh_dispatch_init(active_state, (dflt))
51#define dispatch_range(from, to, fn) \
52 ssh_dispatch_range(active_state, (from), (to), (fn))
53#define dispatch_set(type, fn) \
54 ssh_dispatch_set(active_state, (type), (fn))
55
56#endif 49#endif
diff --git a/opacket.c b/opacket.c
deleted file mode 100644
index e5ccf8099..000000000
--- a/opacket.c
+++ /dev/null
@@ -1,321 +0,0 @@
1/* $OpenBSD: opacket.c,v 1.9 2019/01/19 21:33:14 djm Exp $ */
2/* Written by Markus Friedl. Placed in the public domain. */
3
4#include "includes.h"
5/* $OpenBSD: opacket.c,v 1.8 2019/01/19 21:31:32 djm Exp $ */
6#include <stdarg.h>
7
8#include "ssherr.h"
9#include "packet.h"
10#include "opacket.h" /* XXX */
11#include "log.h"
12
13struct ssh *active_state, *backup_state;
14
15/* Map old to new API */
16
17void
18ssh_packet_start(struct ssh *ssh, u_char type)
19{
20 int r;
21
22 if ((r = sshpkt_start(ssh, type)) != 0)
23 fatal("%s: %s", __func__, ssh_err(r));
24}
25
26void
27ssh_packet_put_char(struct ssh *ssh, int value)
28{
29 u_char ch = value;
30 int r;
31
32 if ((r = sshpkt_put_u8(ssh, ch)) != 0)
33 fatal("%s: %s", __func__, ssh_err(r));
34}
35
36void
37ssh_packet_put_int(struct ssh *ssh, u_int value)
38{
39 int r;
40
41 if ((r = sshpkt_put_u32(ssh, value)) != 0)
42 fatal("%s: %s", __func__, ssh_err(r));
43}
44
45void
46ssh_packet_put_int64(struct ssh *ssh, u_int64_t value)
47{
48 int r;
49
50 if ((r = sshpkt_put_u64(ssh, value)) != 0)
51 fatal("%s: %s", __func__, ssh_err(r));
52}
53
54void
55ssh_packet_put_string(struct ssh *ssh, const void *buf, u_int len)
56{
57 int r;
58
59 if ((r = sshpkt_put_string(ssh, buf, len)) != 0)
60 fatal("%s: %s", __func__, ssh_err(r));
61}
62
63void
64ssh_packet_put_cstring(struct ssh *ssh, const char *str)
65{
66 int r;
67
68 if ((r = sshpkt_put_cstring(ssh, str)) != 0)
69 fatal("%s: %s", __func__, ssh_err(r));
70}
71
72void
73ssh_packet_put_raw(struct ssh *ssh, const void *buf, u_int len)
74{
75 int r;
76
77 if ((r = sshpkt_put(ssh, buf, len)) != 0)
78 fatal("%s: %s", __func__, ssh_err(r));
79}
80
81
82#ifdef WITH_OPENSSL
83void
84ssh_packet_put_bignum2(struct ssh *ssh, BIGNUM * value)
85{
86 int r;
87
88 if ((r = sshpkt_put_bignum2(ssh, value)) != 0)
89 fatal("%s: %s", __func__, ssh_err(r));
90}
91
92# ifdef OPENSSL_HAS_ECC
93void
94ssh_packet_put_ecpoint(struct ssh *ssh, const EC_GROUP *curve,
95 const EC_POINT *point)
96{
97 int r;
98
99 if ((r = sshpkt_put_ec(ssh, point, curve)) != 0)
100 fatal("%s: %s", __func__, ssh_err(r));
101}
102# endif
103#endif /* WITH_OPENSSL */
104
105void
106ssh_packet_send(struct ssh *ssh)
107{
108 int r;
109
110 if ((r = sshpkt_send(ssh)) != 0)
111 fatal("%s: %s", __func__, ssh_err(r));
112}
113
114u_int
115ssh_packet_get_char(struct ssh *ssh)
116{
117 u_char ch;
118 int r;
119
120 if ((r = sshpkt_get_u8(ssh, &ch)) != 0)
121 fatal("%s: %s", __func__, ssh_err(r));
122 return ch;
123}
124
125u_int
126ssh_packet_get_int(struct ssh *ssh)
127{
128 u_int val;
129 int r;
130
131 if ((r = sshpkt_get_u32(ssh, &val)) != 0)
132 fatal("%s: %s", __func__, ssh_err(r));
133 return val;
134}
135
136u_int64_t
137ssh_packet_get_int64(struct ssh *ssh)
138{
139 u_int64_t val;
140 int r;
141
142 if ((r = sshpkt_get_u64(ssh, &val)) != 0)
143 fatal("%s: %s", __func__, ssh_err(r));
144 return val;
145}
146
147
148#ifdef WITH_OPENSSL
149void
150ssh_packet_get_bignum2(struct ssh *ssh, BIGNUM * value)
151{
152 int r;
153
154 if ((r = sshpkt_get_bignum2(ssh, value)) != 0)
155 fatal("%s: %s", __func__, ssh_err(r));
156}
157
158# ifdef OPENSSL_HAS_ECC
159void
160ssh_packet_get_ecpoint(struct ssh *ssh, const EC_GROUP *curve, EC_POINT *point)
161{
162 int r;
163
164 if ((r = sshpkt_get_ec(ssh, point, curve)) != 0)
165 fatal("%s: %s", __func__, ssh_err(r));
166}
167# endif
168#endif /* WITH_OPENSSL */
169
170void *
171ssh_packet_get_string(struct ssh *ssh, u_int *length_ptr)
172{
173 int r;
174 size_t len;
175 u_char *val;
176
177 if ((r = sshpkt_get_string(ssh, &val, &len)) != 0)
178 fatal("%s: %s", __func__, ssh_err(r));
179 if (length_ptr != NULL)
180 *length_ptr = (u_int)len;
181 return val;
182}
183
184const void *
185ssh_packet_get_string_ptr(struct ssh *ssh, u_int *length_ptr)
186{
187 int r;
188 size_t len;
189 const u_char *val;
190
191 if ((r = sshpkt_get_string_direct(ssh, &val, &len)) != 0)
192 fatal("%s: %s", __func__, ssh_err(r));
193 if (length_ptr != NULL)
194 *length_ptr = (u_int)len;
195 return val;
196}
197
198char *
199ssh_packet_get_cstring(struct ssh *ssh, u_int *length_ptr)
200{
201 int r;
202 size_t len;
203 char *val;
204
205 if ((r = sshpkt_get_cstring(ssh, &val, &len)) != 0)
206 fatal("%s: %s", __func__, ssh_err(r));
207 if (length_ptr != NULL)
208 *length_ptr = (u_int)len;
209 return val;
210}
211
212/* Old API, that had to be reimplemented */
213
214void
215packet_set_connection(int fd_in, int fd_out)
216{
217 active_state = ssh_packet_set_connection(active_state, fd_in, fd_out);
218 if (active_state == NULL)
219 fatal("%s: ssh_packet_set_connection failed", __func__);
220}
221
222u_int
223packet_get_char(void)
224{
225 return (ssh_packet_get_char(active_state));
226}
227
228u_int
229packet_get_int(void)
230{
231 return (ssh_packet_get_int(active_state));
232}
233
234int
235packet_read_seqnr(u_int32_t *seqnr)
236{
237 u_char type;
238 int r;
239
240 if ((r = ssh_packet_read_seqnr(active_state, &type, seqnr)) != 0)
241 sshpkt_fatal(active_state, r, "%s", __func__);
242 return type;
243}
244
245int
246packet_read_poll_seqnr(u_int32_t *seqnr)
247{
248 u_char type;
249 int r;
250
251 if ((r = ssh_packet_read_poll_seqnr(active_state, &type, seqnr)))
252 sshpkt_fatal(active_state, r, "%s", __func__);
253 return type;
254}
255
256void
257packet_close(void)
258{
259 ssh_packet_close(active_state);
260 active_state = NULL;
261}
262
263void
264packet_process_incoming(const char *buf, u_int len)
265{
266 int r;
267
268 if ((r = ssh_packet_process_incoming(active_state, buf, len)) != 0)
269 sshpkt_fatal(active_state, r, "%s", __func__);
270}
271
272void
273packet_write_wait(void)
274{
275 int r;
276
277 if ((r = ssh_packet_write_wait(active_state)) != 0)
278 sshpkt_fatal(active_state, r, "%s", __func__);
279}
280
281void
282packet_write_poll(void)
283{
284 int r;
285
286 if ((r = ssh_packet_write_poll(active_state)) != 0)
287 sshpkt_fatal(active_state, r, "%s", __func__);
288}
289
290void
291packet_read_expect(int expected_type)
292{
293 int r;
294
295 if ((r = ssh_packet_read_expect(active_state, expected_type)) != 0)
296 sshpkt_fatal(active_state, r, "%s", __func__);
297}
298
299void
300packet_disconnect(const char *fmt, ...)
301{
302 char buf[1024];
303 va_list args;
304
305 va_start(args, fmt);
306 vsnprintf(buf, sizeof(buf), fmt, args);
307 va_end(args);
308 ssh_packet_disconnect(active_state, "%s", buf);
309}
310
311void
312packet_send_debug(const char *fmt, ...)
313{
314 char buf[1024];
315 va_list args;
316
317 va_start(args, fmt);
318 vsnprintf(buf, sizeof(buf), fmt, args);
319 va_end(args);
320 ssh_packet_send_debug(active_state, "%s", buf);
321}
diff --git a/opacket.h b/opacket.h
deleted file mode 100644
index f92fe586e..000000000
--- a/opacket.h
+++ /dev/null
@@ -1,154 +0,0 @@
1/* $OpenBSD: opacket.h,v 1.13 2018/07/06 09:03:02 sf Exp $ */
2#ifndef _OPACKET_H
3/* Written by Markus Friedl. Placed in the public domain. */
4
5/* Map old to new API */
6void ssh_packet_start(struct ssh *, u_char);
7void ssh_packet_put_char(struct ssh *, int ch);
8void ssh_packet_put_int(struct ssh *, u_int value);
9void ssh_packet_put_int64(struct ssh *, u_int64_t value);
10void ssh_packet_put_bignum2(struct ssh *, BIGNUM * value);
11void ssh_packet_put_ecpoint(struct ssh *, const EC_GROUP *, const EC_POINT *);
12void ssh_packet_put_string(struct ssh *, const void *buf, u_int len);
13void ssh_packet_put_cstring(struct ssh *, const char *str);
14void ssh_packet_put_raw(struct ssh *, const void *buf, u_int len);
15void ssh_packet_send(struct ssh *);
16
17u_int ssh_packet_get_char(struct ssh *);
18u_int ssh_packet_get_int(struct ssh *);
19u_int64_t ssh_packet_get_int64(struct ssh *);
20void ssh_packet_get_bignum2(struct ssh *, BIGNUM * value);
21void ssh_packet_get_ecpoint(struct ssh *, const EC_GROUP *, EC_POINT *);
22void *ssh_packet_get_string(struct ssh *, u_int *length_ptr);
23char *ssh_packet_get_cstring(struct ssh *, u_int *length_ptr);
24
25/* don't allow remaining bytes after the end of the message */
26#define ssh_packet_check_eom(ssh) \
27do { \
28 int _len = ssh_packet_remaining(ssh); \
29 if (_len > 0) { \
30 logit("Packet integrity error (%d bytes remaining) at %s:%d", \
31 _len ,__FILE__, __LINE__); \
32 ssh_packet_disconnect(ssh, \
33 "Packet integrity error."); \
34 } \
35} while (0)
36
37/* old API */
38void packet_close(void);
39u_int packet_get_char(void);
40u_int packet_get_int(void);
41void packet_set_connection(int, int);
42int packet_read_seqnr(u_int32_t *);
43int packet_read_poll_seqnr(u_int32_t *);
44void packet_process_incoming(const char *buf, u_int len);
45void packet_write_wait(void);
46void packet_write_poll(void);
47void packet_read_expect(int expected_type);
48#define packet_set_timeout(timeout, count) \
49 ssh_packet_set_timeout(active_state, (timeout), (count))
50#define packet_connection_is_on_socket() \
51 ssh_packet_connection_is_on_socket(active_state)
52#define packet_set_nonblocking() \
53 ssh_packet_set_nonblocking(active_state)
54#define packet_get_connection_in() \
55 ssh_packet_get_connection_in(active_state)
56#define packet_get_connection_out() \
57 ssh_packet_get_connection_out(active_state)
58#define packet_set_protocol_flags(protocol_flags) \
59 ssh_packet_set_protocol_flags(active_state, (protocol_flags))
60#define packet_get_protocol_flags() \
61 ssh_packet_get_protocol_flags(active_state)
62#define packet_start(type) \
63 ssh_packet_start(active_state, (type))
64#define packet_put_char(value) \
65 ssh_packet_put_char(active_state, (value))
66#define packet_put_int(value) \
67 ssh_packet_put_int(active_state, (value))
68#define packet_put_int64(value) \
69 ssh_packet_put_int64(active_state, (value))
70#define packet_put_string( buf, len) \
71 ssh_packet_put_string(active_state, (buf), (len))
72#define packet_put_cstring(str) \
73 ssh_packet_put_cstring(active_state, (str))
74#define packet_put_raw(buf, len) \
75 ssh_packet_put_raw(active_state, (buf), (len))
76#define packet_put_bignum2(value) \
77 ssh_packet_put_bignum2(active_state, (value))
78#define packet_send() \
79 ssh_packet_send(active_state)
80#define packet_read() \
81 ssh_packet_read(active_state)
82#define packet_get_int64() \
83 ssh_packet_get_int64(active_state)
84#define packet_get_bignum2(value) \
85 ssh_packet_get_bignum2(active_state, (value))
86#define packet_remaining() \
87 ssh_packet_remaining(active_state)
88#define packet_get_string(length_ptr) \
89 ssh_packet_get_string(active_state, (length_ptr))
90#define packet_get_string_ptr(length_ptr) \
91 ssh_packet_get_string_ptr(active_state, (length_ptr))
92#define packet_get_cstring(length_ptr) \
93 ssh_packet_get_cstring(active_state, (length_ptr))
94void packet_send_debug(const char *, ...)
95 __attribute__((format(printf, 1, 2)));
96void packet_disconnect(const char *, ...)
97 __attribute__((format(printf, 1, 2)))
98 __attribute__((noreturn));
99#define packet_have_data_to_write() \
100 ssh_packet_have_data_to_write(active_state)
101#define packet_not_very_much_data_to_write() \
102 ssh_packet_not_very_much_data_to_write(active_state)
103#define packet_set_interactive(interactive, qos_interactive, qos_bulk) \
104 ssh_packet_set_interactive(active_state, (interactive), (qos_interactive), (qos_bulk))
105#define packet_is_interactive() \
106 ssh_packet_is_interactive(active_state)
107#define packet_set_maxsize(s) \
108 ssh_packet_set_maxsize(active_state, (s))
109#define packet_inc_alive_timeouts() \
110 ssh_packet_inc_alive_timeouts(active_state)
111#define packet_set_alive_timeouts(ka) \
112 ssh_packet_set_alive_timeouts(active_state, (ka))
113#define packet_get_maxsize() \
114 ssh_packet_get_maxsize(active_state)
115#define packet_add_padding(pad) \
116 sshpkt_add_padding(active_state, (pad))
117#define packet_send_ignore(nbytes) \
118 ssh_packet_send_ignore(active_state, (nbytes))
119#define packet_set_server() \
120 ssh_packet_set_server(active_state)
121#define packet_set_authenticated() \
122 ssh_packet_set_authenticated(active_state)
123#define packet_get_input() \
124 ssh_packet_get_input(active_state)
125#define packet_get_output() \
126 ssh_packet_get_output(active_state)
127#define packet_check_eom() \
128 ssh_packet_check_eom(active_state)
129#define set_newkeys(mode) \
130 ssh_set_newkeys(active_state, (mode))
131#define packet_get_state(m) \
132 ssh_packet_get_state(active_state, m)
133#define packet_set_state(m) \
134 ssh_packet_set_state(active_state, m)
135#define packet_get_raw(lenp) \
136 sshpkt_ptr(active_state, lenp)
137#define packet_get_ecpoint(c,p) \
138 ssh_packet_get_ecpoint(active_state, c, p)
139#define packet_put_ecpoint(c,p) \
140 ssh_packet_put_ecpoint(active_state, c, p)
141#define packet_get_rekey_timeout() \
142 ssh_packet_get_rekey_timeout(active_state)
143#define packet_set_rekey_limits(x,y) \
144 ssh_packet_set_rekey_limits(active_state, x, y)
145#define packet_get_bytes(x,y) \
146 ssh_packet_get_bytes(active_state, x, y)
147#define packet_set_mux() \
148 ssh_packet_set_mux(active_state)
149#define packet_get_mux() \
150 ssh_packet_get_mux(active_state)
151#define packet_clear_keys() \
152 ssh_packet_clear_keys(active_state)
153
154#endif /* _OPACKET_H */