1 /* Written by Markus Friedl. Placed in the public domain. */
9 struct ssh
*active_state
, *backup_state
;
11 /* Map old to new API */
14 ssh_packet_start(struct ssh
*ssh
, u_char type
)
18 if ((r
= sshpkt_start(ssh
, type
)) != 0)
19 fatal("%s: %s", __func__
, ssh_err(r
));
23 ssh_packet_put_char(struct ssh
*ssh
, int value
)
28 if ((r
= sshpkt_put_u8(ssh
, ch
)) != 0)
29 fatal("%s: %s", __func__
, ssh_err(r
));
33 ssh_packet_put_int(struct ssh
*ssh
, u_int value
)
37 if ((r
= sshpkt_put_u32(ssh
, value
)) != 0)
38 fatal("%s: %s", __func__
, ssh_err(r
));
42 ssh_packet_put_int64(struct ssh
*ssh
, u_int64_t value
)
46 if ((r
= sshpkt_put_u64(ssh
, value
)) != 0)
47 fatal("%s: %s", __func__
, ssh_err(r
));
51 ssh_packet_put_string(struct ssh
*ssh
, const void *buf
, u_int len
)
55 if ((r
= sshpkt_put_string(ssh
, buf
, len
)) != 0)
56 fatal("%s: %s", __func__
, ssh_err(r
));
60 ssh_packet_put_cstring(struct ssh
*ssh
, const char *str
)
64 if ((r
= sshpkt_put_cstring(ssh
, str
)) != 0)
65 fatal("%s: %s", __func__
, ssh_err(r
));
69 ssh_packet_put_raw(struct ssh
*ssh
, const void *buf
, u_int len
)
73 if ((r
= sshpkt_put(ssh
, buf
, len
)) != 0)
74 fatal("%s: %s", __func__
, ssh_err(r
));
80 ssh_packet_put_bignum2(struct ssh
*ssh
, BIGNUM
* value
)
84 if ((r
= sshpkt_put_bignum2(ssh
, value
)) != 0)
85 fatal("%s: %s", __func__
, ssh_err(r
));
88 # ifdef OPENSSL_HAS_ECC
90 ssh_packet_put_ecpoint(struct ssh
*ssh
, const EC_GROUP
*curve
,
91 const EC_POINT
*point
)
95 if ((r
= sshpkt_put_ec(ssh
, point
, curve
)) != 0)
96 fatal("%s: %s", __func__
, ssh_err(r
));
99 #endif /* WITH_OPENSSL */
102 ssh_packet_send(struct ssh
*ssh
)
106 if ((r
= sshpkt_send(ssh
)) != 0)
107 fatal("%s: %s", __func__
, ssh_err(r
));
111 ssh_packet_get_char(struct ssh
*ssh
)
116 if ((r
= sshpkt_get_u8(ssh
, &ch
)) != 0)
117 fatal("%s: %s", __func__
, ssh_err(r
));
122 ssh_packet_get_int(struct ssh
*ssh
)
127 if ((r
= sshpkt_get_u32(ssh
, &val
)) != 0)
128 fatal("%s: %s", __func__
, ssh_err(r
));
133 ssh_packet_get_int64(struct ssh
*ssh
)
138 if ((r
= sshpkt_get_u64(ssh
, &val
)) != 0)
139 fatal("%s: %s", __func__
, ssh_err(r
));
146 ssh_packet_get_bignum2(struct ssh
*ssh
, BIGNUM
* value
)
150 if ((r
= sshpkt_get_bignum2(ssh
, value
)) != 0)
151 fatal("%s: %s", __func__
, ssh_err(r
));
154 # ifdef OPENSSL_HAS_ECC
156 ssh_packet_get_ecpoint(struct ssh
*ssh
, const EC_GROUP
*curve
, EC_POINT
*point
)
160 if ((r
= sshpkt_get_ec(ssh
, point
, curve
)) != 0)
161 fatal("%s: %s", __func__
, ssh_err(r
));
164 #endif /* WITH_OPENSSL */
167 ssh_packet_get_string(struct ssh
*ssh
, u_int
*length_ptr
)
173 if ((r
= sshpkt_get_string(ssh
, &val
, &len
)) != 0)
174 fatal("%s: %s", __func__
, ssh_err(r
));
175 if (length_ptr
!= NULL
)
176 *length_ptr
= (u_int
)len
;
181 ssh_packet_get_string_ptr(struct ssh
*ssh
, u_int
*length_ptr
)
187 if ((r
= sshpkt_get_string_direct(ssh
, &val
, &len
)) != 0)
188 fatal("%s: %s", __func__
, ssh_err(r
));
189 if (length_ptr
!= NULL
)
190 *length_ptr
= (u_int
)len
;
195 ssh_packet_get_cstring(struct ssh
*ssh
, u_int
*length_ptr
)
201 if ((r
= sshpkt_get_cstring(ssh
, &val
, &len
)) != 0)
202 fatal("%s: %s", __func__
, ssh_err(r
));
203 if (length_ptr
!= NULL
)
204 *length_ptr
= (u_int
)len
;
208 /* Old API, that had to be reimplemented */
211 packet_set_connection(int fd_in
, int fd_out
)
213 active_state
= ssh_packet_set_connection(active_state
, fd_in
, fd_out
);
214 if (active_state
== NULL
)
215 fatal("%s: ssh_packet_set_connection failed", __func__
);
219 packet_get_char(void)
221 return (ssh_packet_get_char(active_state
));
227 return (ssh_packet_get_int(active_state
));
231 packet_read_seqnr(u_int32_t
*seqnr
)
236 if ((r
= ssh_packet_read_seqnr(active_state
, &type
, seqnr
)) != 0)
237 sshpkt_fatal(active_state
, __func__
, r
);
242 packet_read_poll_seqnr(u_int32_t
*seqnr
)
247 if ((r
= ssh_packet_read_poll_seqnr(active_state
, &type
, seqnr
)))
248 sshpkt_fatal(active_state
, __func__
, r
);
255 ssh_packet_close(active_state
);
260 packet_process_incoming(const char *buf
, u_int len
)
264 if ((r
= ssh_packet_process_incoming(active_state
, buf
, len
)) != 0)
265 sshpkt_fatal(active_state
, __func__
, r
);
269 packet_write_wait(void)
273 if ((r
= ssh_packet_write_wait(active_state
)) != 0)
274 sshpkt_fatal(active_state
, __func__
, r
);
278 packet_write_poll(void)
282 if ((r
= ssh_packet_write_poll(active_state
)) != 0)
283 sshpkt_fatal(active_state
, __func__
, r
);
287 packet_read_expect(int expected_type
)
291 if ((r
= ssh_packet_read_expect(active_state
, expected_type
)) != 0)
292 sshpkt_fatal(active_state
, __func__
, r
);
296 packet_disconnect(const char *fmt
, ...)
302 vsnprintf(buf
, sizeof(buf
), fmt
, args
);
304 ssh_packet_disconnect(active_state
, "%s", buf
);
308 packet_send_debug(const char *fmt
, ...)
314 vsnprintf(buf
, sizeof(buf
), fmt
, args
);
316 ssh_packet_send_debug(active_state
, "%s", buf
);