Commit 79fce608 authored by Niels Möller's avatar Niels Möller

Initialize key exchange.

Rev: src/lsh.c:1.9
Rev: src/lshd.c:1.8
parent c40012cb
......@@ -30,11 +30,15 @@
#include "getopt.h"
#include "io.h"
#include "werror.h"
#include "alist.h"
#include "atoms.h"
#include "client.h"
#include "format.h"
#include "client_keyexchange.h"
#include "crypto.h"
#include "format.h"
#include "io.h"
#include "randomness.h"
#include "werror.h"
#include "xalloc.h"
#define BLOCK_SIZE 32768
......@@ -49,16 +53,48 @@ void usage()
exit(1);
}
struct fake_host_db
{
struct lookup_verifier super;
struct signature_algorithm *algorithm;
};
static struct verifier *do_host_lookup(struct lookup_verifier *c,
struct lsh_string *key)
{
struct fake_host_db *closure = (struct fake_host_db *) c;
return MAKE_VERIFIER(closure->algorithm, key->length, key->data);
}
static struct lookup_verifier *make_fake_host_db(struct signature_algorithm *a)
{
struct fake_host_db *res = xalloc(sizeof(struct fake_host_db));
res->super.lookup = do_host_lookup;
res->algorithm = a;
return &res->super;
}
int main(int argc, char **argv)
{
char *host = NULL;
char *port = "ssh";
int option;
struct lsh_string *random_seed;
struct sockaddr_in remote;
struct lsh_string *random_seed;
struct randomness *r;
struct diffie_hellman_method *dh;
struct keyexchange_algorithm *kex;
struct alist *algorithms;
struct make_kexinit *make_kexinit;
struct packet_handler *kexinit_handler;
struct lookup_verifier *lookup;
/* For filtering messages. Could perhaps also be used when converting
* strings to and from UTF8. */
setlocale(LC_CTYPE, "");
......@@ -87,20 +123,33 @@ int main(int argc, char **argv)
host = argv[optind];
random_seed = ssh_format("%z", "gazonk");
r = make_poor_random(&sha_algorithm, random_seed);
dh = make_dh1(r);
/* No randomness is needed for verifying signatures */
lookup = make_fake_host_db(make_dss_algorithm(NULL));
kex = make_dh_client(dh, lookup);
algorithms = make_alist(4,
ATOM_ARCFOUR, crypto_rc4_algorithm,
ATOM_HMAC_SHA1, make_hmac_algorithm(&sha_algorithm),
ATOM_DIFFIE_HELLMAN_GROUP1_SHA1, kex,
ATOM_SSH_DSS, make_dss_algorithm(r), -1);
make_kexinit = make_test_kexinit(r);
kexinit_handler = make_kexinit_handler(CONNECTION_CLIENT,
make_kexinit, algorithms);
if (!get_inaddr(&remote, host, port, "tcp"))
{
fprintf(stderr, "No such host or service\n");
exit(1);
}
random_seed = ssh_format("%z", "gazonk");
if (!io_connect(&backend, &remote, NULL,
make_client_callback(&backend,
"lsh - a free ssh",
BLOCK_SIZE,
make_poor_random(&sha_algorithm,
random_seed))))
r, make_kexinit,
kexinit_handler)))
{
werror("lsh: Connection failed: %s\n", strerror(errno));
return 1;
......
......@@ -116,47 +116,6 @@ static void init_host_key(struct randomness *r)
mpz_clear(a);
}
struct simple_kexinit
{
struct make_kexinit super;
struct randomness *r;
};
static struct kexinit *do_make_kexinit(struct make_kexinit *c)
{
struct simple_kexinit *closure = (struct simple_kexinit *) c;
struct kexinit *res = xalloc(sizeof(struct kexinit));
static int kex_algorithms[] = { ATOM_DIFFIE_HELLMAN_GROUP1_SHA1, 0 };
static int server_hostkey_algorithms[] = { ATOM_SSH_DSS, 0 };
static int crypto_algorithms[] = { ATOM_ARCFOUR, ATOM_NONE, 0 };
static int mac_algorithms[] = { ATOM_HMAC_SHA1, 0 };
static int compression_algorithms[] = { ATOM_NONE, 0 };
RANDOM(closure->r, 16, res->cookie);
res->kex_algorithms = kex_algorithms;
res->server_hostkey_algorithms = server_hostkey_algorithms;
res->parameters[KEX_ENCRYPTION_CLIENT_TO_SERVER] = crypto_algorithms;
res->parameters[KEX_ENCRYPTION_SERVER_TO_CLIENT] = crypto_algorithms;
res->parameters[KEX_MAC_CLIENT_TO_SERVER] = mac_algorithms;
res->parameters[KEX_MAC_SERVER_TO_CLIENT] = mac_algorithms;
res->parameters[KEX_COMPRESSION_CLIENT_TO_SERVER] = compression_algorithms;
res->parameters[KEX_COMPRESSION_SERVER_TO_CLIENT] = compression_algorithms;
res->first_kex_packet_follows = 0;
return res;
}
struct make_kexinit *make_simple_kexinit(struct randomness *r)
{
struct simple_kexinit *res = xalloc(sizeof(struct simple_kexinit));
res->super.make = do_make_kexinit;
res->r = r;
return &res->super;
}
int main(int argc, char **argv)
{
char *host = NULL; /* Interface to bind */
......@@ -165,10 +124,12 @@ int main(int argc, char **argv)
struct sockaddr_in local;
struct lsh_string *random_seed;
struct randomness *r;
struct diffie_hellman_method *dh;
struct keyexchange_algorithm *kex;
struct alist *algorithms;
struct make_kexinit *make_kexinit;
struct packet_handler *kexinit_handler;
/* For filtering messages. Could perhaps also be used when converting
......@@ -200,7 +161,9 @@ int main(int argc, char **argv)
if ( (argc - optind) != 0)
usage();
r = make_poor_random(&sha_algorithm, ssh_format("%z", "gazonk"));
random_seed = ssh_format("%z", "foobar");
r = make_poor_random(&sha_algorithm, random_seed);
dh = make_dh1(r);
init_host_key(r); /* Initializes public_key and secret_key */
kex = make_dh_server(dh, public_key, secret_key);
......@@ -209,7 +172,9 @@ int main(int argc, char **argv)
ATOM_HMAC_SHA1, make_hmac_algorithm(&sha_algorithm),
ATOM_DIFFIE_HELLMAN_GROUP1_SHA1, kex,
ATOM_SSH_DSS, make_dss_algorithm(r), -1);
kexinit_handler = make_kexinit_handler(make_simple_kexinit(r), algorithms);
make_kexinit = make_test_kexinit(r);
kexinit_handler = make_kexinit_handler(CONNECTION_SERVER,
make_kexinit, algorithms);
if (!get_inaddr(&local, host, port, "tcp"))
{
......@@ -221,6 +186,7 @@ int main(int argc, char **argv)
make_server_callback(&backend,
"lsh - a free ssh",
BLOCK_SIZE,
r, make_kexinit,
kexinit_handler)))
{
werror("lsh: Connection failed: %s\n", strerror(errno));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment