methods now tests all methods separately, and reports which one goes wrong

Corrected Makefile dependency
This commit is contained in:
Bert Vermeulen 2005-01-25 05:46:00 +00:00
parent 064c6cde3a
commit b25446d0a5
2 changed files with 62 additions and 71 deletions

View File

@ -9,11 +9,11 @@ libssh2-test: $(OBJS)
$(CC) -o libssh2-test $(OBJS) $(LIBS) $(CC) -o libssh2-test $(OBJS) $(LIBS)
main.o: main.c libssh2.h main.o: main.c libssh2-test.h
util.o: util.c libssh2.h util.o: util.c libssh2-test.h
methods.o: methods.c libssh2.h methods.o: methods.c libssh2-test.h
auth.o: auth.c libssh2.h auth.o: auth.c libssh2-test.h
forward.o: forward.c libssh2.h forward.o: forward.c libssh2-test.h
clean: clean:
rm -f $(OBJS) libssh2-test rm -f $(OBJS) libssh2-test

View File

@ -1,5 +1,6 @@
/* /*
* methods.c -- test all available key exchange, hostkey, encryption, mac and compression methods * methods.c -- test all available key exchange, hostkey, encryption, mac
* and compression methods
* *
* Copyright (C) 2005 Bert Vermeulen <bert@biot.com> * Copyright (C) 2005 Bert Vermeulen <bert@biot.com>
* All rights reserved. * All rights reserved.
@ -61,13 +62,13 @@ static char *hostkey_methods[] = {
}; };
static char *crypt_methods[] = { static char *crypt_methods[] = {
"3des-cbc",
"aes256-cbc", "aes256-cbc",
"aes192-cbc", "aes192-cbc",
"aes128-cbc", "aes128-cbc",
"blowfish-cbc", "blowfish-cbc",
"arcfour", "arcfour",
"cast128-cbc", "cast128-cbc",
"3des-cbc",
NULL NULL
}; };
@ -81,6 +82,7 @@ static char *mac_methods[] = {
}; };
static char *compression_methods[] = { static char *compression_methods[] = {
"none",
"zlib", "zlib",
NULL NULL
}; };
@ -119,77 +121,68 @@ static void dump_methods(LIBSSH2_SESSION *session)
static void cycle_methods(void) static void cycle_methods(void)
{ {
LIBSSH2_SESSION *session; LIBSSH2_SESSION *session;
int sock, size, methods_done, i, res; int sock, size, res, method_type, method, i;
struct methodlist *method; char *errmsg;
char methodstring[256], *errmsg;
while(1) method_type = 0;
method = 0;
while(methods[method_type].description)
{ {
increase_progress(); while(methods[method_type].list[method])
sock = new_socket();
if(sock == -1)
{ {
log_line(ERROR, "new_socket() failed"); increase_progress();
return; sock = new_socket();
} if(sock == -1)
session = libssh2_session_init();
i = 0;
methodstring[0] = '\0';
while(methods[i].description)
{
method = &methods[i];
strncat(methodstring, method->list[method->cursor], 256);
strncat(methodstring, " ", 256);
res = libssh2_session_method_pref(session, method->method_type, method->list[method->cursor]);
if(res != 0)
{ {
libssh2_session_last_error(session, &errmsg, &size, 0); log_line(ERROR, "new_socket() failed");
log_line(ERROR, "%s method set to '%s' failed: %s\n",
method->description, method->list[method->cursor], errmsg);
return; return;
} }
i++; session = libssh2_session_init();
}
res = libssh2_session_startup(session, sock);
if(res == 0)
{ for(i = 0; methods[i].description; i++)
if(libssh2_userauth_password(session, auth.username, auth.password))
{ {
log_line(ERROR, "Authentication failed\n"); res = libssh2_session_method_pref(session, methods[i].method_type,
methods[i].list[ i == method_type ? method : 0 ]);
if(res != 0)
{
libssh2_session_last_error(session, &errmsg, &size, 0);
log_line(ERROR, "%s method set to '%s' failed: %s\n",
methods[i].description,
methods[i].list[ i == method_type ? method : 0 ], errmsg);
return;
}
i++;
}
res = libssh2_session_startup(session, sock);
if(res == 0)
{
if(libssh2_userauth_password(session, auth.username, auth.password))
{
log_line(ERROR, "Authentication failed\n");
}
else
step_successful();
} }
else else
step_successful();
}
else
{
libssh2_session_last_error(session, &errmsg, &size, 0);
log_line(ERROR, "session startup with methods [ %s] failed: %s\n", methodstring, errmsg);
}
libssh2_session_disconnect(session, "All done.");
libssh2_session_free(session);
close(sock);
/* increment method cursors */
i = 0;
methods_done = 0;
while( (method = &methods[i++]) && method->description )
{
if(!method->list[++method->cursor])
{ {
method->done = 1; libssh2_session_last_error(session, &errmsg, &size, 0);
method->cursor = 0; log_line(ERROR, "session startup for %s method %s failed: %s\n",
methods[method_type].description, methods[method_type].list[method], errmsg);
} }
methods_done += method->done; libssh2_session_disconnect(session, "All done.");
} libssh2_session_free(session);
if(--i == methods_done) close(sock);
break;
method++;
}
method_type++;
method = 1;
} }
printf("\n"); printf("\n");
@ -198,20 +191,18 @@ static void cycle_methods(void)
void runtest_methods(void) void runtest_methods(void)
{ {
struct methodlist *method; int i, j, num_steps;
int i, j, max;
max = 0; num_steps = 0;
for(i = 0; methods[i].description; i++) for(i = 0; methods[i].description; i++)
{ {
method = &methods[i]; for(j = 0; methods[i].list[j]; j++)
for(j = 0; method->list[j]; j++)
; ;
if(j > max) num_steps += j - 1;
max = j;
} }
num_steps++;
init_test("kex/hostkey/crypt/max/compression methods", max); init_test("kex/hostkey/crypt/max/compression methods", num_steps);
cycle_methods(); cycle_methods();