/*
protocol_key.c -- handle the meta-protocol, key exchange
- Copyright (C) 1999-2002 Ivo Timmermans <ivo@o2w.nl>,
- 2000-2002 Guus Sliepen <guus@sliepen.eu.org>
+ Copyright (C) 1999-2003 Ivo Timmermans <ivo@o2w.nl>,
+ 2000-2003 Guus Sliepen <guus@sliepen.eu.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol_key.c,v 1.1.4.14 2002/09/09 22:33:03 guus Exp $
+ $Id: protocol_key.c,v 1.1.4.18 2003/07/12 17:41:47 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include "meta.h"
#include "connection.h"
#include "node.h"
+#include "logger.h"
#include "system.h"
cp();
if(sscanf(c->buffer, "%*d %*x " MAX_STRING, name) != 1) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED",
+ logger(LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED",
c->name, c->hostname);
return -1;
}
n = lookup_node(name);
if(!n) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"),
+ logger(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"),
"KEY_CHANGED", c->name, c->hostname, name);
return -1;
}
cp();
if(sscanf(c->buffer, "%*d " MAX_STRING " " MAX_STRING, from_name, to_name) != 2) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY", c->name,
+ logger(LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY", c->name,
c->hostname);
return -1;
}
from = lookup_node(from_name);
if(!from) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
+ logger(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
"REQ_KEY", c->name, c->hostname, from_name);
return -1;
}
to = lookup_node(to_name);
if(!to) {
- syslog(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
+ logger(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
"REQ_KEY", c->name, c->hostname, to_name);
return -1;
}
if(to == myself) { /* Yes, send our own key back */
mykeyused = 1;
from->received_seqno = 0;
+ memset(from->late, 0, sizeof(from->late));
send_ans_key(c, myself, from);
} else {
send_req_key(to->nexthop->connection, from, to);
if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d",
from_name, to_name, key, &cipher, &digest, &maclength,
&compression) != 7) {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY", c->name,
+ logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY", c->name,
c->hostname);
return -1;
}
from = lookup_node(from_name);
if(!from) {
- syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
+ logger(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist in our connection list"),
"ANS_KEY", c->name, c->hostname, from_name);
return -1;
}
to = lookup_node(to_name);
if(!to) {
- syslog(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
+ logger(LOG_ERR, _("Got %s from %s (%s) destination %s which does not exist in our connection list"),
"ANS_KEY", c->name, c->hostname, to_name);
return -1;
}
from->cipher = EVP_get_cipherbynid(cipher);
if(!from->cipher) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name,
+ logger(LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name,
from->hostname);
return -1;
}
if(from->keylength != from->cipher->key_len + from->cipher->iv_len) {
- syslog(LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name,
+ logger(LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name,
from->hostname);
return -1;
}
from->digest = EVP_get_digestbynid(digest);
if(!from->digest) {
- syslog(LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name,
+ logger(LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name,
from->hostname);
return -1;
}
if(from->maclength > from->digest->md_size || from->maclength < 0) {
- syslog(LOG_ERR, _("Node %s (%s) uses bogus MAC length!"),
+ logger(LOG_ERR, _("Node %s (%s) uses bogus MAC length!"),
from->name, from->hostname);
return -1;
}
from->digest = NULL;
}
+ if(compression < 0 || compression > 11) {
+ logger(LOG_ERR, _("Node %s (%s) uses bogus compression level!"), from->name, from->hostname);
+ return -1;
+ }
+
from->compression = compression;
+ EVP_EncryptInit_ex(&from->packet_ctx, from->cipher, NULL, from->key, from->key + from->cipher->key_len);
+
flush_queue(from);
return 0;