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
));
79 ssh_packet_put_bignum(struct ssh
*ssh
, BIGNUM
* value
)
83 if ((r
= sshpkt_put_bignum1(ssh
, value
)) != 0)
84 fatal("%s: %s", __func__
, ssh_err(r
));
90 ssh_packet_put_bignum2(struct ssh
*ssh
, BIGNUM
* value
)
94 if ((r
= sshpkt_put_bignum2(ssh
, value
)) != 0)
95 fatal("%s: %s", __func__
, ssh_err(r
));
98 # ifdef OPENSSL_HAS_ECC
100 ssh_packet_put_ecpoint(struct ssh
*ssh
, const EC_GROUP
*curve
,
101 const EC_POINT
*point
)
105 if ((r
= sshpkt_put_ec(ssh
, point
, curve
)) != 0)
106 fatal("%s: %s", __func__
, ssh_err(r
));
109 #endif /* WITH_OPENSSL */
112 ssh_packet_send(struct ssh
*ssh
)
116 if ((r
= sshpkt_send(ssh
)) != 0)
117 fatal("%s: %s", __func__
, ssh_err(r
));
121 ssh_packet_get_char(struct ssh
*ssh
)
126 if ((r
= sshpkt_get_u8(ssh
, &ch
)) != 0)
127 fatal("%s: %s", __func__
, ssh_err(r
));
132 ssh_packet_get_int(struct ssh
*ssh
)
137 if ((r
= sshpkt_get_u32(ssh
, &val
)) != 0)
138 fatal("%s: %s", __func__
, ssh_err(r
));
143 ssh_packet_get_int64(struct ssh
*ssh
)
148 if ((r
= sshpkt_get_u64(ssh
, &val
)) != 0)
149 fatal("%s: %s", __func__
, ssh_err(r
));
155 ssh_packet_get_bignum(struct ssh
*ssh
, BIGNUM
* value
)
159 if ((r
= sshpkt_get_bignum1(ssh
, value
)) != 0)
160 fatal("%s: %s", __func__
, ssh_err(r
));
166 ssh_packet_get_bignum2(struct ssh
*ssh
, BIGNUM
* value
)
170 if ((r
= sshpkt_get_bignum2(ssh
, value
)) != 0)
171 fatal("%s: %s", __func__
, ssh_err(r
));
174 # ifdef OPENSSL_HAS_ECC
176 ssh_packet_get_ecpoint(struct ssh
*ssh
, const EC_GROUP
*curve
, EC_POINT
*point
)
180 if ((r
= sshpkt_get_ec(ssh
, point
, curve
)) != 0)
181 fatal("%s: %s", __func__
, ssh_err(r
));
184 #endif /* WITH_OPENSSL */
187 ssh_packet_get_string(struct ssh
*ssh
, u_int
*length_ptr
)
193 if ((r
= sshpkt_get_string(ssh
, &val
, &len
)) != 0)
194 fatal("%s: %s", __func__
, ssh_err(r
));
195 if (length_ptr
!= NULL
)
196 *length_ptr
= (u_int
)len
;
201 ssh_packet_get_string_ptr(struct ssh
*ssh
, u_int
*length_ptr
)
207 if ((r
= sshpkt_get_string_direct(ssh
, &val
, &len
)) != 0)
208 fatal("%s: %s", __func__
, ssh_err(r
));
209 if (length_ptr
!= NULL
)
210 *length_ptr
= (u_int
)len
;
215 ssh_packet_get_cstring(struct ssh
*ssh
, u_int
*length_ptr
)
221 if ((r
= sshpkt_get_cstring(ssh
, &val
, &len
)) != 0)
222 fatal("%s: %s", __func__
, ssh_err(r
));
223 if (length_ptr
!= NULL
)
224 *length_ptr
= (u_int
)len
;
228 /* Old API, that had to be reimplemented */
231 packet_set_connection(int fd_in
, int fd_out
)
233 active_state
= ssh_packet_set_connection(active_state
, fd_in
, fd_out
);
234 if (active_state
== NULL
)
235 fatal("%s: ssh_packet_set_connection failed", __func__
);
239 packet_get_char(void)
241 return (ssh_packet_get_char(active_state
));
247 return (ssh_packet_get_int(active_state
));
251 packet_read_seqnr(u_int32_t
*seqnr
)
256 if ((r
= ssh_packet_read_seqnr(active_state
, &type
, seqnr
)) != 0)
257 sshpkt_fatal(active_state
, __func__
, r
);
262 packet_read_poll_seqnr(u_int32_t
*seqnr
)
267 if ((r
= ssh_packet_read_poll_seqnr(active_state
, &type
, seqnr
)))
268 sshpkt_fatal(active_state
, __func__
, r
);
275 ssh_packet_close(active_state
);
280 packet_process_incoming(const char *buf
, u_int len
)
284 if ((r
= ssh_packet_process_incoming(active_state
, buf
, len
)) != 0)
285 sshpkt_fatal(active_state
, __func__
, r
);
289 packet_write_wait(void)
293 if ((r
= ssh_packet_write_wait(active_state
)) != 0)
294 sshpkt_fatal(active_state
, __func__
, r
);
298 packet_write_poll(void)
302 if ((r
= ssh_packet_write_poll(active_state
)) != 0)
303 sshpkt_fatal(active_state
, __func__
, r
);
307 packet_read_expect(int expected_type
)
311 if ((r
= ssh_packet_read_expect(active_state
, expected_type
)) != 0)
312 sshpkt_fatal(active_state
, __func__
, r
);
316 packet_disconnect(const char *fmt
, ...)
322 vsnprintf(buf
, sizeof(buf
), fmt
, args
);
324 ssh_packet_disconnect(active_state
, "%s", buf
);
328 packet_send_debug(const char *fmt
, ...)
334 vsnprintf(buf
, sizeof(buf
), fmt
, args
);
336 ssh_packet_send_debug(active_state
, "%s", buf
);