mirror of
https://github.com/clearml/dropbear
synced 2025-03-12 14:48:34 +00:00
* fix longstanding bug with connections being closed on failure to
connect to auth socket (server) * differentiate between get_byte and get_bool * get rid of some // comments * general tidying --HG-- extra : convert_revision : fb8d188ce33b6b45804a5ce51b9f601f83bdf3d7
This commit is contained in:
parent
a68755af2b
commit
f45eafe342
10
buffer.c
10
buffer.c
@ -160,6 +160,16 @@ unsigned char buf_getbyte(buffer* buf) {
|
|||||||
return buf->data[buf->pos++];
|
return buf->data[buf->pos++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get a bool from the buffer and increment the pos */
|
||||||
|
unsigned char buf_getbool(buffer* buf) {
|
||||||
|
|
||||||
|
unsigned char b;
|
||||||
|
b = buf_getbyte(buf);
|
||||||
|
if (b != 0)
|
||||||
|
b = 1;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
/* put a byte, incrementing the length if required */
|
/* put a byte, incrementing the length if required */
|
||||||
void buf_putbyte(buffer* buf, unsigned char val) {
|
void buf_putbyte(buffer* buf, unsigned char val) {
|
||||||
|
|
||||||
|
1
buffer.h
1
buffer.h
@ -50,6 +50,7 @@ void buf_setpos(buffer* buf, unsigned int pos);
|
|||||||
void buf_incrpos(buffer* buf, int incr); /* -ve is ok, to go backwards */
|
void buf_incrpos(buffer* buf, int incr); /* -ve is ok, to go backwards */
|
||||||
void buf_incrwritepos(buffer* buf, unsigned int incr);
|
void buf_incrwritepos(buffer* buf, unsigned int incr);
|
||||||
unsigned char buf_getbyte(buffer* buf);
|
unsigned char buf_getbyte(buffer* buf);
|
||||||
|
unsigned char buf_getbool(buffer* buf);
|
||||||
void buf_putbyte(buffer* buf, unsigned char val);
|
void buf_putbyte(buffer* buf, unsigned char val);
|
||||||
unsigned char* buf_getptr(buffer* buf, unsigned int len);
|
unsigned char* buf_getptr(buffer* buf, unsigned int len);
|
||||||
unsigned char* buf_getwriteptr(buffer* buf, unsigned int len);
|
unsigned char* buf_getwriteptr(buffer* buf, unsigned int len);
|
||||||
|
@ -100,7 +100,7 @@ void chaninitialise();
|
|||||||
void chancleanup();
|
void chancleanup();
|
||||||
void setchannelfds(fd_set *readfd, fd_set *writefd);
|
void setchannelfds(fd_set *readfd, fd_set *writefd);
|
||||||
void channelio(fd_set *readfd, fd_set *writefd);
|
void channelio(fd_set *readfd, fd_set *writefd);
|
||||||
struct Channel* getchannel(unsigned int chan);
|
struct Channel* getchannel();
|
||||||
struct Channel* newchannel(unsigned int remotechan,
|
struct Channel* newchannel(unsigned int remotechan,
|
||||||
const struct ChanType *type,
|
const struct ChanType *type,
|
||||||
unsigned int transwindow, unsigned int transmaxpacket);
|
unsigned int transwindow, unsigned int transmaxpacket);
|
||||||
|
@ -127,7 +127,7 @@ void recv_msg_userauth_failure() {
|
|||||||
|
|
||||||
methods = buf_getstring(ses.payload, &methlen);
|
methods = buf_getstring(ses.payload, &methlen);
|
||||||
|
|
||||||
partial = buf_getbyte(ses.payload);
|
partial = buf_getbool(ses.payload);
|
||||||
|
|
||||||
if (partial) {
|
if (partial) {
|
||||||
dropbear_log(LOG_INFO, "Authentication partially succeeded, more attempts required");
|
dropbear_log(LOG_INFO, "Authentication partially succeeded, more attempts required");
|
||||||
|
@ -33,15 +33,12 @@
|
|||||||
/* We receive channel data - only used by the client chansession code*/
|
/* We receive channel data - only used by the client chansession code*/
|
||||||
void recv_msg_channel_extended_data() {
|
void recv_msg_channel_extended_data() {
|
||||||
|
|
||||||
unsigned int chan;
|
|
||||||
struct Channel *channel;
|
struct Channel *channel;
|
||||||
unsigned int datatype;
|
unsigned int datatype;
|
||||||
|
|
||||||
TRACE(("enter recv_msg_channel_extended_data"))
|
TRACE(("enter recv_msg_channel_extended_data"))
|
||||||
|
|
||||||
chan = buf_getint(ses.payload);
|
channel = getchannel();
|
||||||
channel = getchannel(chan);
|
|
||||||
|
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
dropbear_exit("Unknown channel");
|
dropbear_exit("Unknown channel");
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ static void cli_chansessreq(struct Channel *channel) {
|
|||||||
TRACE(("enter cli_chansessreq"))
|
TRACE(("enter cli_chansessreq"))
|
||||||
|
|
||||||
type = buf_getstring(ses.payload, NULL);
|
type = buf_getstring(ses.payload, NULL);
|
||||||
wantreply = buf_getbyte(ses.payload);
|
wantreply = buf_getbool(ses.payload);
|
||||||
|
|
||||||
if (strcmp(type, "exit-status") != 0) {
|
if (strcmp(type, "exit-status") != 0) {
|
||||||
TRACE(("unknown request '%s'", type))
|
TRACE(("unknown request '%s'", type))
|
||||||
|
@ -162,8 +162,13 @@ struct Channel* newchannel(unsigned int remotechan,
|
|||||||
return newchan;
|
return newchan;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the channel structure corresponding to a channel number */
|
/* Returns the channel structure corresponding to the channel in the current
|
||||||
struct Channel* getchannel(unsigned int chan) {
|
* data packet (ses.payload must be positioned appropriately) */
|
||||||
|
struct Channel* getchannel() {
|
||||||
|
|
||||||
|
unsigned int chan;
|
||||||
|
|
||||||
|
chan = buf_getint(ses.payload);
|
||||||
if (chan >= ses.chansize || ses.channels[chan] == NULL) {
|
if (chan >= ses.chansize || ses.channels[chan] == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -474,14 +479,11 @@ void setchannelfds(fd_set *readfd, fd_set *writefd) {
|
|||||||
* etc) FD is also EOF */
|
* etc) FD is also EOF */
|
||||||
void recv_msg_channel_eof() {
|
void recv_msg_channel_eof() {
|
||||||
|
|
||||||
unsigned int chan;
|
|
||||||
struct Channel * channel;
|
struct Channel * channel;
|
||||||
|
|
||||||
TRACE(("enter recv_msg_channel_eof"))
|
TRACE(("enter recv_msg_channel_eof"))
|
||||||
|
|
||||||
chan = buf_getint(ses.payload);
|
channel = getchannel();
|
||||||
channel = getchannel(chan);
|
|
||||||
|
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
dropbear_exit("EOF for unknown channel");
|
dropbear_exit("EOF for unknown channel");
|
||||||
}
|
}
|
||||||
@ -500,15 +502,11 @@ void recv_msg_channel_eof() {
|
|||||||
/* Handle channel closure(), respond in kind and close the channels */
|
/* Handle channel closure(), respond in kind and close the channels */
|
||||||
void recv_msg_channel_close() {
|
void recv_msg_channel_close() {
|
||||||
|
|
||||||
unsigned int chan;
|
|
||||||
struct Channel * channel;
|
struct Channel * channel;
|
||||||
|
|
||||||
TRACE(("enter recv_msg_channel_close"))
|
TRACE(("enter recv_msg_channel_close"))
|
||||||
|
|
||||||
chan = buf_getint(ses.payload);
|
channel = getchannel();
|
||||||
TRACE(("close channel = %d", chan))
|
|
||||||
channel = getchannel(chan);
|
|
||||||
|
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
/* disconnect ? */
|
/* disconnect ? */
|
||||||
dropbear_exit("Close for unknown channel");
|
dropbear_exit("Close for unknown channel");
|
||||||
@ -567,14 +565,11 @@ static void deletechannel(struct Channel *channel) {
|
|||||||
* such as chansession or x11fwd */
|
* such as chansession or x11fwd */
|
||||||
void recv_msg_channel_request() {
|
void recv_msg_channel_request() {
|
||||||
|
|
||||||
unsigned int chan;
|
|
||||||
struct Channel *channel;
|
struct Channel *channel;
|
||||||
|
|
||||||
TRACE(("enter recv_msg_channel_request"))
|
TRACE(("enter recv_msg_channel_request"))
|
||||||
|
|
||||||
chan = buf_getint(ses.payload);
|
channel = getchannel();
|
||||||
channel = getchannel(chan);
|
|
||||||
|
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
/* disconnect ? */
|
/* disconnect ? */
|
||||||
dropbear_exit("Unknown channel");
|
dropbear_exit("Unknown channel");
|
||||||
@ -666,12 +661,9 @@ static void send_msg_channel_data(struct Channel *channel, int isextended,
|
|||||||
/* We receive channel data */
|
/* We receive channel data */
|
||||||
void recv_msg_channel_data() {
|
void recv_msg_channel_data() {
|
||||||
|
|
||||||
unsigned int chan;
|
|
||||||
struct Channel *channel;
|
struct Channel *channel;
|
||||||
|
|
||||||
chan = buf_getint(ses.payload);
|
channel = getchannel();
|
||||||
channel = getchannel(chan);
|
|
||||||
|
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
dropbear_exit("Unknown channel");
|
dropbear_exit("Unknown channel");
|
||||||
}
|
}
|
||||||
@ -738,13 +730,10 @@ void common_recv_msg_channel_data(struct Channel *channel, int fd,
|
|||||||
* as data is sent, and incremented upon receiving window-adjust messages */
|
* as data is sent, and incremented upon receiving window-adjust messages */
|
||||||
void recv_msg_channel_window_adjust() {
|
void recv_msg_channel_window_adjust() {
|
||||||
|
|
||||||
unsigned int chan;
|
|
||||||
struct Channel * channel;
|
struct Channel * channel;
|
||||||
unsigned int incr;
|
unsigned int incr;
|
||||||
|
|
||||||
chan = buf_getint(ses.payload);
|
channel = getchannel();
|
||||||
channel = getchannel(chan);
|
|
||||||
|
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
dropbear_exit("Unknown channel");
|
dropbear_exit("Unknown channel");
|
||||||
}
|
}
|
||||||
@ -961,14 +950,12 @@ int send_msg_channel_open_init(int fd, const struct ChanType *type) {
|
|||||||
* successful*/
|
* successful*/
|
||||||
void recv_msg_channel_open_confirmation() {
|
void recv_msg_channel_open_confirmation() {
|
||||||
|
|
||||||
unsigned int chan;
|
|
||||||
struct Channel * channel;
|
struct Channel * channel;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
TRACE(("enter recv_msg_channel_open_confirmation"))
|
TRACE(("enter recv_msg_channel_open_confirmation"))
|
||||||
chan = buf_getint(ses.payload);
|
|
||||||
|
|
||||||
channel = getchannel(chan);
|
channel = getchannel();
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
dropbear_exit("Unknown channel");
|
dropbear_exit("Unknown channel");
|
||||||
}
|
}
|
||||||
@ -995,11 +982,9 @@ void recv_msg_channel_open_confirmation() {
|
|||||||
/* Notification that our channel open request failed */
|
/* Notification that our channel open request failed */
|
||||||
void recv_msg_channel_open_failure() {
|
void recv_msg_channel_open_failure() {
|
||||||
|
|
||||||
unsigned int chan;
|
|
||||||
struct Channel * channel;
|
struct Channel * channel;
|
||||||
chan = buf_getbyte(ses.payload);
|
|
||||||
|
|
||||||
channel = getchannel(chan);
|
channel = getchannel();
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
dropbear_exit("Unknown channel");
|
dropbear_exit("Unknown channel");
|
||||||
}
|
}
|
||||||
|
@ -457,7 +457,6 @@ void recv_msg_kexinit() {
|
|||||||
/* the rest of ses.kexhashbuf will be done after DH exchange */
|
/* the rest of ses.kexhashbuf will be done after DH exchange */
|
||||||
|
|
||||||
ses.kexstate.recvkexinit = 1;
|
ses.kexstate.recvkexinit = 1;
|
||||||
// ses.expecting = 0; // client matt
|
|
||||||
|
|
||||||
TRACE(("leave recv_msg_kexinit"))
|
TRACE(("leave recv_msg_kexinit"))
|
||||||
}
|
}
|
||||||
@ -683,7 +682,7 @@ static void read_kex_algos() {
|
|||||||
buf_eatstring(ses.payload);
|
buf_eatstring(ses.payload);
|
||||||
|
|
||||||
/* first_kex_packet_follows */
|
/* first_kex_packet_follows */
|
||||||
if (buf_getbyte(ses.payload)) {
|
if (buf_getbool(ses.payload)) {
|
||||||
ses.kexstate.firstfollows = 1;
|
ses.kexstate.firstfollows = 1;
|
||||||
/* if the guess wasn't good, we ignore the packet sent */
|
/* if the guess wasn't good, we ignore the packet sent */
|
||||||
if (!allgood) {
|
if (!allgood) {
|
||||||
|
2
debug.h
2
debug.h
@ -39,7 +39,7 @@
|
|||||||
* Caution: Don't use this in an unfriendly environment (ie unfirewalled),
|
* Caution: Don't use this in an unfriendly environment (ie unfirewalled),
|
||||||
* since the printing may not sanitise strings etc. This will add a reasonable
|
* since the printing may not sanitise strings etc. This will add a reasonable
|
||||||
* amount to your executable size. */
|
* amount to your executable size. */
|
||||||
//#define DEBUG_TRACE
|
/*#define DEBUG_TRACE */
|
||||||
|
|
||||||
/* All functions writing to the cleartext payload buffer call
|
/* All functions writing to the cleartext payload buffer call
|
||||||
* CHECKCLEARTOWRITE() before writing. This is only really useful if you're
|
* CHECKCLEARTOWRITE() before writing. This is only really useful if you're
|
||||||
|
2
dss.c
2
dss.c
@ -261,6 +261,7 @@ out:
|
|||||||
}
|
}
|
||||||
#endif /* DROPBEAR_SIGNKEY_VERIFY */
|
#endif /* DROPBEAR_SIGNKEY_VERIFY */
|
||||||
|
|
||||||
|
#ifdef DSS_PROTOK
|
||||||
/* convert an unsigned mp into an array of bytes, malloced.
|
/* convert an unsigned mp into an array of bytes, malloced.
|
||||||
* This array must be freed after use, len contains the length of the array,
|
* This array must be freed after use, len contains the length of the array,
|
||||||
* if len != NULL */
|
* if len != NULL */
|
||||||
@ -279,6 +280,7 @@ static unsigned char* mptobytes(mp_int *mp, int *len) {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Sign the data presented with key, writing the signature contents
|
/* Sign the data presented with key, writing the signature contents
|
||||||
* to the buffer
|
* to the buffer
|
||||||
|
6
kex.h
6
kex.h
@ -37,10 +37,10 @@ void gen_kexdh_vals(mp_int *dh_pub, mp_int *dh_priv);
|
|||||||
void kexdh_comb_key(mp_int *dh_pub_us, mp_int *dh_priv, mp_int *dh_pub_them,
|
void kexdh_comb_key(mp_int *dh_pub_us, mp_int *dh_priv, mp_int *dh_pub_them,
|
||||||
sign_key *hostkey);
|
sign_key *hostkey);
|
||||||
|
|
||||||
void recv_msg_kexdh_init(); // server
|
void recv_msg_kexdh_init(); /* server */
|
||||||
|
|
||||||
void send_msg_kexdh_init(); // client
|
void send_msg_kexdh_init(); /* client */
|
||||||
void recv_msg_kexdh_reply(); // client
|
void recv_msg_kexdh_reply(); /* client */
|
||||||
|
|
||||||
extern const unsigned char dh_p_val[];
|
extern const unsigned char dh_p_val[];
|
||||||
#define DH_P_LEN 128 /* The length of the dh_p_val array */
|
#define DH_P_LEN 128 /* The length of the dh_p_val array */
|
||||||
|
3
scp.c
3
scp.c
@ -244,9 +244,6 @@ main(int argc, char **argv)
|
|||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
|
|
||||||
/* hack, seems to work */
|
|
||||||
// __progname = argv[0];
|
|
||||||
|
|
||||||
args.list = NULL;
|
args.list = NULL;
|
||||||
addargs(&args, "ssh"); /* overwritten with ssh_program */
|
addargs(&args, "ssh"); /* overwritten with ssh_program */
|
||||||
addargs(&args, "-x");
|
addargs(&args, "-x");
|
||||||
|
@ -155,7 +155,7 @@ void svr_auth_pam() {
|
|||||||
unsigned char changepw;
|
unsigned char changepw;
|
||||||
|
|
||||||
/* check if client wants to change password */
|
/* check if client wants to change password */
|
||||||
changepw = buf_getbyte(ses.payload);
|
changepw = buf_getbool(ses.payload);
|
||||||
if (changepw) {
|
if (changepw) {
|
||||||
/* not implemented by this server */
|
/* not implemented by this server */
|
||||||
send_msg_userauth_failure(0, 1);
|
send_msg_userauth_failure(0, 1);
|
||||||
|
@ -71,7 +71,7 @@ void svr_auth_password() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if client wants to change password */
|
/* check if client wants to change password */
|
||||||
changepw = buf_getbyte(ses.payload);
|
changepw = buf_getbool(ses.payload);
|
||||||
if (changepw) {
|
if (changepw) {
|
||||||
/* not implemented by this server */
|
/* not implemented by this server */
|
||||||
send_msg_userauth_failure(0, 1);
|
send_msg_userauth_failure(0, 1);
|
||||||
|
@ -64,7 +64,7 @@ void svr_auth_pubkey() {
|
|||||||
|
|
||||||
/* 0 indicates user just wants to check if key can be used, 1 is an
|
/* 0 indicates user just wants to check if key can be used, 1 is an
|
||||||
* actual attempt*/
|
* actual attempt*/
|
||||||
testkey = (buf_getbyte(ses.payload) == 0);
|
testkey = (buf_getbool(ses.payload) == 0);
|
||||||
|
|
||||||
algo = buf_getstring(ses.payload, &algolen);
|
algo = buf_getstring(ses.payload, &algolen);
|
||||||
keybloblen = buf_getint(ses.payload);
|
keybloblen = buf_getint(ses.payload);
|
||||||
|
@ -305,7 +305,7 @@ static void chansessionrequest(struct Channel *channel) {
|
|||||||
TRACE(("enter chansessionrequest"))
|
TRACE(("enter chansessionrequest"))
|
||||||
|
|
||||||
type = buf_getstring(ses.payload, &typelen);
|
type = buf_getstring(ses.payload, &typelen);
|
||||||
wantreply = buf_getbyte(ses.payload);
|
wantreply = buf_getbool(ses.payload);
|
||||||
|
|
||||||
if (typelen > MAX_NAME_LEN) {
|
if (typelen > MAX_NAME_LEN) {
|
||||||
TRACE(("leave chansessionrequest: type too long")) /* XXX send error?*/
|
TRACE(("leave chansessionrequest: type too long")) /* XXX send error?*/
|
||||||
|
@ -78,7 +78,7 @@ void recv_msg_global_request_remotetcp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reqname = buf_getstring(ses.payload, &namelen);
|
reqname = buf_getstring(ses.payload, &namelen);
|
||||||
wantreply = buf_getbyte(ses.payload);
|
wantreply = buf_getbool(ses.payload);
|
||||||
|
|
||||||
if (namelen > MAXNAMLEN) {
|
if (namelen > MAXNAMLEN) {
|
||||||
TRACE(("name len is wrong: %d", namelen))
|
TRACE(("name len is wrong: %d", namelen))
|
||||||
|
@ -52,7 +52,7 @@ int x11req(struct ChanSess * chansess) {
|
|||||||
return DROPBEAR_FAILURE;
|
return DROPBEAR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
chansess->x11singleconn = buf_getbyte(ses.payload);
|
chansess->x11singleconn = buf_getbool(ses.payload);
|
||||||
chansess->x11authprot = buf_getstring(ses.payload, NULL);
|
chansess->x11authprot = buf_getstring(ses.payload, NULL);
|
||||||
chansess->x11authcookie = buf_getstring(ses.payload, NULL);
|
chansess->x11authcookie = buf_getstring(ses.payload, NULL);
|
||||||
chansess->x11screennum = buf_getint(ses.payload);
|
chansess->x11screennum = buf_getint(ses.payload);
|
||||||
|
Loading…
Reference in New Issue
Block a user