mirror of
https://github.com/clearml/dropbear
synced 2025-04-03 12:30:55 +00:00
- Fixed twofish algorithm naming so it actually works.
- Added support for aes256, twofish256 and sha1-96 - Fixed some debugging statements --HG-- extra : convert_revision : 598835dadaddb1e95d4ac99f8a1be4ba51639000
This commit is contained in:
parent
71c07ed930
commit
ca77392bd1
@ -32,6 +32,10 @@
|
|||||||
/* Mappings for ciphers, parameters are
|
/* Mappings for ciphers, parameters are
|
||||||
{&cipher_desc, keysize, blocksize} */
|
{&cipher_desc, keysize, blocksize} */
|
||||||
|
|
||||||
|
#ifdef DROPBEAR_AES256_CBC
|
||||||
|
static const struct dropbear_cipher dropbear_aes256 =
|
||||||
|
{&aes_desc, 32, 16};
|
||||||
|
#endif
|
||||||
#ifdef DROPBEAR_AES128_CBC
|
#ifdef DROPBEAR_AES128_CBC
|
||||||
static const struct dropbear_cipher dropbear_aes128 =
|
static const struct dropbear_cipher dropbear_aes128 =
|
||||||
{&aes_desc, 16, 16};
|
{&aes_desc, 16, 16};
|
||||||
@ -40,6 +44,10 @@ static const struct dropbear_cipher dropbear_aes128 =
|
|||||||
static const struct dropbear_cipher dropbear_blowfish =
|
static const struct dropbear_cipher dropbear_blowfish =
|
||||||
{&blowfish_desc, 16, 8};
|
{&blowfish_desc, 16, 8};
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef DROPBEAR_TWOFISH256_CBC
|
||||||
|
static const struct dropbear_cipher dropbear_twofish256 =
|
||||||
|
{&twofish_desc, 32, 16};
|
||||||
|
#endif
|
||||||
#ifdef DROPBEAR_TWOFISH128_CBC
|
#ifdef DROPBEAR_TWOFISH128_CBC
|
||||||
static const struct dropbear_cipher dropbear_twofish128 =
|
static const struct dropbear_cipher dropbear_twofish128 =
|
||||||
{&twofish_desc, 16, 16};
|
{&twofish_desc, 16, 16};
|
||||||
@ -60,6 +68,10 @@ const struct dropbear_cipher dropbear_nocipher =
|
|||||||
static const struct dropbear_hash dropbear_sha1 =
|
static const struct dropbear_hash dropbear_sha1 =
|
||||||
{&sha1_desc, 20, 20};
|
{&sha1_desc, 20, 20};
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef DROPBEAR_SHA1_96_HMAC
|
||||||
|
static const struct dropbear_hash dropbear_sha1_96 =
|
||||||
|
{&sha1_desc, 20, 12};
|
||||||
|
#endif
|
||||||
#ifdef DROPBEAR_MD5_HMAC
|
#ifdef DROPBEAR_MD5_HMAC
|
||||||
static const struct dropbear_hash dropbear_md5 =
|
static const struct dropbear_hash dropbear_md5 =
|
||||||
{&md5_desc, 16, 16};
|
{&md5_desc, 16, 16};
|
||||||
@ -75,19 +87,28 @@ algo_type sshciphers[] = {
|
|||||||
#ifdef DROPBEAR_AES128_CBC
|
#ifdef DROPBEAR_AES128_CBC
|
||||||
{"aes128-cbc", 0, (void*)&dropbear_aes128, 1},
|
{"aes128-cbc", 0, (void*)&dropbear_aes128, 1},
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef DROPBEAR_3DES_CBC
|
||||||
|
{"3des-cbc", 0, (void*)&dropbear_3des, 1},
|
||||||
|
#endif
|
||||||
|
#ifdef DROPBEAR_AES256_CBC
|
||||||
|
{"aes256-cbc", 0, (void*)&dropbear_aes256, 1},
|
||||||
|
#endif
|
||||||
#ifdef DROPBEAR_BLOWFISH_CBC
|
#ifdef DROPBEAR_BLOWFISH_CBC
|
||||||
{"blowfish-cbc", 0, (void*)&dropbear_blowfish, 1},
|
{"blowfish-cbc", 0, (void*)&dropbear_blowfish, 1},
|
||||||
#endif
|
#endif
|
||||||
#ifdef DROPBEAR_TWOFISH128_CBC
|
#ifdef DROPBEAR_TWOFISH256_CBC
|
||||||
{"twofish-cbc", 0, (void*)&dropbear_twofish128, 1},
|
{"twofish256-cbc", 0, (void*)&dropbear_twofish256, 1},
|
||||||
#endif
|
#endif
|
||||||
#ifdef DROPBEAR_3DES_CBC
|
#ifdef DROPBEAR_TWOFISH128_CBC
|
||||||
{"3des-cbc", 0, (void*)&dropbear_3des, 1},
|
{"twofish128-cbc", 0, (void*)&dropbear_twofish128, 1},
|
||||||
#endif
|
#endif
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
algo_type sshhashes[] = {
|
algo_type sshhashes[] = {
|
||||||
|
#ifdef DROPBEAR_SHA1_96_HMAC
|
||||||
|
{"hmac-sha1-96", 0, (void*)&dropbear_sha1_96, 1},
|
||||||
|
#endif
|
||||||
#ifdef DROPBEAR_SHA1_HMAC
|
#ifdef DROPBEAR_SHA1_HMAC
|
||||||
{"hmac-sha1", 0, (void*)&dropbear_sha1, 1},
|
{"hmac-sha1", 0, (void*)&dropbear_sha1, 1},
|
||||||
#endif
|
#endif
|
||||||
|
15
common-kex.c
15
common-kex.c
@ -622,7 +622,7 @@ static void read_kex_algos() {
|
|||||||
erralgo = "enc c->s";
|
erralgo = "enc c->s";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
TRACE(("c2s is %s", c2s_cipher_algo->name))
|
TRACE(("enc c2s is %s", c2s_cipher_algo->name))
|
||||||
|
|
||||||
/* encryption_algorithms_server_to_client */
|
/* encryption_algorithms_server_to_client */
|
||||||
s2c_cipher_algo = ses.buf_match_algo(ses.payload, sshciphers, &goodguess);
|
s2c_cipher_algo = ses.buf_match_algo(ses.payload, sshciphers, &goodguess);
|
||||||
@ -630,7 +630,7 @@ static void read_kex_algos() {
|
|||||||
erralgo = "enc s->c";
|
erralgo = "enc s->c";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
TRACE(("s2c is %s", s2c_cipher_algo->name))
|
TRACE(("enc s2c is %s", s2c_cipher_algo->name))
|
||||||
|
|
||||||
/* mac_algorithms_client_to_server */
|
/* mac_algorithms_client_to_server */
|
||||||
c2s_hash_algo = ses.buf_match_algo(ses.payload, sshhashes, &goodguess);
|
c2s_hash_algo = ses.buf_match_algo(ses.payload, sshhashes, &goodguess);
|
||||||
@ -638,6 +638,7 @@ static void read_kex_algos() {
|
|||||||
erralgo = "mac c->s";
|
erralgo = "mac c->s";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
TRACE(("hash c2s is %s", c2s_hash_algo->name))
|
||||||
|
|
||||||
/* mac_algorithms_server_to_client */
|
/* mac_algorithms_server_to_client */
|
||||||
s2c_hash_algo = ses.buf_match_algo(ses.payload, sshhashes, &goodguess);
|
s2c_hash_algo = ses.buf_match_algo(ses.payload, sshhashes, &goodguess);
|
||||||
@ -645,6 +646,7 @@ static void read_kex_algos() {
|
|||||||
erralgo = "mac s->c";
|
erralgo = "mac s->c";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
TRACE(("hash s2c is %s", s2c_hash_algo->name))
|
||||||
|
|
||||||
/* compression_algorithms_client_to_server */
|
/* compression_algorithms_client_to_server */
|
||||||
c2s_comp_algo = ses.buf_match_algo(ses.payload, sshcompress, &goodguess);
|
c2s_comp_algo = ses.buf_match_algo(ses.payload, sshcompress, &goodguess);
|
||||||
@ -652,6 +654,7 @@ static void read_kex_algos() {
|
|||||||
erralgo = "comp c->s";
|
erralgo = "comp c->s";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
TRACE(("hash c2s is %s", c2s_comp_algo->name))
|
||||||
|
|
||||||
/* compression_algorithms_server_to_client */
|
/* compression_algorithms_server_to_client */
|
||||||
s2c_comp_algo = ses.buf_match_algo(ses.payload, sshcompress, &goodguess);
|
s2c_comp_algo = ses.buf_match_algo(ses.payload, sshcompress, &goodguess);
|
||||||
@ -659,6 +662,7 @@ static void read_kex_algos() {
|
|||||||
erralgo = "comp s->c";
|
erralgo = "comp s->c";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
TRACE(("hash s2c is %s", s2c_comp_algo->name))
|
||||||
|
|
||||||
/* languages_client_to_server */
|
/* languages_client_to_server */
|
||||||
buf_eatstring(ses.payload);
|
buf_eatstring(ses.payload);
|
||||||
@ -701,13 +705,6 @@ static void read_kex_algos() {
|
|||||||
ses.newkeys->trans_algo_comp = s2c_comp_algo->val;
|
ses.newkeys->trans_algo_comp = s2c_comp_algo->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE(("enc algo recv %s", algo->name))
|
|
||||||
TRACE(("enc algo trans %s", algo->name))
|
|
||||||
TRACE(("mac algo recv %s", algo->name))
|
|
||||||
TRACE(("mac algo trans %s", algo->name))
|
|
||||||
TRACE(("comp algo recv %s", algo->name))
|
|
||||||
TRACE(("comp algo trans %s", algo->name))
|
|
||||||
|
|
||||||
/* reserved for future extensions */
|
/* reserved for future extensions */
|
||||||
buf_getint(ses.payload);
|
buf_getint(ses.payload);
|
||||||
return;
|
return;
|
||||||
|
33
options.h
33
options.h
@ -62,25 +62,30 @@ etc) slower (perhaps by 50%). Recommended for most small systems. */
|
|||||||
#define ENABLE_AGENTFWD
|
#define ENABLE_AGENTFWD
|
||||||
|
|
||||||
/* Encryption - at least one required.
|
/* Encryption - at least one required.
|
||||||
* RFC Draft requires 3DES, and recommends Blowfish, AES128 & Twofish128 */
|
* RFC Draft requires 3DES and recommends AES128 for interoperability.
|
||||||
|
* Including multiple keysize variants the same cipher
|
||||||
|
* (eg AES256 as well as AES128) will result in a minimal size increase.*/
|
||||||
#define DROPBEAR_AES128_CBC
|
#define DROPBEAR_AES128_CBC
|
||||||
#define DROPBEAR_BLOWFISH_CBC
|
|
||||||
#define DROPBEAR_TWOFISH128_CBC
|
|
||||||
#define DROPBEAR_3DES_CBC
|
#define DROPBEAR_3DES_CBC
|
||||||
|
#define DROPBEAR_AES256_CBC
|
||||||
|
#define DROPBEAR_BLOWFISH_CBC
|
||||||
|
#define DROPBEAR_TWOFISH256_CBC
|
||||||
|
#define DROPBEAR_TWOFISH128_CBC
|
||||||
|
|
||||||
/* Integrity - at least one required.
|
/* Message Integrity - at least one required.
|
||||||
* RFC Draft requires sha1-hmac, and recommends md5-hmac.
|
* RFC Draft requires sha1 and recommends sha1-96.
|
||||||
|
* sha1-96 may be of use for slow links, as it has a smaller overhead.
|
||||||
*
|
*
|
||||||
* Note: there's no point disabling sha1 to save space, since it's used in the
|
* Note: there's no point disabling sha1 to save space, since it's used
|
||||||
* for the random number generator and public-key cryptography anyway.
|
* for the random number generator and public-key cryptography anyway.
|
||||||
* Disabling it here will just stop it from being used as the integrity portion
|
* Disabling it here will just stop it from being used as the integrity portion
|
||||||
* of the ssh protocol.
|
* of the ssh protocol.
|
||||||
*
|
*
|
||||||
* These are also used for key fingerprints in logs (when pubkey auth is used),
|
* These hashes are also used for public key fingerprints in logs.
|
||||||
* MD5 fingerprints are printed if available, however SHA1 fingerprints will be
|
* If you disable MD5, Dropbear will fall back to SHA1 fingerprints,
|
||||||
* generated otherwise. This isn't exactly optimal, although SHA1 fingerprints
|
* which are not the standard form. */
|
||||||
* are not too hard to create from pubkeys if required. */
|
|
||||||
#define DROPBEAR_SHA1_HMAC
|
#define DROPBEAR_SHA1_HMAC
|
||||||
|
#define DROPBEAR_SHA1_96_HMAC
|
||||||
#define DROPBEAR_MD5_HMAC
|
#define DROPBEAR_MD5_HMAC
|
||||||
|
|
||||||
/* Hostkey/public key algorithms - at least one required, these are used
|
/* Hostkey/public key algorithms - at least one required, these are used
|
||||||
@ -310,6 +315,14 @@ etc) slower (perhaps by 50%). Recommended for most small systems. */
|
|||||||
|
|
||||||
#define DROPBEAR_MAX_CLI_PASS 1024
|
#define DROPBEAR_MAX_CLI_PASS 1024
|
||||||
|
|
||||||
|
#if defined(DROPBEAR_AES256_CBC) || defined(DROPBEAR_AES128_CBC)
|
||||||
|
#define DROPBEAR_AES_CBC
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(DROPBEAR_TWOFISH256_CBC) || defined(DROPBEAR_TWOFISH128_CBC)
|
||||||
|
#define DROPBEAR_TWOFISH_CBC
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_X11FWD
|
#ifndef ENABLE_X11FWD
|
||||||
#define DISABLE_X11FWD
|
#define DISABLE_X11FWD
|
||||||
#endif
|
#endif
|
||||||
|
27
packet.c
27
packet.c
@ -215,7 +215,7 @@ static void read_packet_init() {
|
|||||||
if ((len > MAX_PACKET_LEN) ||
|
if ((len > MAX_PACKET_LEN) ||
|
||||||
(len < MIN_PACKET_LEN + macsize) ||
|
(len < MIN_PACKET_LEN + macsize) ||
|
||||||
((len - macsize) % blocksize != 0)) {
|
((len - macsize) % blocksize != 0)) {
|
||||||
dropbear_exit("bad packet size");
|
dropbear_exit("bad packet size %d", len);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf_resize(ses.readbuf, len);
|
buf_resize(ses.readbuf, len);
|
||||||
@ -314,14 +314,13 @@ void decrypt_packet() {
|
|||||||
* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
|
* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
|
||||||
static int checkmac(buffer* macbuf, buffer* sourcebuf) {
|
static int checkmac(buffer* macbuf, buffer* sourcebuf) {
|
||||||
|
|
||||||
unsigned char macsize;
|
unsigned int macsize;
|
||||||
hmac_state hmac;
|
hmac_state hmac;
|
||||||
unsigned char tempbuf[MAX_MAC_LEN];
|
unsigned char tempbuf[MAX_MAC_LEN];
|
||||||
unsigned long hashsize;
|
unsigned long bufsize;
|
||||||
int len;
|
unsigned int len;
|
||||||
|
|
||||||
macsize = ses.keys->recv_algo_mac->hashsize;
|
macsize = ses.keys->recv_algo_mac->hashsize;
|
||||||
|
|
||||||
if (macsize == 0) {
|
if (macsize == 0) {
|
||||||
return DROPBEAR_SUCCESS;
|
return DROPBEAR_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -347,8 +346,8 @@ static int checkmac(buffer* macbuf, buffer* sourcebuf) {
|
|||||||
dropbear_exit("HMAC error");
|
dropbear_exit("HMAC error");
|
||||||
}
|
}
|
||||||
|
|
||||||
hashsize = sizeof(tempbuf);
|
bufsize = sizeof(tempbuf);
|
||||||
if (hmac_done(&hmac, tempbuf, &hashsize) != CRYPT_OK) {
|
if (hmac_done(&hmac, tempbuf, &bufsize) != CRYPT_OK) {
|
||||||
dropbear_exit("HMAC error");
|
dropbear_exit("HMAC error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,15 +523,15 @@ void encrypt_packet() {
|
|||||||
/* Create the packet mac, and append H(seqno|clearbuf) to the output */
|
/* Create the packet mac, and append H(seqno|clearbuf) to the output */
|
||||||
static void writemac(buffer * outputbuffer, buffer * clearwritebuf) {
|
static void writemac(buffer * outputbuffer, buffer * clearwritebuf) {
|
||||||
|
|
||||||
int macsize;
|
unsigned int macsize;
|
||||||
unsigned char seqbuf[4];
|
unsigned char seqbuf[4];
|
||||||
unsigned long hashsize;
|
unsigned char tempbuf[MAX_MAC_LEN];
|
||||||
|
unsigned long bufsize;
|
||||||
hmac_state hmac;
|
hmac_state hmac;
|
||||||
|
|
||||||
TRACE(("enter writemac"))
|
TRACE(("enter writemac"))
|
||||||
|
|
||||||
macsize = ses.keys->trans_algo_mac->hashsize;
|
macsize = ses.keys->recv_algo_mac->hashsize;
|
||||||
|
|
||||||
if (macsize > 0) {
|
if (macsize > 0) {
|
||||||
/* calculate the mac */
|
/* calculate the mac */
|
||||||
if (hmac_init(&hmac,
|
if (hmac_init(&hmac,
|
||||||
@ -557,12 +556,12 @@ static void writemac(buffer * outputbuffer, buffer * clearwritebuf) {
|
|||||||
dropbear_exit("HMAC error");
|
dropbear_exit("HMAC error");
|
||||||
}
|
}
|
||||||
|
|
||||||
hashsize = macsize;
|
bufsize = sizeof(tempbuf);
|
||||||
if (hmac_done(&hmac, buf_getwriteptr(outputbuffer, macsize), &hashsize)
|
if (hmac_done(&hmac, tempbuf, &bufsize)
|
||||||
!= CRYPT_OK) {
|
!= CRYPT_OK) {
|
||||||
dropbear_exit("HMAC error");
|
dropbear_exit("HMAC error");
|
||||||
}
|
}
|
||||||
buf_incrwritepos(outputbuffer, macsize);
|
buf_putbytes(outputbuffer, tempbuf, macsize);
|
||||||
}
|
}
|
||||||
TRACE(("leave writemac"))
|
TRACE(("leave writemac"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user