1
1

tests: Cover also compression with unit tests

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Jakub Jelen 2018-12-04 14:15:04 +01:00 коммит произвёл Andreas Schneider
родитель 31bc83f366
Коммит cf6f1e7a64

Просмотреть файл

@ -41,9 +41,10 @@ static SSH_PACKET_CALLBACK(copy_packet_data){
return 0;
}
static void torture_packet(const char *cipher,
const char *mac_type, size_t payload_len) {
static void
torture_packet(const char *cipher, const char *mac_type,
const char *comp_type, size_t payload_len)
{
ssh_session session = ssh_new();
int verbosity = torture_libssh_verbosity();
struct ssh_crypto_struct *crypto;
@ -61,6 +62,7 @@ static void torture_packet(const char *cipher,
.callbacks=callbacks,
.user=response
};
int cmp;
assert_non_null(session);
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
@ -75,8 +77,8 @@ static void torture_packet(const char *cipher,
crypto->kex_methods[SSH_CRYPT_S_C] = strdup(cipher);
crypto->kex_methods[SSH_MAC_C_S] = strdup(mac_type);
crypto->kex_methods[SSH_MAC_S_C] = strdup(mac_type);
crypto->kex_methods[SSH_COMP_C_S] = strdup("none");
crypto->kex_methods[SSH_COMP_S_C] = strdup("none");
crypto->kex_methods[SSH_COMP_C_S] = strdup(comp_type);
crypto->kex_methods[SSH_COMP_S_C] = strdup(comp_type);
crypto->kex_methods[SSH_LANG_C_S] = strdup("none");
crypto->kex_methods[SSH_LANG_S_C] = strdup("none");
rc = crypt_set_algorithms_client(session);
@ -112,7 +114,12 @@ static void torture_packet(const char *cipher,
rc = recv(sockets[1], buffer, sizeof(buffer), 0);
assert_true(rc > 0);
encrypted_packet_len = rc;
assert_in_range(encrypted_packet_len, payload_len + 4, payload_len + (32 * 3));
cmp = strcmp(comp_type, "none");
if (cmp == 0) {
assert_in_range(encrypted_packet_len,
payload_len + 4,
payload_len + (32 * 3));
}
rc = send(sockets[0], buffer, encrypted_packet_len, 0);
assert_int_equal(rc, encrypted_packet_len);
@ -134,7 +141,7 @@ static void torture_packet_aes128_ctr(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes128-ctr","hmac-sha1",i);
torture_packet("aes128-ctr", "hmac-sha1", "none", i);
}
}
@ -143,7 +150,7 @@ static void torture_packet_aes192_ctr(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes192-ctr","hmac-sha1",i);
torture_packet("aes192-ctr", "hmac-sha1", "none", i);
}
}
@ -152,7 +159,7 @@ static void torture_packet_aes256_ctr(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes256-ctr","hmac-sha1",i);
torture_packet("aes256-ctr", "hmac-sha1", "none", i);
}
}
@ -161,7 +168,7 @@ static void torture_packet_aes128_cbc(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes128-cbc","hmac-sha1",i);
torture_packet("aes128-cbc", "hmac-sha1", "none", i);
}
}
@ -170,7 +177,7 @@ static void torture_packet_aes192_cbc(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes192-cbc","hmac-sha1",i);
torture_packet("aes192-cbc", "hmac-sha1", "none", i);
}
}
@ -179,7 +186,7 @@ static void torture_packet_aes256_cbc(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes256-cbc","hmac-sha1",i);
torture_packet("aes256-cbc", "hmac-sha1", "none", i);
}
}
@ -188,7 +195,7 @@ static void torture_packet_3des_cbc(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("3des-cbc","hmac-sha1",i);
torture_packet("3des-cbc", "hmac-sha1", "none", i);
}
}
@ -197,7 +204,7 @@ static void torture_packet_chacha20(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("chacha20-poly1305@openssh.com","none",i);
torture_packet("chacha20-poly1305@openssh.com", "none", "none", i);
}
}
@ -206,7 +213,7 @@ static void torture_packet_aes128_gcm(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes128-gcm@openssh.com","none",i);
torture_packet("aes128-gcm@openssh.com", "none", "none", i);
}
}
@ -215,7 +222,25 @@ static void torture_packet_aes256_gcm(void **state)
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes256-gcm@openssh.com","none",i);
torture_packet("aes256-gcm@openssh.com", "none", "none", i);
}
}
static void torture_packet_compress_zlib(void **state)
{
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes256-ctr", "hmac-sha1", "zlib", i);
}
}
static void torture_packet_compress_zlib_openssh(void **state)
{
int i;
(void)state; /* unused */
for (i=1;i<256;++i){
torture_packet("aes256-ctr", "hmac-sha1", "zlib@openssh.com", i);
}
}
@ -232,6 +257,8 @@ int torture_run_tests(void) {
cmocka_unit_test(torture_packet_chacha20),
cmocka_unit_test(torture_packet_aes128_gcm),
cmocka_unit_test(torture_packet_aes256_gcm),
cmocka_unit_test(torture_packet_compress_zlib),
cmocka_unit_test(torture_packet_compress_zlib_openssh),
};
ssh_init();