version 1.22, 2001/03/05 17:17:20 |
version 1.23, 2001/03/10 17:51:04 |
|
|
#include "key.h" |
#include "key.h" |
#include "log.h" |
#include "log.h" |
#include "mac.h" |
#include "mac.h" |
|
#include "match.h" |
|
|
#define KEX_COOKIE_LEN 16 |
#define KEX_COOKIE_LEN 16 |
|
|
|
|
return digest; |
return digest; |
} |
} |
|
|
#define NKEYS 6 |
|
|
|
#define MAX_PROP 20 |
|
#define SEP "," |
|
|
|
char * |
|
get_match(char *client, char *server) |
|
{ |
|
char *sproposals[MAX_PROP]; |
|
char *c, *s, *p, *ret, *cp, *sp; |
|
int i, j, nproposals; |
|
|
|
c = cp = xstrdup(client); |
|
s = sp = xstrdup(server); |
|
|
|
for ((p = strsep(&sp, SEP)), i=0; p && *p != '\0'; |
|
(p = strsep(&sp, SEP)), i++) { |
|
if (i < MAX_PROP) |
|
sproposals[i] = p; |
|
else |
|
break; |
|
} |
|
nproposals = i; |
|
|
|
for ((p = strsep(&cp, SEP)), i=0; p && *p != '\0'; |
|
(p = strsep(&cp, SEP)), i++) { |
|
for (j = 0; j < nproposals; j++) { |
|
if (strcmp(p, sproposals[j]) == 0) { |
|
ret = xstrdup(p); |
|
xfree(c); |
|
xfree(s); |
|
return ret; |
|
} |
|
} |
|
} |
|
xfree(c); |
|
xfree(s); |
|
return NULL; |
|
} |
|
void |
void |
choose_enc(Enc *enc, char *client, char *server) |
choose_enc(Enc *enc, char *client, char *server) |
{ |
{ |
char *name = get_match(client, server); |
char *name = match_list(client, server, NULL); |
if (name == NULL) |
if (name == NULL) |
fatal("no matching cipher found: client %s server %s", client, server); |
fatal("no matching cipher found: client %s server %s", client, server); |
enc->cipher = cipher_by_name(name); |
enc->cipher = cipher_by_name(name); |
|
|
void |
void |
choose_mac(Mac *mac, char *client, char *server) |
choose_mac(Mac *mac, char *client, char *server) |
{ |
{ |
char *name = get_match(client, server); |
char *name = match_list(client, server, NULL); |
if (name == NULL) |
if (name == NULL) |
fatal("no matching mac found: client %s server %s", client, server); |
fatal("no matching mac found: client %s server %s", client, server); |
if (mac_init(mac, name) < 0) |
if (mac_init(mac, name) < 0) |
|
|
void |
void |
choose_comp(Comp *comp, char *client, char *server) |
choose_comp(Comp *comp, char *client, char *server) |
{ |
{ |
char *name = get_match(client, server); |
char *name = match_list(client, server, NULL); |
if (name == NULL) |
if (name == NULL) |
fatal("no matching comp found: client %s server %s", client, server); |
fatal("no matching comp found: client %s server %s", client, server); |
if (strcmp(name, "zlib") == 0) { |
if (strcmp(name, "zlib") == 0) { |
|
|
void |
void |
choose_kex(Kex *k, char *client, char *server) |
choose_kex(Kex *k, char *client, char *server) |
{ |
{ |
k->name = get_match(client, server); |
k->name = match_list(client, server, NULL); |
if (k->name == NULL) |
if (k->name == NULL) |
fatal("no kex alg"); |
fatal("no kex alg"); |
if (strcmp(k->name, KEX_DH1) == 0) { |
if (strcmp(k->name, KEX_DH1) == 0) { |
|
|
void |
void |
choose_hostkeyalg(Kex *k, char *client, char *server) |
choose_hostkeyalg(Kex *k, char *client, char *server) |
{ |
{ |
char *hostkeyalg = get_match(client, server); |
char *hostkeyalg = match_list(client, server, NULL); |
if (hostkeyalg == NULL) |
if (hostkeyalg == NULL) |
fatal("no hostkey alg"); |
fatal("no hostkey alg"); |
k->hostkey_type = key_type_from_name(hostkeyalg); |
k->hostkey_type = key_type_from_name(hostkeyalg); |
|
|
return k; |
return k; |
} |
} |
|
|
|
#define NKEYS 6 |
int |
int |
kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret) |
kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret) |
{ |
{ |