Improve server_set_kex().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@654 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-29 16:59:15 +00:00
parent 78ad279a43
commit fa63c0adee

View File

@@ -269,49 +269,57 @@ void ssh_bind_free(SSH_BIND *ssh_bind){
extern char *supported_methods[]; extern char *supported_methods[];
static int server_set_kex(SSH_SESSION * session) { static int server_set_kex(SSH_SESSION * session) {
KEX *server = &session->server_kex; KEX *server = &session->server_kex;
SSH_OPTIONS *options = session->options; SSH_OPTIONS *options = session->options;
int i, j; int i, j;
char *wanted; char *wanted;
memset(server,0,sizeof(KEX));
// the program might ask for a specific cookie to be sent. useful for server ZERO_STRUCTP(server);
// debugging /*
if (options->wanted_cookie) * The program might ask for a specific cookie to be sent. Useful for server
memcpy(server->cookie, options->wanted_cookie, 16); * debugging
else */
ssh_get_random(server->cookie, 16,0); if (options->wanted_cookie) {
if (session->dsa_key && session->rsa_key) { memcpy(server->cookie, options->wanted_cookie, 16);
if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-dss,ssh-rsa") < 0) { } else {
return -1; ssh_get_random(server->cookie, 16, 0);
} }
} else {
if (session->dsa_key) { if (session->dsa_key != NULL && session->rsa_key != NULL) {
if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-dss") < 0) { if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS,
return -1; "ssh-dss,ssh-rsa") < 0) {
}
} else {
if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-rsa") < 0) {
return -1;
}
}
}
server->methods = malloc(10 * sizeof(char **));
if (server->methods == NULL) {
return -1; return -1;
} }
for (i = 0; i < 10; i++) { } else if (session->dsa_key != NULL) {
if (!(wanted = options->wanted_methods[i])) if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-dss") < 0) {
wanted = supported_methods[i]; return -1;
server->methods[i] = strdup(wanted);
if (server->methods[i] == NULL) {
for (j = i - 1; j <= 0; j--) {
SAFE_FREE(server->methods[j]);
}
SAFE_FREE(server->methods);
return -1;
}
} }
return 0; } else {
if (ssh_options_set_wanted_algos(options, SSH_HOSTKEYS, "ssh-rsa") < 0) {
return -1;
}
}
server->methods = malloc(10 * sizeof(char **));
if (server->methods == NULL) {
return -1;
}
for (i = 0; i < 10; i++) {
if ((wanted = options->wanted_methods[i]) == NULL) {
wanted = supported_methods[i];
}
server->methods[i] = strdup(wanted);
if (server->methods[i] == NULL) {
for (j = i - 1; j <= 0; j--) {
SAFE_FREE(server->methods[j]);
}
SAFE_FREE(server->methods);
return -1;
}
}
return 0;
} }
static int dh_handshake_server(SSH_SESSION *session){ static int dh_handshake_server(SSH_SESSION *session){