From 20bdf3a5b1a1227b55a94830e5046b68b5ebc60c Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 15 Dec 2015 22:57:22 +0800 Subject: [PATCH 01/29] revert removal of space handling, different fix for avoiding option prefix matches --- cli-runopts.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cli-runopts.c b/cli-runopts.c index 60b4aa1..ab25d37 100644 --- a/cli-runopts.c +++ b/cli-runopts.c @@ -824,22 +824,34 @@ badport: #endif static int match_extendedopt(const char** strptr, const char *optname) { + int seen_eq = 0; int optlen = strlen(optname); const char *str = *strptr; + while (isspace(*str)) { + ++str; + } + if (strncasecmp(str, optname, optlen) != 0) { return DROPBEAR_FAILURE; } str += optlen; - if (*str == '=') { - *strptr = str+1; - return DROPBEAR_SUCCESS; - } else { + while (isspace(*str) || (!seen_eq && *str == '=')) { + if (*str == '=') { + seen_eq = 1; + } + ++str; + } + + if (str-*strptr == optlen) { + /* matched just a prefix of optname */ return DROPBEAR_FAILURE; } + *strptr = str; + return DROPBEAR_SUCCESS; } static int parse_flag_value(const char *value) { From 4c4aa502d4a65b90a86de6c1af868984565f1fe2 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Fri, 18 Dec 2015 21:20:46 +0800 Subject: [PATCH 02/29] use exec for proxycommand --- cli-main.c | 9 ++++++++- dbclient.1 | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cli-main.c b/cli-main.c index c2fd729..787d770 100644 --- a/cli-main.c +++ b/cli-main.c @@ -152,12 +152,19 @@ static void exec_proxy_cmd(void *user_data_cmd) { #ifdef ENABLE_CLI_PROXYCMD static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) { + char * ex_cmd = NULL; + size_t ex_cmdlen; int ret; fill_passwd(cli_opts.own_user); - ret = spawn_command(exec_proxy_cmd, cli_opts.proxycmd, + ex_cmdlen = strlen(cli_opts.proxycmd) + 6; /* "exec " + command + '\0' */ + ex_cmd = m_malloc(ex_cmdlen); + snprintf(ex_cmd, ex_cmdlen, "exec %s", cli_opts.proxycmd); + + ret = spawn_command(exec_proxy_cmd, ex_cmd, sock_out, sock_in, NULL, pid_out); + m_free(ex_cmd); if (ret == DROPBEAR_FAILURE) { dropbear_exit("Failed running proxy command"); *sock_in = *sock_out = -1; diff --git a/dbclient.1 b/dbclient.1 index e521af6..fee23c6 100644 --- a/dbclient.1 +++ b/dbclient.1 @@ -114,7 +114,8 @@ Disconnect the session if no traffic is transmitted or received for \fIidle_time .B \-J \fIproxy_command Use the standard input/output of the program \fIproxy_command\fR rather than using a normal TCP connection. A hostname should be still be provided, as this is used for -comparing saved hostkeys. +comparing saved hostkeys. This command will be executed as "exec proxy_command ..." with the +default shell. .TP .B \-B \fIendhost:endport "Netcat-alike" mode, where Dropbear will connect to the given host, then create a From 23ac7f56fa2acd9f35e6b8ca36602f3c14e986cd Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Thu, 31 Dec 2015 15:59:01 +0100 Subject: [PATCH 03/29] refactor indentation with hard tab --- cli-auth.c | 12 ++++++------ dropbearkey.c | 10 +++++----- packet.c | 2 +- rsa.c | 10 +++++----- signkey.c | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cli-auth.c b/cli-auth.c index da0d9d5..59d455b 100644 --- a/cli-auth.c +++ b/cli-auth.c @@ -332,12 +332,12 @@ char* getpass_or_cancel(char* prompt) char* password = NULL; #ifdef DROPBEAR_PASSWORD_ENV - /* Password provided in an environment var */ - password = getenv(DROPBEAR_PASSWORD_ENV); - if (password) - { - return password; - } + /* Password provided in an environment var */ + password = getenv(DROPBEAR_PASSWORD_ENV); + if (password) + { + return password; + } #endif password = getpass(prompt); diff --git a/dropbearkey.c b/dropbearkey.c index 7eb2f3f..0d13b38 100644 --- a/dropbearkey.c +++ b/dropbearkey.c @@ -238,13 +238,13 @@ int main(int argc, char ** argv) { } check_signkey_bits(keytype, bits);; - } + } fprintf(stderr, "Generating key, this may take a while...\n"); - if (signkey_generate(keytype, bits, filename) == DROPBEAR_FAILURE) - { - dropbear_exit("Failed to generate key.\n"); - } + if (signkey_generate(keytype, bits, filename) == DROPBEAR_FAILURE) + { + dropbear_exit("Failed to generate key.\n"); + } printpubfile(filename); diff --git a/packet.c b/packet.c index 19b5759..9269e95 100644 --- a/packet.c +++ b/packet.c @@ -645,7 +645,7 @@ static void make_mac(unsigned int seqno, const struct key_context_directional * dropbear_exit("HMAC error"); } - bufsize = MAX_MAC_LEN; + bufsize = MAX_MAC_LEN; if (hmac_done(&hmac, output_mac, &bufsize) != CRYPT_OK) { dropbear_exit("HMAC error"); } diff --git a/rsa.c b/rsa.c index 193e577..1cedbc4 100644 --- a/rsa.c +++ b/rsa.c @@ -69,12 +69,12 @@ int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) { } TRACE(("leave buf_get_rsa_pub_key: success")) - ret = DROPBEAR_SUCCESS; + ret = DROPBEAR_SUCCESS; out: - if (ret == DROPBEAR_FAILURE) { - m_free(key->e); - m_free(key->n); - } + if (ret == DROPBEAR_FAILURE) { + m_free(key->e); + m_free(key->n); + } return ret; } diff --git a/signkey.c b/signkey.c index ac5d887..55f34e7 100644 --- a/signkey.c +++ b/signkey.c @@ -317,15 +317,15 @@ void buf_put_priv_key(buffer* buf, sign_key *key, enum signkey_type type) { #ifdef DROPBEAR_DSS if (type == DROPBEAR_SIGNKEY_DSS) { buf_put_dss_priv_key(buf, key->dsskey); - TRACE(("leave buf_put_priv_key: dss done")) - return; + TRACE(("leave buf_put_priv_key: dss done")) + return; } #endif #ifdef DROPBEAR_RSA if (type == DROPBEAR_SIGNKEY_RSA) { buf_put_rsa_priv_key(buf, key->rsakey); - TRACE(("leave buf_put_priv_key: rsa done")) - return; + TRACE(("leave buf_put_priv_key: rsa done")) + return; } #endif #ifdef DROPBEAR_ECDSA From 9bda22e70219c3056c07837803d0289b76453adb Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Fri, 1 Jan 2016 15:02:09 +0100 Subject: [PATCH 04/29] more hard tab --- bignum.c | 38 +++++++++++++++++++------------------- buffer.c | 2 +- cli-tcpfwd.c | 4 ++-- common-kex.c | 48 ++++++++++++++++++++++++------------------------ dbutil.c | 30 +++++++++++++++--------------- dropbearkey.c | 30 +++++++++++++++--------------- ecdsa.c | 4 ++-- gensignkey.c | 32 ++++++++++++++++---------------- keyimport.c | 8 ++++---- list.h | 8 ++++---- packet.c | 4 ++-- rsa.c | 30 +++++++++++++++--------------- scp.c | 4 ++-- svr-main.c | 2 +- svr-tcpfwd.c | 2 +- 15 files changed, 123 insertions(+), 123 deletions(-) diff --git a/bignum.c b/bignum.c index 4400969..3758052 100644 --- a/bignum.c +++ b/bignum.c @@ -39,33 +39,33 @@ void m_mp_init(mp_int *mp) { * on error */ void m_mp_init_multi(mp_int *mp, ...) { - mp_int* cur_arg = mp; - va_list args; + mp_int* cur_arg = mp; + va_list args; - va_start(args, mp); /* init args to next argument from caller */ - while (cur_arg != NULL) { - if (mp_init(cur_arg) != MP_OKAY) { + va_start(args, mp); /* init args to next argument from caller */ + while (cur_arg != NULL) { + if (mp_init(cur_arg) != MP_OKAY) { dropbear_exit("Mem alloc error"); - } - cur_arg = va_arg(args, mp_int*); - } - va_end(args); + } + cur_arg = va_arg(args, mp_int*); + } + va_end(args); } void m_mp_alloc_init_multi(mp_int **mp, ...) { - mp_int** cur_arg = mp; - va_list args; + mp_int** cur_arg = mp; + va_list args; - va_start(args, mp); /* init args to next argument from caller */ - while (cur_arg != NULL) { - *cur_arg = m_malloc(sizeof(mp_int)); - if (mp_init(*cur_arg) != MP_OKAY) { + va_start(args, mp); /* init args to next argument from caller */ + while (cur_arg != NULL) { + *cur_arg = m_malloc(sizeof(mp_int)); + if (mp_init(*cur_arg) != MP_OKAY) { dropbear_exit("Mem alloc error"); - } - cur_arg = va_arg(args, mp_int**); - } - va_end(args); + } + cur_arg = va_arg(args, mp_int**); + } + va_end(args); } void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) { diff --git a/buffer.c b/buffer.c index 1e5a864..cd974e3 100644 --- a/buffer.c +++ b/buffer.c @@ -98,7 +98,7 @@ buffer* buf_newcopy(buffer* buf) { ret = buf_new(buf->len); ret->len = buf->len; if (buf->len > 0) { - memcpy(ret->data, buf->data, buf->len); + memcpy(ret->data, buf->data, buf->len); } return ret; } diff --git a/cli-tcpfwd.c b/cli-tcpfwd.c index fec5dba..d5023cc 100644 --- a/cli-tcpfwd.c +++ b/cli-tcpfwd.c @@ -231,7 +231,7 @@ void setup_remotetcp() { static int newtcpforwarded(struct Channel * channel) { - char *origaddr = NULL; + char *origaddr = NULL; unsigned int origport; m_list_elem * iter = NULL; struct TCPFwdEntry *fwd; @@ -267,7 +267,7 @@ static int newtcpforwarded(struct Channel * channel) { if (iter == NULL) { /* We didn't request forwarding on that port */ - cleantext(origaddr); + cleantext(origaddr); dropbear_log(LOG_INFO, "Server sent unrequested forward from \"%s:%d\"", origaddr, origport); goto out; diff --git a/common-kex.c b/common-kex.c index b233819..8c0c873 100644 --- a/common-kex.c +++ b/common-kex.c @@ -40,7 +40,7 @@ /* diffie-hellman-group1-sha1 value for p */ const unsigned char dh_p_1[DH_P_1_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, - 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, + 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, @@ -54,7 +54,7 @@ const unsigned char dh_p_1[DH_P_1_LEN] = { /* diffie-hellman-group14-sha1 value for p */ const unsigned char dh_p_14[DH_P_14_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, - 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, + 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, @@ -349,17 +349,17 @@ static void gen_new_keys() { ses.hash = NULL; if (IS_DROPBEAR_CLIENT) { - trans_IV = C2S_IV; - recv_IV = S2C_IV; - trans_key = C2S_key; - recv_key = S2C_key; + trans_IV = C2S_IV; + recv_IV = S2C_IV; + trans_key = C2S_key; + recv_key = S2C_key; mactransletter = 'E'; macrecvletter = 'F'; } else { - trans_IV = S2C_IV; - recv_IV = C2S_IV; - trans_key = S2C_key; - recv_key = C2S_key; + trans_IV = S2C_IV; + recv_IV = C2S_IV; + trans_key = S2C_key; + recv_key = C2S_key; mactransletter = 'F'; macrecvletter = 'E'; } @@ -525,18 +525,18 @@ void recv_msg_kexinit() { read_kex_algos(); /* V_C, the client's version string (CR and NL excluded) */ - buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len); + buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len); /* V_S, the server's version string (CR and NL excluded) */ - buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); + buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); /* I_C, the payload of the client's SSH_MSG_KEXINIT */ - buf_putstring(ses.kexhashbuf, + buf_putstring(ses.kexhashbuf, (const char*)ses.transkexinit->data, ses.transkexinit->len); /* I_S, the payload of the server's SSH_MSG_KEXINIT */ - buf_setpos(ses.payload, ses.payload_beginning); - buf_putstring(ses.kexhashbuf, - (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos), - ses.payload->len-ses.payload->pos); + buf_setpos(ses.payload, ses.payload_beginning); + buf_putstring(ses.kexhashbuf, + (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos), + ses.payload->len-ses.payload->pos); ses.requirenext = SSH_MSG_KEXDH_REPLY; } else { /* SERVER */ @@ -544,18 +544,18 @@ void recv_msg_kexinit() { /* read the peer's choice of algos */ read_kex_algos(); /* V_C, the client's version string (CR and NL excluded) */ - buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); + buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); /* V_S, the server's version string (CR and NL excluded) */ - buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len); + buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len); /* I_C, the payload of the client's SSH_MSG_KEXINIT */ - buf_setpos(ses.payload, ses.payload_beginning); - buf_putstring(ses.kexhashbuf, - (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos), - ses.payload->len-ses.payload->pos); + buf_setpos(ses.payload, ses.payload_beginning); + buf_putstring(ses.kexhashbuf, + (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos), + ses.payload->len-ses.payload->pos); /* I_S, the payload of the server's SSH_MSG_KEXINIT */ - buf_putstring(ses.kexhashbuf, + buf_putstring(ses.kexhashbuf, (const char*)ses.transkexinit->data, ses.transkexinit->len); ses.requirenext = SSH_MSG_KEXDH_INIT; diff --git a/dbutil.c b/dbutil.c index 7c7c069..93b03a3 100644 --- a/dbutil.c +++ b/dbutil.c @@ -157,26 +157,26 @@ void debug_start_net() { if (getenv("DROPBEAR_DEBUG_NET_TIMESTAMP")) { - /* Timestamps start from first network activity */ - struct timeval tv; - gettimeofday(&tv, NULL); - debug_start_time = tv.tv_sec + (tv.tv_usec / 1000000.0); - TRACE(("Resetting Dropbear TRACE timestamps")) + /* Timestamps start from first network activity */ + struct timeval tv; + gettimeofday(&tv, NULL); + debug_start_time = tv.tv_sec + (tv.tv_usec / 1000000.0); + TRACE(("Resetting Dropbear TRACE timestamps")) } } static double time_since_start() { - double nowf; - struct timeval tv; - gettimeofday(&tv, NULL); - nowf = tv.tv_sec + (tv.tv_usec / 1000000.0); - if (debug_start_time < 0) - { - debug_start_time = nowf; - return 0; - } - return nowf - debug_start_time; + double nowf; + struct timeval tv; + gettimeofday(&tv, NULL); + nowf = tv.tv_sec + (tv.tv_usec / 1000000.0); + if (debug_start_time < 0) + { + debug_start_time = nowf; + return 0; + } + return nowf - debug_start_time; } void dropbear_trace(const char* format, ...) { diff --git a/dropbearkey.c b/dropbearkey.c index 0d13b38..644de94 100644 --- a/dropbearkey.c +++ b/dropbearkey.c @@ -105,25 +105,25 @@ static void printhelp(char * progname) { /* fails fatally */ static void check_signkey_bits(enum signkey_type type, int bits) { - switch (type) { + switch (type) { #ifdef DROPBEAR_RSA - case DROPBEAR_SIGNKEY_RSA: - if (bits < 512 || bits > 4096 || (bits % 8 != 0)) { - dropbear_exit("Bits must satisfy 512 <= bits <= 4096, and be a" - " multiple of 8\n"); - } - break; + case DROPBEAR_SIGNKEY_RSA: + if (bits < 512 || bits > 4096 || (bits % 8 != 0)) { + dropbear_exit("Bits must satisfy 512 <= bits <= 4096, and be a" + " multiple of 8\n"); + } + break; #endif #ifdef DROPEAR_DSS - case DROPBEAR_SIGNKEY_DSS: - if (bits != 1024) { - dropbear_exit("DSS keys have a fixed size of 1024 bits\n"); - exit(EXIT_FAILURE); - } + case DROPBEAR_SIGNKEY_DSS: + if (bits != 1024) { + dropbear_exit("DSS keys have a fixed size of 1024 bits\n"); + exit(EXIT_FAILURE); + } #endif - default: - (void)0; /* quiet, compiler. ecdsa handles checks itself */ - } + default: + (void)0; /* quiet, compiler. ecdsa handles checks itself */ + } } #if defined(DBMULTI_dropbearkey) || !defined(DROPBEAR_MULTI) diff --git a/ecdsa.c b/ecdsa.c index 5568131..14558b6 100644 --- a/ecdsa.c +++ b/ecdsa.c @@ -385,12 +385,12 @@ int buf_ecdsa_verify(buffer *buf, ecc_key *key, buffer *data_buf) { goto out; } - /* reduce */ + /* reduce */ if (ltc_mp.ecc_map(mG, m, mp) != CRYPT_OK) { goto out; } } else { - /* use Shamir's trick to compute u1*mG + u2*mQ using half of the doubles */ + /* use Shamir's trick to compute u1*mG + u2*mQ using half of the doubles */ if (ltc_mp.ecc_mul2add(mG, u1, mQ, u2, mG, m) != CRYPT_OK) { goto out; } diff --git a/gensignkey.c b/gensignkey.c index e6c40e0..cdc16e6 100644 --- a/gensignkey.c +++ b/gensignkey.c @@ -52,28 +52,28 @@ out: /* returns 0 on failure */ static int get_default_bits(enum signkey_type keytype) { - switch (keytype) { + switch (keytype) { #ifdef DROPBEAR_RSA - case DROPBEAR_SIGNKEY_RSA: - return RSA_DEFAULT_SIZE; + case DROPBEAR_SIGNKEY_RSA: + return RSA_DEFAULT_SIZE; #endif #ifdef DROPBEAR_DSS - case DROPBEAR_SIGNKEY_DSS: - return DSS_DEFAULT_SIZE; + case DROPBEAR_SIGNKEY_DSS: + return DSS_DEFAULT_SIZE; #endif #ifdef DROPBEAR_ECDSA - case DROPBEAR_SIGNKEY_ECDSA_KEYGEN: - return ECDSA_DEFAULT_SIZE; - case DROPBEAR_SIGNKEY_ECDSA_NISTP521: - return 521; - case DROPBEAR_SIGNKEY_ECDSA_NISTP384: - return 384; - case DROPBEAR_SIGNKEY_ECDSA_NISTP256: - return 256; + case DROPBEAR_SIGNKEY_ECDSA_KEYGEN: + return ECDSA_DEFAULT_SIZE; + case DROPBEAR_SIGNKEY_ECDSA_NISTP521: + return 521; + case DROPBEAR_SIGNKEY_ECDSA_NISTP384: + return 384; + case DROPBEAR_SIGNKEY_ECDSA_NISTP256: + return 256; #endif - default: - return 0; - } + default: + return 0; + } } int signkey_generate(enum signkey_type keytype, int bits, const char* filename) diff --git a/keyimport.c b/keyimport.c index d45914f..66a6df7 100644 --- a/keyimport.c +++ b/keyimport.c @@ -194,13 +194,13 @@ static void base64_encode_fp(FILE * fp, unsigned char *data, int datalen, int cpl) { unsigned char out[100]; - int n; + int n; unsigned long outlen; int rawcpl; rawcpl = cpl * 3 / 4; dropbear_assert((unsigned int)cpl < sizeof(out)); - while (datalen > 0) { + while (datalen > 0) { n = (datalen < rawcpl ? datalen : rawcpl); outlen = sizeof(out); base64_encode(data, n, out, &outlen); @@ -208,7 +208,7 @@ static void base64_encode_fp(FILE * fp, unsigned char *data, datalen -= n; fwrite(out, 1, outlen, fp); fputc('\n', fp); - } + } } /* * Read an ASN.1/BER identifier and length pair. @@ -1056,7 +1056,7 @@ static int openssh_write(const char *filename, sign_key *key, dropbear_assert(k_size <= curve_size); buf_incrwritepos(seq_buf, ber_write_id_len(buf_getwriteptr(seq_buf, 10), 4, k_size, 0)); - mp_to_unsigned_bin((*eck)->k, buf_getwriteptr(seq_buf, k_size)); + mp_to_unsigned_bin((*eck)->k, buf_getwriteptr(seq_buf, k_size)); buf_incrwritepos(seq_buf, k_size); /* SECGCurveNames */ diff --git a/list.h b/list.h index 35c0d49..b26a212 100644 --- a/list.h +++ b/list.h @@ -4,17 +4,17 @@ struct _m_list; struct _m_list_elem { - void *item; + void *item; struct _m_list_elem *next; struct _m_list_elem *prev; - struct _m_list *list; + struct _m_list *list; }; typedef struct _m_list_elem m_list_elem; struct _m_list { - m_list_elem *first; - m_list_elem *last; + m_list_elem *first; + m_list_elem *last; }; typedef struct _m_list m_list; diff --git a/packet.c b/packet.c index 9269e95..f827ab8 100644 --- a/packet.c +++ b/packet.c @@ -576,8 +576,8 @@ void encrypt_packet() { } buf_incrpos(writebuf, len); - /* stick the MAC on it */ - buf_putbytes(writebuf, mac_bytes, mac_size); + /* stick the MAC on it */ + buf_putbytes(writebuf, mac_bytes, mac_size); /* Update counts */ ses.kexstate.datatrans += writebuf->len; diff --git a/rsa.c b/rsa.c index 1cedbc4..4fa4088 100644 --- a/rsa.c +++ b/rsa.c @@ -47,7 +47,7 @@ static void rsa_pad_em(dropbear_rsa_key * key, * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) { - int ret = DROPBEAR_FAILURE; + int ret = DROPBEAR_FAILURE; TRACE(("enter buf_get_rsa_pub_key")) dropbear_assert(key != NULL); m_mp_alloc_init_multi(&key->e, &key->n, NULL); @@ -60,12 +60,12 @@ int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) { if (buf_getmpint(buf, key->e) == DROPBEAR_FAILURE || buf_getmpint(buf, key->n) == DROPBEAR_FAILURE) { TRACE(("leave buf_get_rsa_pub_key: failure")) - goto out; + goto out; } if (mp_count_bits(key->n) < MIN_RSA_KEYLEN) { dropbear_log(LOG_WARNING, "RSA key too short"); - goto out; + goto out; } TRACE(("leave buf_get_rsa_pub_key: success")) @@ -82,7 +82,7 @@ out: * Loads a private rsa key from a buffer * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) { - int ret = DROPBEAR_FAILURE; + int ret = DROPBEAR_FAILURE; TRACE(("enter buf_get_rsa_priv_key")) dropbear_assert(key != NULL); @@ -99,34 +99,34 @@ int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) { m_mp_alloc_init_multi(&key->d, NULL); if (buf_getmpint(buf, key->d) == DROPBEAR_FAILURE) { TRACE(("leave buf_get_rsa_priv_key: d: ret == DROPBEAR_FAILURE")) - goto out; + goto out; } if (buf->pos == buf->len) { - /* old Dropbear private keys didn't keep p and q, so we will ignore them*/ + /* old Dropbear private keys didn't keep p and q, so we will ignore them*/ } else { m_mp_alloc_init_multi(&key->p, &key->q, NULL); if (buf_getmpint(buf, key->p) == DROPBEAR_FAILURE) { TRACE(("leave buf_get_rsa_priv_key: p: ret == DROPBEAR_FAILURE")) - goto out; + goto out; } if (buf_getmpint(buf, key->q) == DROPBEAR_FAILURE) { TRACE(("leave buf_get_rsa_priv_key: q: ret == DROPBEAR_FAILURE")) - goto out; + goto out; } } - ret = DROPBEAR_SUCCESS; + ret = DROPBEAR_SUCCESS; out: - if (ret == DROPBEAR_FAILURE) { - m_free(key->d); - m_free(key->p); - m_free(key->q); - } + if (ret == DROPBEAR_FAILURE) { + m_free(key->d); + m_free(key->p); + m_free(key->q); + } TRACE(("leave buf_get_rsa_priv_key")) - return ret; + return ret; } diff --git a/scp.c b/scp.c index 70f45e3..c176a3a 100644 --- a/scp.c +++ b/scp.c @@ -441,9 +441,9 @@ main(int argc, char **argv) */ if (do_cmd_pid != -1 && errs == 0) { if (remin != -1) - (void) close(remin); + (void) close(remin); if (remout != -1) - (void) close(remout); + (void) close(remout); if (waitpid(do_cmd_pid, &status, 0) == -1) errs = 1; else { diff --git a/svr-main.c b/svr-main.c index af56a7c..28fc9b0 100644 --- a/svr-main.c +++ b/svr-main.c @@ -398,7 +398,7 @@ static void commonsetup() { * otherwise we might end up blatting error messages to the socket */ load_all_hostkeys(); - seedrandom(); + seedrandom(); } /* Set up listening sockets for all the requested ports */ diff --git a/svr-tcpfwd.c b/svr-tcpfwd.c index d2f1427..5f87511 100644 --- a/svr-tcpfwd.c +++ b/svr-tcpfwd.c @@ -194,7 +194,7 @@ static int svr_remotetcpreq() { tcpinfo->request_listenaddr = request_addr; if (!opts.listen_fwd_all || (strcmp(request_addr, "localhost") == 0) ) { - /* NULL means "localhost only" */ + /* NULL means "localhost only" */ tcpinfo->listenaddr = NULL; } else From f37d67ff5ed10789d50fed6b1302252884ae0cbe Mon Sep 17 00:00:00 2001 From: Nick Steel Date: Sun, 3 Jan 2016 14:42:57 +0000 Subject: [PATCH 05/29] Added missing init info field to debian init script. The Short-Description init info field is used by systemd and displayed along with the service name. When it's missing the string 'null' is displayed instead. --- debian/dropbear.init | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/dropbear.init b/debian/dropbear.init index 1705330..ef3ec3f 100644 --- a/debian/dropbear.init +++ b/debian/dropbear.init @@ -5,6 +5,7 @@ # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 +# Short-Description: Dropbear SSH server ### END INIT INFO # # Do not configure this file. Edit /etc/default/dropbear instead! From 533aebe33656f0ade5f9071ae7880b54a097752b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Jan 2016 12:25:10 +0800 Subject: [PATCH 06/29] Fix "Pointer to local array variable returned" --- compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat.c b/compat.c index a689a14..71558a5 100644 --- a/compat.c +++ b/compat.c @@ -235,7 +235,7 @@ void setusershell() { static char **initshells() { /* don't touch this list. */ - const char *okshells[] = { "/bin/sh", "/bin/csh", NULL }; + static const char *okshells[] = { "/bin/sh", "/bin/csh", NULL }; register char **sp, *cp; register FILE *fp; struct stat statb; From 9bcd5f3c0aac51af390b77d725c124e42baa60cd Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Jan 2016 12:32:33 +0800 Subject: [PATCH 07/29] Fix print format specifier --- cli-runopts.c | 2 +- cli-tcpfwd.c | 2 +- svr-session.c | 2 +- svr-tcpfwd.c | 2 +- svr-x11fwd.c | 4 ++-- tcp-accept.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cli-runopts.c b/cli-runopts.c index ab25d37..8d1edee 100644 --- a/cli-runopts.c +++ b/cli-runopts.c @@ -538,7 +538,7 @@ multihop_passthrough_args() { if (opts.recv_window != DEFAULT_RECV_WINDOW) { - int written = snprintf(ret+total, len-total, "-W %d ", opts.recv_window); + int written = snprintf(ret+total, len-total, "-W %u ", opts.recv_window); total += written; } diff --git a/cli-tcpfwd.c b/cli-tcpfwd.c index fec5dba..b32d9e0 100644 --- a/cli-tcpfwd.c +++ b/cli-tcpfwd.c @@ -273,7 +273,7 @@ static int newtcpforwarded(struct Channel * channel) { goto out; } - snprintf(portstring, sizeof(portstring), "%d", fwd->connectport); + snprintf(portstring, sizeof(portstring), "%u", fwd->connectport); channel->conn_pending = connect_remote(fwd->connectaddr, portstring, channel_connect_done, channel); channel->prio = DROPBEAR_CHANNEL_PRIO_UNKNOWABLE; diff --git a/svr-session.c b/svr-session.c index f777b5f..254a747 100644 --- a/svr-session.c +++ b/svr-session.c @@ -160,7 +160,7 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param) { } else if (ses.authstate.pw_name) { /* we have a potential user */ snprintf(fmtbuf, sizeof(fmtbuf), - "Exit before auth (user '%s', %d fails): %s", + "Exit before auth (user '%s', %u fails): %s", ses.authstate.pw_name, ses.authstate.failcount, format); } else { /* before userauth */ diff --git a/svr-tcpfwd.c b/svr-tcpfwd.c index d2f1427..9d051bf 100644 --- a/svr-tcpfwd.c +++ b/svr-tcpfwd.c @@ -269,7 +269,7 @@ static int newtcpdirect(struct Channel * channel) { goto out; } - snprintf(portstring, sizeof(portstring), "%d", destport); + snprintf(portstring, sizeof(portstring), "%u", destport); channel->conn_pending = connect_remote(desthost, portstring, channel_connect_done, channel); channel->prio = DROPBEAR_CHANNEL_PRIO_UNKNOWABLE; diff --git a/svr-x11fwd.c b/svr-x11fwd.c index 144ec0b..9e7df24 100644 --- a/svr-x11fwd.c +++ b/svr-x11fwd.c @@ -142,7 +142,7 @@ void x11setauth(struct ChanSess *chansess) { } /* create the DISPLAY string */ - val = snprintf(display, sizeof(display), "localhost:%d.%d", + val = snprintf(display, sizeof(display), "localhost:%d.%u", chansess->x11port - X11BASEPORT, chansess->x11screennum); if (val < 0 || val >= (int)sizeof(display)) { /* string was truncated */ @@ -152,7 +152,7 @@ void x11setauth(struct ChanSess *chansess) { addnewvar("DISPLAY", display); /* create the xauth string */ - val = snprintf(display, sizeof(display), "unix:%d.%d", + val = snprintf(display, sizeof(display), "unix:%d.%u", chansess->x11port - X11BASEPORT, chansess->x11screennum); if (val < 0 || val >= (int)sizeof(display)) { /* string was truncated */ diff --git a/tcp-accept.c b/tcp-accept.c index 4456920..f1f51a7 100644 --- a/tcp-accept.c +++ b/tcp-accept.c @@ -121,7 +121,7 @@ int listen_tcpfwd(struct TCPListener* tcpinfo) { TRACE(("enter listen_tcpfwd")) /* first we try to bind, so don't need to do so much cleanup on failure */ - snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport); + snprintf(portstring, sizeof(portstring), "%u", tcpinfo->listenport); nsocks = dropbear_listen(tcpinfo->listenaddr, portstring, socks, DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd); From bbf9ba6d8d7fb605d9169f528ed90868ce7840f2 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Jan 2016 14:09:25 +0800 Subject: [PATCH 08/29] TravisCI: modify to run builds in container --- .travis.yml | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4bfef9f..dcd6d6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,32 @@ language: c + compiler: - gcc -script: - - autoconf && autoheader && ./configure $BUNDLEDLIBTOM CFLAGS="-O2 -Wall -Wno-pointer-sign $WEXTRAFLAGS" --prefix=$HOME/inst +env: + - BUNDLEDLIBTOM=--disable-bundled-libtom WEXTRAFLAGS=-Werror + - BUNDLEDLIBTOM=--enable-bundled-libtom + - MULTI=1 + - NOWRITEV=1 + +# container-based builds +sudo: false +addons: + apt: + packages: + # packages list: https://github.com/travis-ci/apt-package-whitelist/blob/master/ubuntu-precise + - zlib1g-dev + - libtomcrypt-dev + - libtommath-dev + +script: + - autoconf && autoheader && ./configure $BUNDLEDLIBTOM CFLAGS="-O2 -Wall -Wno-pointer-sign $WEXTRAFLAGS" --prefix=$HOME/inst - test "$NOWRITEV" && sed -i s/HAVE_WRITEV/DONT_HAVE_WRITEV/ config.h || true - make install + +after_success: - ~/inst/bin/dropbearkey -t rsa -f testrsa - ~/inst/bin/dropbearkey -t dss -f testdss - ~/inst/bin/dropbearkey -t ecdsa -f testec256 -s 256 - ~/inst/bin/dropbearkey -t ecdsa -f testec384 -s 384 - ~/inst/bin/dropbearkey -t ecdsa -f testec521 -s 521 - -before_install: - - sudo apt-get update -qq - - sudo apt-get install -qq libz-dev libtomcrypt-dev libtommath-dev - -env: - - BUNDLEDLIBTOM=--disable-bundled-libtom WEXTRAFLAGS=-Werror - - BUNDLEDLIBTOM=--enable-bundled-libtom - - MULTI=1 - - NOWRITEV=1 From b41ae80399d6a99ddea5bfc789fd48aae21cab79 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Jan 2016 14:12:38 +0800 Subject: [PATCH 09/29] TravisCI: enable parallel build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dcd6d6f..9090557 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ addons: script: - autoconf && autoheader && ./configure $BUNDLEDLIBTOM CFLAGS="-O2 -Wall -Wno-pointer-sign $WEXTRAFLAGS" --prefix=$HOME/inst - test "$NOWRITEV" && sed -i s/HAVE_WRITEV/DONT_HAVE_WRITEV/ config.h || true - - make install + - make -j3 install after_success: - ~/inst/bin/dropbearkey -t rsa -f testrsa From 307c71b66a645dd066aee71e96da0c4ed15cb78d Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Jan 2016 14:13:34 +0800 Subject: [PATCH 10/29] TravisCI: enable build with clang --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9090557..71f8080 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,15 @@ language: c -compiler: - - gcc - env: - BUNDLEDLIBTOM=--disable-bundled-libtom WEXTRAFLAGS=-Werror - BUNDLEDLIBTOM=--enable-bundled-libtom - MULTI=1 - NOWRITEV=1 +compiler: + - gcc + - clang + # container-based builds sudo: false addons: From de1993a1fdc12355ee90da357128d3ec43522c57 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Jan 2016 12:49:04 +0800 Subject: [PATCH 11/29] Fix parentheses weird placement --- svr-authpam.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svr-authpam.c b/svr-authpam.c index 101017c..98505ba 100644 --- a/svr-authpam.c +++ b/svr-authpam.c @@ -218,7 +218,7 @@ void svr_auth_pam() { } /* just to set it to something */ - if ((rc = pam_set_item(pamHandlep, PAM_TTY, "ssh") != PAM_SUCCESS)) { + if ((rc = pam_set_item(pamHandlep, PAM_TTY, "ssh")) != PAM_SUCCESS) { dropbear_log(LOG_WARNING, "pam_set_item() failed, rc=%d, %s", rc, pam_strerror(pamHandlep, rc)); goto cleanup; From d416a9b818143a1bf3a3fbc49e521d0fad3fec0a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Jan 2016 14:19:58 +0800 Subject: [PATCH 12/29] TravisCI: enable osx builds --- .travis.yml | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71f8080..45bbd1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,25 @@ language: c +os: + - linux + - osx + env: - - BUNDLEDLIBTOM=--disable-bundled-libtom WEXTRAFLAGS=-Werror - - BUNDLEDLIBTOM=--enable-bundled-libtom - - MULTI=1 - - NOWRITEV=1 + matrix: + - BUNDLEDLIBTOM=--disable-bundled-libtom WEXTRAFLAGS=-Werror + - BUNDLEDLIBTOM=--enable-bundled-libtom + - MULTI=1 + - NOWRITEV=1 + +# TODO: remove this section when libtomcrypt compiles on OSX: https://github.com/libtom/libtomcrypt/issues/82 +matrix: + exclude: + - os: osx + env: BUNDLEDLIBTOM=--disable-bundled-libtom WEXTRAFLAGS=-Werror + - os: osx + env: MULTI=1 + - os: osx + env: NOWRITEV=1 compiler: - gcc @@ -20,6 +35,10 @@ addons: - libtomcrypt-dev - libtommath-dev + +install: + - if [ "$TRAVIS_OS_NAME" = "osx" -a "$BUNDLEDLIBTOM" != "--enable-bundled-libtom" ]; then brew update > /dev/null && brew install libtomcrypt libtommath ; fi + script: - autoconf && autoheader && ./configure $BUNDLEDLIBTOM CFLAGS="-O2 -Wall -Wno-pointer-sign $WEXTRAFLAGS" --prefix=$HOME/inst - test "$NOWRITEV" && sed -i s/HAVE_WRITEV/DONT_HAVE_WRITEV/ config.h || true From 0ba59d80b6d9ef680175dcb5f202982d3db9fef9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Jan 2016 15:27:18 +0800 Subject: [PATCH 13/29] TravisCI: use `if` block --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 45bbd1f..0c97752 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,8 +40,8 @@ install: - if [ "$TRAVIS_OS_NAME" = "osx" -a "$BUNDLEDLIBTOM" != "--enable-bundled-libtom" ]; then brew update > /dev/null && brew install libtomcrypt libtommath ; fi script: - - autoconf && autoheader && ./configure $BUNDLEDLIBTOM CFLAGS="-O2 -Wall -Wno-pointer-sign $WEXTRAFLAGS" --prefix=$HOME/inst - - test "$NOWRITEV" && sed -i s/HAVE_WRITEV/DONT_HAVE_WRITEV/ config.h || true + - autoconf && autoheader && ./configure "$BUNDLEDLIBTOM" CFLAGS="-O2 -Wall -Wno-pointer-sign $WEXTRAFLAGS" --prefix="$HOME/inst" + - if [ "$NOWRITEV" = "1" ]; then sed -i s/HAVE_WRITEV/DONT_HAVE_WRITEV/ config.h ; fi - make -j3 install after_success: From 3360072f84625a6bae6fd55a2da7402ab5f2c013 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 11 Jan 2016 13:31:41 +0800 Subject: [PATCH 14/29] TravisCI: fix linux + clang compile --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0c97752..b84b84a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,9 @@ addons: - libtommath-dev +before_install: + - if [ "$CC" = "clang" ]; then WEXTRAFLAGS="$WEXTRAFLAGS -Wno-error=incompatible-library-redeclaration" ; fi # workaround + install: - if [ "$TRAVIS_OS_NAME" = "osx" -a "$BUNDLEDLIBTOM" != "--enable-bundled-libtom" ]; then brew update > /dev/null && brew install libtomcrypt libtommath ; fi From 09e83ad74212a35e8ed05c4ea45af788debfde78 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Thu, 14 Jan 2016 21:54:58 +0800 Subject: [PATCH 15/29] Move dh group constants to a separate file --- Makefile.in | 2 +- common-algo.c | 2 +- common-kex.c | 43 +------------------------------------------ dh_groups.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ dh_groups.h | 11 +++++++++++ kex.h | 5 ----- 6 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 dh_groups.c create mode 100644 dh_groups.h diff --git a/Makefile.in b/Makefile.in index b2e7a27..becc4ab 100644 --- a/Makefile.in +++ b/Makefile.in @@ -44,7 +44,7 @@ CLIOBJS=cli-main.o cli-auth.o cli-authpasswd.o cli-kex.o \ CLISVROBJS=common-session.o packet.o common-algo.o common-kex.o \ common-channel.o common-chansession.o termcodes.o loginrec.o \ - tcp-accept.o listener.o process-packet.o \ + tcp-accept.o listener.o process-packet.o dh_groups.o \ common-runopts.o circbuffer.o curve25519-donna.o list.o netio.o KEYOBJS=dropbearkey.o diff --git a/common-algo.c b/common-algo.c index 51907d0..c46fa3a 100644 --- a/common-algo.c +++ b/common-algo.c @@ -27,7 +27,7 @@ #include "algo.h" #include "session.h" #include "dbutil.h" -#include "kex.h" +#include "dh_groups.h" #include "ltc_prng.h" #include "ecc.h" diff --git a/common-kex.c b/common-kex.c index b233819..d403bd2 100644 --- a/common-kex.c +++ b/common-kex.c @@ -29,6 +29,7 @@ #include "buffer.h" #include "session.h" #include "kex.h" +#include "dh_groups.h" #include "ssh.h" #include "packet.h" #include "bignum.h" @@ -37,48 +38,6 @@ #include "ecc.h" #include "crypto_desc.h" -/* diffie-hellman-group1-sha1 value for p */ -const unsigned char dh_p_1[DH_P_1_LEN] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, - 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, - 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, - 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, - 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, - 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, - 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, - 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, - 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, - 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - -/* diffie-hellman-group14-sha1 value for p */ -const unsigned char dh_p_14[DH_P_14_LEN] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x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, 0x3B, - 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, - 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, - 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, - 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, - 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF}; - -/* Same for group1 and group14 */ -static const int DH_G_VAL = 2; - static void kexinitialise(); static void gen_new_keys(); #ifndef DISABLE_ZLIB diff --git a/dh_groups.c b/dh_groups.c new file mode 100644 index 0000000..c876bff --- /dev/null +++ b/dh_groups.c @@ -0,0 +1,44 @@ +#include "dh_groups.h" + +/* diffie-hellman-group1-sha1 value for p */ +const unsigned char dh_p_1[DH_P_1_LEN] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, + 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, + 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, + 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, + 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, + 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, + 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, + 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, + 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, + 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + +/* diffie-hellman-group14-sha1 value for p */ +const unsigned char dh_p_14[DH_P_14_LEN] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, + 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, + 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, + 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, + 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, + 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, + 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, + 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, + 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, + 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, + 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, + 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, + 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, + 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, + 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, + 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, + 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, + 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, + 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, + 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, + 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF}; + +/* Same for group1 and group14 */ +const int DH_G_VAL = 2; + diff --git a/dh_groups.h b/dh_groups.h new file mode 100644 index 0000000..b210def --- /dev/null +++ b/dh_groups.h @@ -0,0 +1,11 @@ +#ifndef DROPBEAR_DH_GROUPS_H +#define DROPBEAR_DH_GROUPS_H + +#define DH_P_1_LEN 128 +extern const unsigned char dh_p_1[DH_P_1_LEN]; +#define DH_P_14_LEN 256 +extern const unsigned char dh_p_14[DH_P_14_LEN]; +extern const int DH_G_VAL; + + +#endif diff --git a/kex.h b/kex.h index 4cee8e3..126c19e 100644 --- a/kex.h +++ b/kex.h @@ -83,11 +83,6 @@ struct KEXState { }; -#define DH_P_1_LEN 128 -extern const unsigned char dh_p_1[DH_P_1_LEN]; -#define DH_P_14_LEN 256 -extern const unsigned char dh_p_14[DH_P_14_LEN]; - struct kex_dh_param { mp_int pub; /* e */ mp_int priv; /* x */ From 21ed9480d7ca1e39c98e50c019ba40831ec9bcfb Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Fri, 15 Jan 2016 00:19:11 +0800 Subject: [PATCH 16/29] add dh group15 and group16, disabled by default --- common-algo.c | 14 ++++++++- dh_groups.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ dh_groups.h | 13 ++++++++ options.h | 5 +++ 4 files changed, 115 insertions(+), 1 deletion(-) diff --git a/common-algo.c b/common-algo.c index c46fa3a..1841d67 100644 --- a/common-algo.c +++ b/common-algo.c @@ -251,6 +251,12 @@ algo_type sshhostkey[] = { static const struct dropbear_kex kex_dh_group1 = {DROPBEAR_KEX_NORMAL_DH, dh_p_1, DH_P_1_LEN, NULL, &sha1_desc }; static const struct dropbear_kex kex_dh_group14_sha1 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha1_desc }; static const struct dropbear_kex kex_dh_group14_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha256_desc }; +#ifdef DROPBEAR_DH_GROUP15 +static const struct dropbear_kex kex_dh_group15_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_15, DH_P_15_LEN, NULL, &sha256_desc }; +#endif +#ifdef DROPBEAR_DH_GROUP16 +static const struct dropbear_kex kex_dh_group16_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_16, DH_P_16_LEN, NULL, &sha256_desc }; +#endif /* These can't be const since dropbear_ecc_fill_dp() fills out ecc_curve at runtime */ @@ -289,6 +295,12 @@ algo_type sshkex[] = { {"diffie-hellman-group14-sha256", 0, &kex_dh_group14_sha256, 1, NULL}, {"diffie-hellman-group14-sha1", 0, &kex_dh_group14_sha1, 1, NULL}, {"diffie-hellman-group1-sha1", 0, &kex_dh_group1, 1, NULL}, +#ifdef DROPBEAR_DH_GROUP15 + {"diffie-hellman-group15-sha256", 0, &kex_dh_group15_sha256, 1, NULL}, +#endif +#ifdef DROPBEAR_DH_GROUP16 + {"diffie-hellman-group16-sha256", 0, &kex_dh_group16_sha256, 1, NULL}, +#endif #ifdef USE_KEXGUESS2 {KEXGUESS2_ALGO_NAME, KEXGUESS2_ALGO_ID, NULL, 1, NULL}, #endif @@ -320,7 +332,7 @@ void buf_put_algolist(buffer * buf, algo_type localalgos[]) { unsigned int donefirst = 0; buffer *algolist = NULL; - algolist = buf_new(200); + algolist = buf_new(300); for (i = 0; localalgos[i].name != NULL; i++) { if (localalgos[i].usable) { if (donefirst) diff --git a/dh_groups.c b/dh_groups.c index c876bff..205dea3 100644 --- a/dh_groups.c +++ b/dh_groups.c @@ -1,3 +1,4 @@ +#include "options.h" #include "dh_groups.h" /* diffie-hellman-group1-sha1 value for p */ @@ -39,6 +40,89 @@ const unsigned char dh_p_14[DH_P_14_LEN] = { 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +#ifdef DROPBEAR_DH_GROUP15 +/* diffie-hellman-group15-sha256 value for p */ +const unsigned char dh_p_15[DH_P_15_LEN] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, + 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, + 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, + 0x3B, 0x13, 0x9B, 0x22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x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, + 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, + 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, + 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, + 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, + 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, + 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, + 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, + 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, + 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, + 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, + 0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, + 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, + 0xA9, 0x3A, 0xD2, 0xCA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +#endif /* DROPBEAR_DH_GROUP15 */ + + +#ifdef DROPBEAR_DH_GROUP16 +/* diffie-hellman-group16-256 value for p */ +const unsigned char dh_p_16[DH_P_16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, 0x43, 0xDB, 0x5B, 0xFC, + 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01, 0x1A, + 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, + 0x5B, 0x26, 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C, 0x1A, 0x94, 0x68, + 0x34, 0xB6, 0x15, 0x0B, 0xDA, 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, + 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, 0xFC, 0x14, 0x1F, + 0xBE, 0xCA, 0xA6, 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, 0xB2, + 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2, 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, + 0xED, 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF, 0xB8, 0x1B, 0xDD, 0x76, + 0x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9, 0x93, + 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, + 0xC0, 0x8F, 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +#endif /* DROPBEAR_DH_GROUP16 */ + /* Same for group1 and group14 */ const int DH_G_VAL = 2; diff --git a/dh_groups.h b/dh_groups.h index b210def..7fadac2 100644 --- a/dh_groups.h +++ b/dh_groups.h @@ -1,10 +1,23 @@ #ifndef DROPBEAR_DH_GROUPS_H #define DROPBEAR_DH_GROUPS_H +#include "options.h" #define DH_P_1_LEN 128 extern const unsigned char dh_p_1[DH_P_1_LEN]; #define DH_P_14_LEN 256 extern const unsigned char dh_p_14[DH_P_14_LEN]; + +#ifdef DROPBEAR_DH_GROUP15 +#define DH_P_15_LEN 384 +extern const unsigned char dh_p_15[DH_P_15_LEN]; +#endif + +#ifdef DROPBEAR_DH_GROUP16 +#define DH_P_16_LEN 512 +extern const unsigned char dh_p_16[DH_P_16_LEN]; +#endif + + extern const int DH_G_VAL; diff --git a/options.h b/options.h index 27e2a02..1be412b 100644 --- a/options.h +++ b/options.h @@ -152,6 +152,11 @@ If you test it please contact the Dropbear author */ * on x86-64 */ #define DROPBEAR_ECDSA +/* These larger DH groups (3072 and 4096 bit respectively) add to binary size + and may be significantly slower. Usually ECDH or curve25519 will be a better option */ +/*#define DROPBEAR_DH_GROUP15*/ +/*#define DROPBEAR_DH_GROUP16*/ + /* Generate hostkeys as-needed when the first connection using that key type occurs. This avoids the need to otherwise run "dropbearkey" and avoids some problems with badly seeded /dev/urandom when systems first boot. From 61b49ea2e3bd77c15a016070137ef35fa650e1a1 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 19 Jan 2016 00:22:23 +0800 Subject: [PATCH 17/29] Add note about OpenSSH origin --- scp.c | 3 +++ scpmisc.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/scp.c b/scp.c index 70f45e3..4f6a579 100644 --- a/scp.c +++ b/scp.c @@ -1,3 +1,6 @@ +/* Dropbear Note: This file is based on OpenSSH 4.3p2. Avoid unnecessary + changes to simplify future updates */ + /* * scp - secure remote copy. This is basically patched BSD rcp which * uses ssh to do the data transfer (instead of using rcmd). diff --git a/scpmisc.c b/scpmisc.c index ec4df35..e60cbe8 100644 --- a/scpmisc.c +++ b/scpmisc.c @@ -1,3 +1,6 @@ +/* Dropbear Note: This file is based on OpenSSH 4.3p2. Avoid unnecessary + changes to simplify future updates */ + /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * From 6453b5b70ea151ad1f378d39ff42ade81f87d834 Mon Sep 17 00:00:00 2001 From: Michael Witten Date: Tue, 19 Jan 2016 00:23:19 +0800 Subject: [PATCH 18/29] scp: Have `fatal()' append a newline to the message Date: Wed, 4 Nov 2015 20:33:19 -0000 It would seem that it's standard practice not to include a newline in the message text, but that results in poor formatting, as a shell's command line then begins on the line of the error message itself. This commit simply instructs `fatal()' to append a newline after the message, which should be suitable behavior for all of the invocations I've come across. --- scpmisc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/scpmisc.c b/scpmisc.c index e60cbe8..d99e358 100644 --- a/scpmisc.c +++ b/scpmisc.c @@ -226,6 +226,7 @@ void fatal(char* fmt,...) va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); + fputc('\n', stderr); exit(255); } From de70b02c2f357d6a2fd51b2de3bec2e0f345d5b1 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 19 Jan 2016 00:34:37 +0800 Subject: [PATCH 19/29] Don't fail if can't get the username --- scp.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scp.c b/scp.c index 4f6a579..8c94ec8 100644 --- a/scp.c +++ b/scp.c @@ -289,7 +289,6 @@ int okname(char *); void run_err(const char *,...); void verifydir(char *); -struct passwd *pwd; uid_t userid; int errs, remin, remout; int pflag, iamremote, iamrecursive, targetshouldbedirectory; @@ -396,9 +395,6 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if ((pwd = getpwuid(userid = getuid())) == NULL) - fatal("unknown user %u", (u_int) userid); - if (!isatty(STDERR_FILENO)) showprogress = 0; @@ -514,7 +510,7 @@ toremote(char *targ, int argc, char **argv) host = cleanhostname(host); suser = argv[i]; if (*suser == '\0') - suser = pwd->pw_name; + continue; /* pretend there wasn't any @ at all */ else if (!okname(suser)) continue; addargs(&alist, "-l"); @@ -582,7 +578,7 @@ tolocal(int argc, char **argv) *host++ = 0; suser = argv[i]; if (*suser == '\0') - suser = pwd->pw_name; + suser = NULL; } host = cleanhostname(host); len = strlen(src) + CMDNEEDS + 20; From 18681875e30e1ea251914417829fdbb50534c9ba Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 9 Mar 2016 22:45:40 +0800 Subject: [PATCH 20/29] Validate xauth input --- svr-x11fwd.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/svr-x11fwd.c b/svr-x11fwd.c index 144ec0b..7fe9a3a 100644 --- a/svr-x11fwd.c +++ b/svr-x11fwd.c @@ -42,11 +42,29 @@ static void x11accept(struct Listener* listener, int sock); static int bindport(int fd); static int send_msg_channel_open_x11(int fd, struct sockaddr_in* addr); +/* Check untrusted xauth strings for metacharacters */ +/* Returns DROPBEAR_SUCCESS/DROPBEAR_FAILURE */ +static int +xauth_valid_string(const char *s) +{ + size_t i; + + for (i = 0; s[i] != '\0'; i++) { + if (!isalnum(s[i]) && + s[i] != '.' && s[i] != ':' && s[i] != '/' && + s[i] != '-' && s[i] != '_') { + return DROPBEAR_FAILURE; + } + } + return DROPBEAR_SUCCESS; +} + + /* called as a request for a session channel, sets up listening X11 */ /* returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ int x11req(struct ChanSess * chansess) { - int fd; + int fd = -1; if (!svr_pubkey_allows_x11fwd()) { return DROPBEAR_FAILURE; @@ -62,6 +80,11 @@ int x11req(struct ChanSess * chansess) { chansess->x11authcookie = buf_getstring(ses.payload, NULL); chansess->x11screennum = buf_getint(ses.payload); + if (xauth_valid_string(chansess->x11authprot) == DROPBEAR_FAILURE || + xauth_valid_string(chansess->x11authcookie) == DROPBEAR_FAILURE) { + dropbear_log(LOG_WARNING, "Bad xauth request"); + goto fail; + } /* create listening socket */ fd = socket(PF_INET, SOCK_STREAM, 0); if (fd < 0) { @@ -159,7 +182,7 @@ void x11setauth(struct ChanSess *chansess) { return; } - /* popen is a nice function - code is strongly based on OpenSSH's */ + /* code is strongly based on OpenSSH's */ authprog = popen(XAUTH_COMMAND, "w"); if (authprog) { fprintf(authprog, "add %s %s %s\n", From 97dff151ae2c6c5a622b0d625c2e4764de62ca84 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 9 Mar 2016 22:54:15 +0800 Subject: [PATCH 21/29] 2016.72 --- CHANGES | 5 +++++ sysoptions.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 7b1e2da..d9d6029 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +2016.72 - 9 March 2016 + +- Validate X11 forwarding input. Could allow bypass of authorized_keys command= restrictions, + found by github.com/tintinweb. Thanks for Damien Miller for a patch. + 2015.71 - 3 December 2015 - Fix "bad buf_incrpos" when data is transferred, broke in 2015.69 diff --git a/sysoptions.h b/sysoptions.h index a29cbbe..85ef718 100644 --- a/sysoptions.h +++ b/sysoptions.h @@ -4,7 +4,7 @@ *******************************************************************/ #ifndef DROPBEAR_VERSION -#define DROPBEAR_VERSION "2015.71" +#define DROPBEAR_VERSION "2016.72" #endif #define LOCAL_IDENT "SSH-2.0-dropbear_" DROPBEAR_VERSION From 7e5fe1d8139a9bc03186a31676794204ca61590c Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 9 Mar 2016 22:54:51 +0800 Subject: [PATCH 22/29] debian changelog --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 79ea117..9a3d08e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,8 @@ -dropbear (2015.71-0.1) unstable; urgency=low +dropbear (2016.72-0.1) unstable; urgency=low * New upstream release. - -- Matt Johnston Thu, 3 Dec 2015 22:52:58 +0800 + -- Matt Johnston Wed, 10 Mar 2016 22:52:58 +0800 dropbear (2015.70-0.1) unstable; urgency=low From 9e1d038a65dac88f97265939b2e7b217e6641957 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Thu, 10 Mar 2016 20:50:24 +0800 Subject: [PATCH 23/29] Added tag DROPBEAR_2016.72 for changeset 78b12b6549be --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 032317e..cf18375 100644 --- a/.hgtags +++ b/.hgtags @@ -50,3 +50,4 @@ cbd674d63cd4f3781464a8d4056a5506c8ae926f DROPBEAR_2015.67 809feaa9408f036734129c77f2b3c7e779d4f099 DROPBEAR_2015.68 1637dbd262124d113e52967df46afd6c715e4fad DROPBEAR_2015.69 79a6ef02307d05cb9dda10465cb5b807baa8f62e DROPBEAR_2015.70 +78b12b6549be08b0bea3da329b2578060a76ca31 DROPBEAR_2016.72 From 9cb325ee6fb8b164d0bef0b5a44073496abc41b2 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Thu, 10 Mar 2016 20:50:31 +0800 Subject: [PATCH 24/29] Added signature for changeset fd1981f41c62 --- .hgsigs | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgsigs b/.hgsigs index c3ac393..683577c 100644 --- a/.hgsigs +++ b/.hgsigs @@ -18,3 +18,4 @@ a687f835236c7025b5cb2968fe9c4ebc4a49f0ea 0 iQIcBAABCgAGBQJVxg62AAoJEPSYMBLCC7qsC ef4b26364b0cdda1084751d7de3d76c589e2d9cb 0 iQIcBAABCgAGBQJVxg7BAAoJEESTFJTynGdz9Q4P/A0Kq4H52rQqxq42PoEMFbVQIUfkFzyWjAz8eEGLmP5x5/sdpyxZDEyBSUG55uyNvOPTHE+Sd3t2h2Iieq749qwYgqggXC0P+C0zGzW3hB5Rv6dTUrKN1yCyaWE2tY488RsyVlcAs4vrp1Cum5Gv8/BUVKjzZmkZ1iq/3RyrvbLEiLoMrcLnQ+sUdaYHvfEwxDbzpOEvepg8iDJBitTrfG9xHp9otX6ucahwn1EumFvC5mvUxbiQ9jv76t4FJztjMoB24hPCH9T1FjB8uNsoM+j2Z67r81eJrGgNpJzjX0S3lY/AADZGhfGnfybTM9gFuQayIJuCJqduQibVwYkAAnPi17NmbdwPu0Rdz55oU+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fDUas4ERRQWYkX+68GyzO9GrkYFle931Akw2K6ZZfUuiC2TrF5xv1eRP1Zm2GX481U4ZGFTI8IzZL8sVQ6tvzq2Mxsecu589JNui9aB2d8Gp2Su/E2zn0h0ShIRmviGzf2HiBt+Bnji5X2h/fJKWbLaWge0MdOU5Jidfyh9k0YT7xo4piJLJYSaZ3nv+j4jTYnTfL7uYvuWbYkJ1T32aQVCan7Eup3BFAgQjzbWYi1XQVg6fvu8uHPpS3tNNA9EAMeeyTyg1l6zI2EIU5gPfd/dKmdyotY2lZBkFZNJqFkKRZuzjWekcw7hAxS+Bd68GKklt/DGrQiVycAgimqwXrfkzzQagawq2fXL2uXB8ghlsyxKLSQPnAtBF2Jcn5FH2z7HOQ+e18ZrFfNy0cYa/4OdH6K5aK1igTzhZZP2Urn0 From 26a1a0a3bc4420e57334d3ecc827f14ffcb9f24a Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Thu, 10 Mar 2016 21:35:23 +0800 Subject: [PATCH 25/29] allow specifying dropbearmulti command as an argument --- dbmulti.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/dbmulti.c b/dbmulti.c index 8d99656..204e9a3 100644 --- a/dbmulti.c +++ b/dbmulti.c @@ -26,17 +26,13 @@ /* definitions are cleanest if we just put them here */ int dropbear_main(int argc, char ** argv); +int cli_main(int argc, char ** argv); int dropbearkey_main(int argc, char ** argv); int dropbearconvert_main(int argc, char ** argv); int scp_main(int argc, char ** argv); -int main(int argc, char ** argv) { - - char * progname; - - if (argc > 0) { - /* figure which form we're being called as */ - progname = basename(argv[0]); +static int runprog(const char *progname, int argc, char ** argv, int *match) { + *match = DROPBEAR_SUCCESS; #ifdef DBMULTI_dropbear if (strcmp(progname, "dropbear") == 0) { @@ -64,10 +60,28 @@ int main(int argc, char ** argv) { return scp_main(argc, argv); } #endif + *match = DROPBEAR_FAILURE; + return 1; +} + +int main(int argc, char ** argv) { + int i; + for (i = 0; i < 2; i++) { + /* Try symlink first, then try as an argument eg "dropbearmulti dbclient host ..." */ + if (argc > i) { + int match, res; + /* figure which form we're being called as */ + const char* progname = basename(argv[i]); + res = runprog(progname, argc-i, &argv[i], &match); + if (match == DROPBEAR_SUCCESS) { + return res; + } + } } fprintf(stderr, "Dropbear SSH multi-purpose v%s\n" - "Make a symlink pointing at this binary with one of the following names:\n" + "Make a symlink pointing at this binary with one of the\n" + "following names or run 'dropbearmulti '.\n" #ifdef DBMULTI_dropbear "'dropbear' - the Dropbear server\n" #endif From fdc61f3ab2c07f3f8d0546ee83b1a6776cc1786e Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 12 Mar 2016 16:21:13 +0800 Subject: [PATCH 26/29] Get rid of group15, move group16 to sha512. New groups are disabled by default pending draft-ietf-curdle-ssh-kex-sha2-02 being finalised --- common-algo.c | 30 ++++++++++++++++++------------ dh_groups.c | 46 ++++++---------------------------------------- dh_groups.h | 14 +++++++------- options.h | 10 +++++----- sysoptions.h | 9 +++++++-- 5 files changed, 43 insertions(+), 66 deletions(-) diff --git a/common-algo.c b/common-algo.c index 1841d67..c2cef77 100644 --- a/common-algo.c +++ b/common-algo.c @@ -248,14 +248,17 @@ algo_type sshhostkey[] = { {NULL, 0, NULL, 0, NULL} }; +#if DROPBEAR_DH_GROUP1 static const struct dropbear_kex kex_dh_group1 = {DROPBEAR_KEX_NORMAL_DH, dh_p_1, DH_P_1_LEN, NULL, &sha1_desc }; -static const struct dropbear_kex kex_dh_group14_sha1 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha1_desc }; -static const struct dropbear_kex kex_dh_group14_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha256_desc }; -#ifdef DROPBEAR_DH_GROUP15 -static const struct dropbear_kex kex_dh_group15_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_15, DH_P_15_LEN, NULL, &sha256_desc }; #endif -#ifdef DROPBEAR_DH_GROUP16 -static const struct dropbear_kex kex_dh_group16_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_16, DH_P_16_LEN, NULL, &sha256_desc }; +#if DROPBEAR_DH_GROUP14 +static const struct dropbear_kex kex_dh_group14_sha1 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha1_desc }; +#if DROPBEAR_DH_GROUP14_256 +static const struct dropbear_kex kex_dh_group14_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha256_desc }; +#endif +#endif +#if DROPBEAR_DH_GROUP16 +static const struct dropbear_kex kex_dh_group16_sha512 = {DROPBEAR_KEX_NORMAL_DH, dh_p_16, DH_P_16_LEN, NULL, &sha512_desc }; #endif /* These can't be const since dropbear_ecc_fill_dp() fills out @@ -292,14 +295,17 @@ algo_type sshkex[] = { {"ecdh-sha2-nistp256", 0, &kex_ecdh_nistp256, 1, NULL}, #endif #endif +#if DROPBEAR_DH_GROUP14 +#if DROPBEAR_DH_GROUP14_256 {"diffie-hellman-group14-sha256", 0, &kex_dh_group14_sha256, 1, NULL}, - {"diffie-hellman-group14-sha1", 0, &kex_dh_group14_sha1, 1, NULL}, - {"diffie-hellman-group1-sha1", 0, &kex_dh_group1, 1, NULL}, -#ifdef DROPBEAR_DH_GROUP15 - {"diffie-hellman-group15-sha256", 0, &kex_dh_group15_sha256, 1, NULL}, #endif -#ifdef DROPBEAR_DH_GROUP16 - {"diffie-hellman-group16-sha256", 0, &kex_dh_group16_sha256, 1, NULL}, + {"diffie-hellman-group14-sha1", 0, &kex_dh_group14_sha1, 1, NULL}, +#endif +#if DROPBEAR_DH_GROUP1 + {"diffie-hellman-group1-sha1", 0, &kex_dh_group1, 1, NULL}, +#endif +#if DROPBEAR_DH_GROUP16 + {"diffie-hellman-group16-sha512", 0, &kex_dh_group16_sha512, 1, NULL}, #endif #ifdef USE_KEXGUESS2 {KEXGUESS2_ALGO_NAME, KEXGUESS2_ALGO_ID, NULL, 1, NULL}, diff --git a/dh_groups.c b/dh_groups.c index 205dea3..44ee830 100644 --- a/dh_groups.c +++ b/dh_groups.c @@ -1,6 +1,7 @@ #include "options.h" #include "dh_groups.h" +#if DROPBEAR_DH_GROUP1 /* diffie-hellman-group1-sha1 value for p */ const unsigned char dh_p_1[DH_P_1_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, @@ -14,7 +15,9 @@ const unsigned char dh_p_1[DH_P_1_LEN] = { 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +#endif /* DROPBEAR_DH_GROUP1 */ +#if DROPBEAR_DH_GROUP14 /* diffie-hellman-group14-sha1 value for p */ const unsigned char dh_p_14[DH_P_14_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, @@ -39,46 +42,9 @@ const unsigned char dh_p_14[DH_P_14_LEN] = { 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +#endif /* DROPBEAR_DH_GROUP14 */ -#ifdef DROPBEAR_DH_GROUP15 -/* diffie-hellman-group15-sha256 value for p */ -const unsigned char dh_p_15[DH_P_15_LEN] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, - 0x21, 0x68, 0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xCA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; -#endif /* DROPBEAR_DH_GROUP15 */ - - -#ifdef DROPBEAR_DH_GROUP16 +#if DROPBEAR_DH_GROUP16 /* diffie-hellman-group16-256 value for p */ const unsigned char dh_p_16[DH_P_16_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, @@ -123,6 +89,6 @@ const unsigned char dh_p_16[DH_P_16_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; #endif /* DROPBEAR_DH_GROUP16 */ -/* Same for group1 and group14 */ +/* Same for all groups */ const int DH_G_VAL = 2; diff --git a/dh_groups.h b/dh_groups.h index 7fadac2..cddaa17 100644 --- a/dh_groups.h +++ b/dh_groups.h @@ -2,17 +2,17 @@ #define DROPBEAR_DH_GROUPS_H #include "options.h" +#if DROPBEAR_DH_GROUP1 #define DH_P_1_LEN 128 extern const unsigned char dh_p_1[DH_P_1_LEN]; -#define DH_P_14_LEN 256 -extern const unsigned char dh_p_14[DH_P_14_LEN]; - -#ifdef DROPBEAR_DH_GROUP15 -#define DH_P_15_LEN 384 -extern const unsigned char dh_p_15[DH_P_15_LEN]; #endif -#ifdef DROPBEAR_DH_GROUP16 +#if DROPBEAR_DH_GROUP14 +#define DH_P_14_LEN 256 +extern const unsigned char dh_p_14[DH_P_14_LEN]; +#endif + +#if DROPBEAR_DH_GROUP16 #define DH_P_16_LEN 512 extern const unsigned char dh_p_16[DH_P_16_LEN]; #endif diff --git a/options.h b/options.h index 1be412b..0c51bb1 100644 --- a/options.h +++ b/options.h @@ -152,11 +152,6 @@ If you test it please contact the Dropbear author */ * on x86-64 */ #define DROPBEAR_ECDSA -/* These larger DH groups (3072 and 4096 bit respectively) add to binary size - and may be significantly slower. Usually ECDH or curve25519 will be a better option */ -/*#define DROPBEAR_DH_GROUP15*/ -/*#define DROPBEAR_DH_GROUP16*/ - /* Generate hostkeys as-needed when the first connection using that key type occurs. This avoids the need to otherwise run "dropbearkey" and avoids some problems with badly seeded /dev/urandom when systems first boot. @@ -173,6 +168,11 @@ If you test it please contact the Dropbear author */ * ECDSA above */ #define DROPBEAR_ECDH +/* Group14 (2048 bit) is recommended. Group1 is less secure (1024 bit) though + is the only option for interoperability with some older SSH programs */ +#define DROPBEAR_DH_GROUP1 1 +#define DROPBEAR_DH_GROUP14 1 + /* Control the memory/performance/compression tradeoff for zlib. * Set windowBits=8 for least memory usage, see your system's * zlib.h for full details. diff --git a/sysoptions.h b/sysoptions.h index 85ef718..8ce4361 100644 --- a/sysoptions.h +++ b/sysoptions.h @@ -113,20 +113,25 @@ #define RSA_BLINDING /* hashes which will be linked and registered */ -#if defined(DROPBEAR_SHA2_256_HMAC) || defined(DROPBEAR_ECC_256) || defined(DROPBEAR_CURVE25519) +#if defined(DROPBEAR_SHA2_256_HMAC) || defined(DROPBEAR_ECC_256) || defined(DROPBEAR_CURVE25519) || DROPBEAR_DH_GROUP14 #define DROPBEAR_SHA256 #endif #if defined(DROPBEAR_ECC_384) #define DROPBEAR_SHA384 #endif /* LTC SHA384 depends on SHA512 */ -#if defined(DROPBEAR_SHA2_512_HMAC) || defined(DROPBEAR_ECC_521) || defined(DROPBEAR_ECC_384) +#if defined(DROPBEAR_SHA2_512_HMAC) || defined(DROPBEAR_ECC_521) || defined(DROPBEAR_ECC_384) || DROPBEAR_DH_GROUP16 #define DROPBEAR_SHA512 #endif #if defined(DROPBEAR_MD5_HMAC) #define DROPBEAR_MD5 #endif +/* These are disabled in Dropbear 2016.73 by default since the spec + draft-ietf-curdle-ssh-kex-sha2-02 is under development. */ +#define DROPBEAR_DH_GROUP14_256 0 +#define DROPBEAR_DH_GROUP16 0 + /* roughly 2x 521 bits */ #define MAX_ECC_SIZE 140 From 4615631d83419aefd372008fc483b13834ad91a1 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 15 Mar 2016 22:03:23 +0800 Subject: [PATCH 27/29] update CHANGES --- CHANGES | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGES b/CHANGES index a6cd0b6..ca6e7bb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,22 @@ +- Fix crash when fallback initshells() is used, reported by Michael Nowak and Mike Tzou + +- Support syslog in dbclient, option -o usesyslog=yes. Patch from Konstantin Tokarev + +- Kill a proxycommand when dbclient exits, patch from Konstantin Tokarev + +- Option to exit when a TCP forward fails, patch from Konstantin Tokarev + +- New "-o" option parsing from Konstantin Tokarev. This allows handling some extra options + in the style of OpenSSH, though implementing all OpenSSH options is not planned. + +- Various cleanups for issues found by a lint tool, patch from Francois Perrad + +- Allow specifying commands eg "dropbearmulti dbclient ..." instead of symlinks + +- Fix tab indent consistency, patch from Francois Perrad + +- Fix issues found by cppcheck, reported by Mike Tzou + 2016.72 - 9 March 2016 - Validate X11 forwarding input. Could allow bypass of authorized_keys command= restrictions, From e255f0590b9c60d4eb3f006fa78880c568a92e68 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 15 Mar 2016 22:04:13 +0800 Subject: [PATCH 28/29] remove unused loginrec_set_addr() --- loginrec.c | 15 --------------- loginrec.h | 4 ---- 2 files changed, 19 deletions(-) diff --git a/loginrec.c b/loginrec.c index d6ec75f..1b8b143 100644 --- a/loginrec.c +++ b/loginrec.c @@ -305,21 +305,6 @@ login_set_current_time(struct logininfo *li) li->tv_usec = tv.tv_usec; } -/* copy a sockaddr_* into our logininfo */ -void -login_set_addr(struct logininfo *li, const struct sockaddr *sa, - const unsigned int sa_size) -{ - unsigned int bufsize = sa_size; - - /* make sure we don't overrun our union */ - if (sizeof(li->hostaddr) < sa_size) - bufsize = sizeof(li->hostaddr); - - memcpy((void *)&(li->hostaddr.sa), (const void *)sa, bufsize); -} - - /** ** login_write: Call low-level recording functions based on autoconf ** results diff --git a/loginrec.h b/loginrec.h index 830c045..b2e3778 100644 --- a/loginrec.h +++ b/loginrec.h @@ -173,10 +173,6 @@ int login_utmp_only(struct logininfo *li); int login_write (struct logininfo *li); int login_log_entry(struct logininfo *li); -/* set the network address based on network address type */ -void login_set_addr(struct logininfo *li, const struct sockaddr *sa, - const unsigned int sa_size); - /* produce various forms of the line filename */ char *line_fullname(char *dst, const char *src, size_t dstsize); char *line_stripname(char *dst, const char *src, size_t dstsize); From e7828bb9113fc4e43a30723d82d7c6187fba08ef Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 15 Mar 2016 22:40:15 +0800 Subject: [PATCH 29/29] cast return type to enum --- signkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signkey.c b/signkey.c index 55f34e7..a043d0d 100644 --- a/signkey.c +++ b/signkey.c @@ -93,7 +93,7 @@ enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen) } #endif - return i; + return (enum signkey_type)i; } }