service
automech.[ch]
udptunnel-forwarder
+blowfishtest
-# Copyright (C) 1999 Ian Jackson
+# Makefile for ipif/udptunnel stuff
+
+# Copyright (C) 1999-2000 Ian Jackson
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
etcuserv= $(etcdir)/userv
services= $(etcuserv)/services.d
-TARGETS= service udptunnel-forwarder blowfishtest
+PROGRAMS= udptunnel udptunnel-forwarder
+TARGETS= service blowfishtest $(PROGRAMS)
MECHFILES= null pkcs5 timestamp sequence blowfish
MECHOBJS= $(foreach m, $(MECHFILES), mech-$m.o)
mkdir -p $(libuserv) $(services)
cp -b service $(libuserv)/ipif
cp ipif $(services)/ipif:new
- cp -b udptunnel $(bindir)/.
+ cp -b $(PROGRAMS) $(bindir)/.
set -e; cd $(services); test -f ipif || mv ipif:new ipif
udptunnel-forwarder: $(OBJS_FORWARD)
#!/bin/sh
+# generates automech.h and automech.c
+
+# Copyright (C) 2000 Ian Jackson
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with userv-utils; if not, write to the Free Software
+# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
exec >automech.c.new
exec 3>automech.h.new
* Algorithm by Bruce Schneier 1995
* This implementation adapted from a public domain version by Bruce
* Schneier (1995) by Ian Jackson in 1997.
- * Copyright (C)1997 Ian Jackson.
+ */
+/*
+ * Copyright (C) 1997,2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* TODO: test with zero length key */
-/**/
+/*
+ * Copyright (C) 1997,2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#ifndef BLOWFISH__H_INCLUDED
#define BLOWFISH__H_INCLUDED
-/**/
+/*
+ * Copyright (C) 1997,2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include <stdio.h>
#include <assert.h>
-/**/
+/*
+ * test program for blowfish; very hard to use (sorry!)
+ */
+/*
+ * Copyright (C) 1997,2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
#include <stdio.h>
#include <string.h>
/*
* Encrypting tunnel for userv-ipif tunnels, actual implementation
- *
+ */
+/*
* usage:
* udptunnel-forwarder <optchars>
* <public-local-fd> <private-in-fd> <private-out-fd>
* 12 usage error
* 16 bad trouble
*/
+/*
+ * Copyright (C) 2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include <sys/socket.h>
#include <netinet/in.h>
for (i=n_mechs-1; i>=0; i--) {
emsg= mechs[i]->decode(md_in[i],&buf_in);
if (emsg) {
- fprintf(stderr, "%s: bad packet: %s: %s\n", programid, mechs[i]->name, emsg);
+ if (*emsg)
+ fprintf(stderr, "%s: bad packet: %s: %s\n",
+ programid, mechs[i]->name, emsg);
return;
}
cdebugbuf(i, "decode", &buf_in, 3,0);
/*
+ * Encrypting tunnel for userv-ipif tunnels, header file
+ */
+/*
+ * Copyright (C) 2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef MECHS_H
*
* setup_in function may increase maxprefix and maxsuffix
* code functions modify buffer in place
- * decode function returns message to print
+ * decode function returns 0 meaning packet decoded ok,
+ * "" meaning discard it quietly, or message to print for verbose discard
*/
const char *getarg_string(void);
-/**/
+/*
+ * Copyright (C) 1997,2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include <stdio.h>
#include <stdlib.h>
-/**/
+/*
+ * Copyright (C) 1997,2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#ifndef HEX__H_INCLUDED
#define HEX__H_INCLUDED
/*
- * Blowfish
+ * Blowfish mechanism for udp tunnel
*
* arguments: key size in bits (must be multiple of 8)
*
* encoding: do CBC encryption overwriting message
* encoding for MAC: do CBC and prepend last ciphertext block
*/
+/*
+ * Copyright (C) 2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include "forwarder.h"
#include "blowfish.h"
/*
+ * Null mechanism for udp tunnel (for testing purposes only)
+ */
+/*
+ * Copyright (C) 2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "forwarder.h"
/*
- * PKCS#5 padding
+ * PKCS#5 padding mechanism for udp tunnel
*
* arguments: block size to pad to, must be power of 2
*
* encoding: append between 1 and n bytes, all of the same value being
* the number of bytes appended
*/
+/*
+ * Copyright (C) 2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include "forwarder.h"
/*
- * Sequence number / nonce mechanism
+ * Sequence number / nonce mechanism for udp tunnel
*
* arguments: none
*
* encoding: prepend 4 bytes of sequence arithmetic serial number
* decoding: check increasingness, or ignore
*/
+/*
+ * Copyright (C) 2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include <netinet/in.h>
/*
- * Timestamp mechanism
+ * Timestamp mechanism for udp tunnel
*
* arguments: <max-skew> <max-age>
*
* accept a packet (or 0 for any future age).
*
*/
+/*
+ * Copyright (C) 2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include <stdint.h>
#include <netinet/in.h>
#include "forwarder.h"
+#define WARN_EVERY 30
+
struct mechdata {
time_t max_skew, max_age;
+ time_t next_warn;
};
static void mds_timestamp(struct mechdata **md_r) {
md->max_skew= getarg_ulong();
md->max_age= getarg_ulong();
+ md->next_warn= now();
*md_r= md;
}
static const char *mdec_timestamp(struct mechdata *md, struct buffer *buf) {
static char cbuf[40];
- uint32_t *tp, timestamp, tnow;
+ uint32_t *tp, timestamp;
+ time_t tnow;
long age;
BUF_UNPREPEND(tp,buf,4);
timestamp= ntohl(*tp);
tnow= now();
- age= timestamp - tnow;
+ age= timestamp - (uint32_t)tnow;
if (age > 0) {
- if (md->max_age && age > md->max_age) {
- sprintf(cbuf,"packet too old (%lds)",age);
- return cbuf;
- }
+ if (!md->max_age || age <= md->max_age) return 0;
+ sprintf(cbuf,"packet too old (%lds)",age);
} else if (age < 0) {
- if (md->max_skew && age < -md->max_skew) {
- sprintf(cbuf,"too much skew (%lds)",-age);
- return cbuf;
- }
+ if (!md->max_skew || age >= -md->max_skew) return 0;
+ sprintf(cbuf,"too much skew (%lds)",-age);
}
- return 0;
+ if (tnow < md->next_warn) return "";
+
+ md->next_warn= tnow+WARN_EVERY;
+ return cbuf;
}
STANDARD_MECHANISMLIST("timestamp",timestamp);
/*
+ * General utility functions for udp tunnel
+ */
+/*
+ * Copyright (C) 2000 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <string.h>