X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fprotocol_key.c;h=88695c79909c8d470c64abfb533d22ba3e063cde;hb=30c0381d71d333a99f6c83ff9d03ef4a0857f423;hp=66c9a9093cc4dad40822b0e43571fbf2ecb17fa6;hpb=f75dcef72a81a337e847adf0bae54198894f65b9;p=tinc diff --git a/src/protocol_key.c b/src/protocol_key.c index 66c9a909..88695c79 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -17,14 +17,13 @@ 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.13 2002/09/09 21:24:56 guus Exp $ + $Id: protocol_key.c,v 1.1.4.17 2003/07/06 22:11:32 guus Exp $ */ #include "config.h" #include #include -#include #include #include #include @@ -40,12 +39,13 @@ #include "meta.h" #include "connection.h" #include "node.h" +#include "logger.h" #include "system.h" int mykeyused = 0; -int send_key_changed(connection_t * c, node_t * n) +int send_key_changed(connection_t *c, node_t *n) { cp(); @@ -59,7 +59,7 @@ int send_key_changed(connection_t * c, node_t * n) return send_request(c, "%d %lx %s", KEY_CHANGED, random(), n->name); } -int key_changed_h(connection_t * c) +int key_changed_h(connection_t *c) { char name[MAX_STRING_SIZE]; node_t *n; @@ -67,7 +67,7 @@ int key_changed_h(connection_t * c) cp(); if(sscanf(c->buffer, "%*d %*x " MAX_STRING, name) != 1) { - syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED", + logger(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "KEY_CHANGED", c->name, c->hostname); return -1; } @@ -78,7 +78,7 @@ int key_changed_h(connection_t * c) n = lookup_node(name); if(!n) { - syslog(LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"), + logger(DEBUG_ALWAYS, LOG_ERR, _("Got %s from %s (%s) origin %s which does not exist"), "KEY_CHANGED", c->name, c->hostname, name); return -1; } @@ -93,14 +93,14 @@ int key_changed_h(connection_t * c) return 0; } -int send_req_key(connection_t * c, node_t * from, node_t * to) +int send_req_key(connection_t *c, node_t *from, node_t *to) { cp(); return send_request(c, "%d %s %s", REQ_KEY, from->name, to->name); } -int req_key_h(connection_t * c) +int req_key_h(connection_t *c) { char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; @@ -109,7 +109,7 @@ int req_key_h(connection_t * c) 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(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "REQ_KEY", c->name, c->hostname); return -1; } @@ -117,7 +117,7 @@ int req_key_h(connection_t * c) 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(DEBUG_ALWAYS, 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; } @@ -125,7 +125,7 @@ int req_key_h(connection_t * c) 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(DEBUG_ALWAYS, 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; } @@ -135,6 +135,7 @@ int req_key_h(connection_t * c) 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); @@ -143,7 +144,7 @@ int req_key_h(connection_t * c) return 0; } -int send_ans_key(connection_t * c, node_t * from, node_t * to) +int send_ans_key(connection_t *c, node_t *from, node_t *to) { char key[MAX_STRING_SIZE]; @@ -159,7 +160,7 @@ int send_ans_key(connection_t * c, node_t * from, node_t * to) from->compression); } -int ans_key_h(connection_t * c) +int ans_key_h(connection_t *c) { char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; @@ -172,7 +173,7 @@ int ans_key_h(connection_t * c) 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(DEBUG_ALWAYS, LOG_ERR, _("Got bad %s from %s (%s)"), "ANS_KEY", c->name, c->hostname); return -1; } @@ -180,7 +181,7 @@ int ans_key_h(connection_t * c) 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(DEBUG_ALWAYS, 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; } @@ -188,7 +189,7 @@ int ans_key_h(connection_t * c) 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(DEBUG_ALWAYS, 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; } @@ -219,13 +220,13 @@ int ans_key_h(connection_t * c) from->cipher = EVP_get_cipherbynid(cipher); if(!from->cipher) { - syslog(LOG_ERR, _("Node %s (%s) uses unknown cipher!"), from->name, + logger(DEBUG_ALWAYS, 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(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses wrong keylength!"), from->name, from->hostname); return -1; } @@ -239,13 +240,13 @@ int ans_key_h(connection_t * c) from->digest = EVP_get_digestbynid(digest); if(!from->digest) { - syslog(LOG_ERR, _("Node %s (%s) uses unknown digest!"), from->name, + logger(DEBUG_ALWAYS, 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(DEBUG_ALWAYS, LOG_ERR, _("Node %s (%s) uses bogus MAC length!"), from->name, from->hostname); return -1; } @@ -253,8 +254,15 @@ int ans_key_h(connection_t * c) from->digest = NULL; } + if(compression < 0 || compression > 11) { + logger(DEBUG_ALWAYS, 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;