Second round of fixes
This commit is contained in:
parent
ed397b6ac6
commit
7f3ab38c22
5 changed files with 75 additions and 32 deletions
14
src/encr.c
14
src/encr.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: encr.c,v 1.12.4.4 2000/08/18 11:17:09 guus Exp $
|
$Id: encr.c,v 1.12.4.5 2000/09/15 12:58:38 zarq Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -337,12 +337,12 @@ cp
|
||||||
/* We haven't received a key from this host (yet). */
|
/* We haven't received a key from this host (yet). */
|
||||||
continue;
|
continue;
|
||||||
ek = make_shared_key(p->public_key->key);
|
ek = make_shared_key(p->public_key->key);
|
||||||
free_key(p->key);
|
free_key(p->datakey);
|
||||||
p->key = xmalloc(sizeof(*p->key));
|
p->datakey = xmalloc(sizeof(*p->datakey));
|
||||||
p->key->length = strlen(ek);
|
p->datakey->length = strlen(ek);
|
||||||
p->key->expiry = p->public_key->expiry;
|
p->datakey->expiry = p->public_key->expiry;
|
||||||
p->key->key = xmalloc(strlen(ek) + 1);
|
p->datakey->key = xmalloc(strlen(ek) + 1);
|
||||||
strcpy(p->key->key, ek);
|
strcpy(p->datakey->key, ek);
|
||||||
}
|
}
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
20
src/net.c
20
src/net.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: net.c,v 1.35.4.29 2000/09/14 21:51:19 zarq Exp $
|
$Id: net.c,v 1.35.4.30 2000/09/15 12:58:39 zarq Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -93,11 +93,25 @@ cp
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int str2opt(const char *str) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = 0;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *opt2str(int opt) {
|
||||||
|
static char s[50];
|
||||||
|
|
||||||
|
snprintf(s, 49, "%d", opt);
|
||||||
|
return &s;
|
||||||
|
}
|
||||||
|
|
||||||
int xsend(conn_list_t *cl, void *packet)
|
int xsend(conn_list_t *cl, void *packet)
|
||||||
{
|
{
|
||||||
real_packet_t rp;
|
real_packet_t rp;
|
||||||
cp
|
cp
|
||||||
do_encrypt((vpn_packet_t*)packet, &rp, cl->key);
|
do_encrypt((vpn_packet_t*)packet, &rp, cl->datakey);
|
||||||
rp.from = htonl(myself->vpn_ip);
|
rp.from = htonl(myself->vpn_ip);
|
||||||
rp.data.len = htons(rp.data.len);
|
rp.data.len = htons(rp.data.len);
|
||||||
rp.len = htons(rp.len);
|
rp.len = htons(rp.len);
|
||||||
|
@ -128,7 +142,7 @@ int xrecv(conn_list_t *cl, void *packet)
|
||||||
vpn_packet_t vp;
|
vpn_packet_t vp;
|
||||||
int lenin;
|
int lenin;
|
||||||
cp
|
cp
|
||||||
do_decrypt((real_packet_t*)packet, &vp, cl->key);
|
do_decrypt((real_packet_t*)packet, &vp, cl->datakey);
|
||||||
add_mac_addresses(&vp);
|
add_mac_addresses(&vp);
|
||||||
|
|
||||||
if(debug_lvl > 3)
|
if(debug_lvl > 3)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: net.h,v 1.9.4.11 2000/09/14 21:51:20 zarq Exp $
|
$Id: net.h,v 1.9.4.12 2000/09/15 12:58:40 zarq Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_NET_H__
|
#ifndef __TINC_NET_H__
|
||||||
|
@ -133,13 +133,13 @@ typedef struct conn_list_t {
|
||||||
int meta_socket; /* our tcp meta socket */
|
int meta_socket; /* our tcp meta socket */
|
||||||
int protocol_version; /* used protocol */
|
int protocol_version; /* used protocol */
|
||||||
status_bits_t status; /* status info */
|
status_bits_t status; /* status info */
|
||||||
option_bits_t options; /* options turned on for this connection */
|
int options; /* options turned on for this connection */
|
||||||
passphrase_t *pp; /* encoded passphrase */
|
passphrase_t *pp; /* encoded passphrase */
|
||||||
packet_queue_t *sq; /* pending outgoing packets */
|
packet_queue_t *sq; /* pending outgoing packets */
|
||||||
packet_queue_t *rq; /* pending incoming packets (they have no
|
packet_queue_t *rq; /* pending incoming packets (they have no
|
||||||
valid key to be decrypted with) */
|
valid key to be decrypted with) */
|
||||||
enc_key_t *public_key; /* the other party's public key */
|
enc_key_t *public_key; /* the other party's public key */
|
||||||
enc_key_t *key; /* encrypt with this key */
|
enc_key_t *datakey; /* encrypt data packets with this key */
|
||||||
char *buffer; /* metadata input buffer */
|
char *buffer; /* metadata input buffer */
|
||||||
int buflen; /* bytes read into buffer */
|
int buflen; /* bytes read into buffer */
|
||||||
int reqlen; /* length of first request in buffer */
|
int reqlen; /* length of first request in buffer */
|
||||||
|
@ -164,7 +164,10 @@ extern conn_list_t *conn_list;
|
||||||
extern conn_list_t *myself;
|
extern conn_list_t *myself;
|
||||||
|
|
||||||
extern char *request_name[256];
|
extern char *request_name[256];
|
||||||
|
extern char *status_text[10];
|
||||||
|
|
||||||
|
extern int str2opt(const char *);
|
||||||
|
extern char *opt2str(int);
|
||||||
extern int send_packet(ip_t, vpn_packet_t *);
|
extern int send_packet(ip_t, vpn_packet_t *);
|
||||||
extern int setup_network_connections(void);
|
extern int setup_network_connections(void);
|
||||||
extern void close_network_connections(void);
|
extern void close_network_connections(void);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: netutl.c,v 1.12.4.9 2000/09/14 21:51:20 zarq Exp $
|
$Id: netutl.c,v 1.12.4.10 2000/09/15 12:58:40 zarq Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -95,7 +95,7 @@ cp
|
||||||
if(p->hostname)
|
if(p->hostname)
|
||||||
free(p->hostname);
|
free(p->hostname);
|
||||||
free_key(p->public_key);
|
free_key(p->public_key);
|
||||||
free_key(p->key);
|
free_key(p->datakey);
|
||||||
free(p);
|
free(p);
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: protocol.c,v 1.28.4.31 2000/09/14 21:51:21 zarq Exp $
|
$Id: protocol.c,v 1.28.4.32 2000/09/15 12:58:40 zarq Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -46,6 +46,21 @@
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
|
int check_id(char *id)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < strlen(id); i++)
|
||||||
|
{
|
||||||
|
if(!isalpha(id[i]) && id[i] != '_')
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Generic outgoing request routine - takes care of logging and error detection as well */
|
/* Generic outgoing request routine - takes care of logging and error detection as well */
|
||||||
|
|
||||||
int send_request(conn_list_t *cl, const char *format, int request, /*args*/ ...)
|
int send_request(conn_list_t *cl, const char *format, int request, /*args*/ ...)
|
||||||
|
@ -596,7 +611,8 @@ int status_h(conn_list_t *cl)
|
||||||
cp
|
cp
|
||||||
if(sscanf(cl->buffer, "%*d %d %as", &statusno, &statusstring) != 2)
|
if(sscanf(cl->buffer, "%*d %d %as", &statusno, &statusstring) != 2)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got bad STATUS from %s (%s)"), cl->id, cl->hostname);
|
syslog(LOG_ERR, _("Got bad STATUS from %s (%s)"),
|
||||||
|
cl->name, cl->hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,7 +631,7 @@ int send_error(conn_list_t *cl, int errno, char *errstring)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
if(!errstring)
|
if(!errstring)
|
||||||
errstring = error_text[errno];
|
errstring = strerror(errno);
|
||||||
return send_request(cl, "%d %d %s", ERROR, errno, errstring);
|
return send_request(cl, "%d %d %s", ERROR, errno, errstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,7 +650,7 @@ cp
|
||||||
if(debug_lvl > DEBUG_error)
|
if(debug_lvl > DEBUG_error)
|
||||||
{
|
{
|
||||||
syslog(LOG_NOTICE, _("Error message from %s (%s): %s: %s"),
|
syslog(LOG_NOTICE, _("Error message from %s (%s): %s: %s"),
|
||||||
cl->name, cl->hostname, error_text[errno], errorstring);
|
cl->name, cl->hostname, strerror(errno), errorstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(errorstring);
|
free(errorstring);
|
||||||
|
@ -718,7 +734,8 @@ cp
|
||||||
|
|
||||||
if(!(from = lookup_id(from_id)))
|
if(!(from = lookup_id(from_id)))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got KEY_CHANGED from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
|
syslog(LOG_ERR, _("Got KEY_CHANGED from %s (%s) origin %s which does not exist in our connection list"),
|
||||||
|
cl->name, cl->hostname, from_id);
|
||||||
free(from_id);
|
free(from_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -736,7 +753,8 @@ cp
|
||||||
int send_req_key(conn_list_t *from, conn_list_t *to)
|
int send_req_key(conn_list_t *from, conn_list_t *to)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
return send_request(to->nexthop, "%d %s %s", REQ_KEY, from->id, to->id);
|
return send_request(to->nexthop, "%d %s %s", REQ_KEY,
|
||||||
|
from->name, to->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int req_key_h(conn_list_t *cl)
|
int req_key_h(conn_list_t *cl)
|
||||||
|
@ -746,28 +764,31 @@ int req_key_h(conn_list_t *cl)
|
||||||
cp
|
cp
|
||||||
if(sscanf(cl->buffer, "%*d %as %as", &from_id, &to_id) != 2)
|
if(sscanf(cl->buffer, "%*d %as %as", &from_id, &to_id) != 2)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got bad REQ_KEY from %s (%s)"), cl->id, cl->hostname);
|
syslog(LOG_ERR, _("Got bad REQ_KEY from %s (%s)"),
|
||||||
|
cl->name, cl->hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(from = lookup_id(from_id)))
|
if(!(from = lookup_id(from_id)))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
|
syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) origin %s which does not exist in our connection list"),
|
||||||
|
cl->name, cl->hostname, from_id);
|
||||||
free(from_id); free(to_id);
|
free(from_id); free(to_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if this key request is for us */
|
/* Check if this key request is for us */
|
||||||
|
|
||||||
if(!strcmp(id, myself->strcmp))
|
if(!strcmp(to_id, myself->name))
|
||||||
{
|
{
|
||||||
send_ans_key(myself, from, myself->datakey);
|
send_ans_key(myself, from, myself->datakey->key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!(to = lookup_id(to_id)))
|
if(!(to = lookup_id(to_id)))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) destination %s which does not exist in our connection list"), cl->id, cl->hostname, to_id);
|
syslog(LOG_ERR, _("Got REQ_KEY from %s (%s) destination %s which does not exist in our connection list"),
|
||||||
|
cl->name, cl->hostname, to_id);
|
||||||
free(from_id); free(to_id);
|
free(from_id); free(to_id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -782,7 +803,8 @@ cp
|
||||||
int send_ans_key(conn_list_t *from, conn_list_t *to, char *datakey)
|
int send_ans_key(conn_list_t *from, conn_list_t *to, char *datakey)
|
||||||
{
|
{
|
||||||
cp
|
cp
|
||||||
return send_request(to->nexthop, "%d %s %s %s", ANS_KEY, from->id, to->id, datakey);
|
return send_request(to->nexthop, "%d %s %s %s", ANS_KEY,
|
||||||
|
from->name, to->name, datakey);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ans_key_h(conn_list_t *cl)
|
int ans_key_h(conn_list_t *cl)
|
||||||
|
@ -793,20 +815,22 @@ int ans_key_h(conn_list_t *cl)
|
||||||
cp
|
cp
|
||||||
if(sscanf(cl->buffer, "%*d %as %as %as", &from_id, &to_id, &datakey) != 3)
|
if(sscanf(cl->buffer, "%*d %as %as %as", &from_id, &to_id, &datakey) != 3)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s)"), cl->id, cl->hostname);
|
syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s)"),
|
||||||
|
cl->name, cl->hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(from = lookup_id(from_id)))
|
if(!(from = lookup_id(from_id)))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) origin %s which does not exist in our connection list"), cl->id, cl->hostname, from_id);
|
syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) origin %s which does not exist in our connection list"),
|
||||||
|
cl->name, cl->hostname, from_id);
|
||||||
free(from_id); free(to_id); free(datakey);
|
free(from_id); free(to_id); free(datakey);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if this key request is for us */
|
/* Check if this key request is for us */
|
||||||
|
|
||||||
if(!strcmp(id, myself->strcmp))
|
if(!strcmp(to_id, myself->name))
|
||||||
{
|
{
|
||||||
/* It is for us, convert it to binary and set the key with it. */
|
/* It is for us, convert it to binary and set the key with it. */
|
||||||
|
|
||||||
|
@ -814,7 +838,8 @@ cp
|
||||||
|
|
||||||
if((keylength%2) || (keylength <= 0))
|
if((keylength%2) || (keylength <= 0))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s) origin %s: invalid key"), cl->id, cl->hostname, from->id);
|
syslog(LOG_ERR, _("Got bad ANS_KEY from %s (%s) origin %s: invalid key"),
|
||||||
|
cl->name, cl->hostname, from->name);
|
||||||
free(from_id); free(to_id); free(datakey);
|
free(from_id); free(to_id); free(datakey);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -826,7 +851,8 @@ cp
|
||||||
{
|
{
|
||||||
if(!(to = lookup_id(to_id)))
|
if(!(to = lookup_id(to_id)))
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) destination %s which does not exist in our connection list"), cl->id, cl->hostname, to_id);
|
syslog(LOG_ERR, _("Got ANS_KEY from %s (%s) destination %s which does not exist in our connection list"),
|
||||||
|
cl->name, cl->hostname, to_id);
|
||||||
free(from_id); free(to_id); free(datakey);
|
free(from_id); free(to_id); free(datakey);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue