chiark / gitweb /
secnet.git
4 years ago.gitignore: ignore config.stamp.in too
Ian Jackson [Sat, 19 Oct 2019 22:14:21 +0000 (23:14 +0100)]
.gitignore: ignore config.stamp.in too

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Use topbuilddir (now in common.make)
Ian Jackson [Sat, 19 Oct 2019 22:13:55 +0000 (23:13 +0100)]
stest: Use topbuilddir (now in common.make)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Use common.make and therefore our standard CFLAGS
Ian Jackson [Sat, 19 Oct 2019 22:13:35 +0000 (23:13 +0100)]
stest: Use common.make and therefore our standard CFLAGS

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest/udp-preload: Fix some compiler warnings
Ian Jackson [Sat, 19 Oct 2019 22:13:01 +0000 (23:13 +0100)]
stest/udp-preload: Fix some compiler warnings

These come up with our standard CFLAGS which we are erroneously not
using.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agobuild system: stest: Fix out-of-tree builds
Ian Jackson [Sat, 19 Oct 2019 22:03:40 +0000 (23:03 +0100)]
build system: stest: Fix out-of-tree builds

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agobuild system: test-example: Fix out-of-tree builds
Ian Jackson [Sat, 19 Oct 2019 22:03:19 +0000 (23:03 +0100)]
build system: test-example: Fix out-of-tree builds

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agobuild system: Move srcdir setting out of common.make.in
Ian Jackson [Sat, 19 Oct 2019 22:00:28 +0000 (23:00 +0100)]
build system: Move srcdir setting out of common.make.in

This varies according to the cwd.  So for common.make.in it is always
the top-level.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agobuild system: Process test-example with autoconf
Ian Jackson [Sat, 19 Oct 2019 21:17:37 +0000 (22:17 +0100)]
build system: Process test-example with autoconf

This makes configure make the directory during out-of-tree builds.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Rename from `test'
Ian Jackson [Sat, 19 Oct 2019 21:10:49 +0000 (22:10 +0100)]
stest: Rename from `test'

We want other tests too.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agobuild system: Rename stamp-h to config.stamp
Ian Jackson [Sat, 19 Oct 2019 21:05:40 +0000 (22:05 +0100)]
build system: Rename stamp-h to config.stamp

This makes more sense and gets it out of the way of "st..." tab
completion which we are going to want in a momen.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoipaddrset-test: Fix network with host bits
Ian Jackson [Fri, 18 Oct 2019 18:22:36 +0000 (19:22 +0100)]
ipaddrset-test: Fix network with host bits

2001:23:24:: has 3x16 bits set, ie /48.  This was always wrong.

We need to fix this now because we are going to switch to ipaddress
from ipaddr, which actually checks this.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Add a missing dependency on the sites file
Ian Jackson [Sun, 13 Oct 2019 10:05:33 +0000 (11:05 +0100)]
test: Add a missing dependency on the sites file

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Rerun tests only when deps changed
Ian Jackson [Sat, 12 Oct 2019 23:29:42 +0000 (00:29 +0100)]
test: Rerun tests only when deps changed

By touching the stamp file.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: New t-dyni-kex
Ian Jackson [Sat, 12 Oct 2019 23:25:40 +0000 (00:25 +0100)]
test: New t-dyni-kex

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Beak out proc test-kex
Ian Jackson [Sat, 12 Oct 2019 23:24:00 +0000 (00:24 +0100)]
test: Beak out proc test-kex

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Slurp test-example/sites.conf and paste it in
Ian Jackson [Sat, 12 Oct 2019 23:20:42 +0000 (00:20 +0100)]
test: Slurp test-example/sites.conf and paste it in

This will enable us to edit this common config.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Drop redundant headers
Ian Jackson [Sat, 12 Oct 2019 23:14:31 +0000 (00:14 +0100)]
test: udp-preload: Drop redundant headers

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Fix copyright dates and error message
Ian Jackson [Sat, 12 Oct 2019 23:10:03 +0000 (00:10 +0100)]
test: udp-preload: Fix copyright dates and error message

Also upgrade the licence to GPLv3+ like the rest of secnet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Fix build dependencies so `make check' works in sbuild again
Ian Jackson [Sat, 12 Oct 2019 21:45:11 +0000 (22:45 +0100)]
test: Fix build dependencies so `make check' works in sbuild again

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Disconnect -j for check parallelism
Ian Jackson [Sat, 12 Oct 2019 21:58:03 +0000 (22:58 +0100)]
test: Disconnect -j for check parallelism

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Wire into "make check"
Ian Jackson [Sat, 12 Oct 2019 21:45:11 +0000 (22:45 +0100)]
test: Wire into "make check"

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Use test/d-* instead of test/tmp for everything
Ian Jackson [Sat, 12 Oct 2019 21:40:51 +0000 (22:40 +0100)]
test: Use test/d-* instead of test/tmp for everything

Now it is actually ok to run multiple tests in parallel.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Makefile rune for `check'
Ian Jackson [Sat, 12 Oct 2019 21:34:23 +0000 (22:34 +0100)]
test: Makefile rune for `check'

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Move sockets in a subdirectory
Ian Jackson [Sat, 12 Oct 2019 21:14:04 +0000 (22:14 +0100)]
test: Move sockets in a subdirectory

They need to be not world-accessible and this is the easiest way.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Specify the LD_PRELOAD etc.
Ian Jackson [Sat, 12 Oct 2019 21:12:37 +0000 (22:12 +0100)]
test: Specify the LD_PRELOAD etc.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Split "invoke" up
Ian Jackson [Sat, 12 Oct 2019 21:03:17 +0000 (22:03 +0100)]
test: Split "invoke" up

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Use $(CC) for link, provide clean target
Ian Jackson [Sat, 12 Oct 2019 20:54:25 +0000 (21:54 +0100)]
test: udp-preload: Use $(CC) for link, provide clean target

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Build system
Ian Jackson [Sat, 12 Oct 2019 20:50:34 +0000 (21:50 +0100)]
test: udp-preload: Build system

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoMakefiles: Break some settings out into common.make
Ian Jackson [Sat, 12 Oct 2019 20:46:45 +0000 (21:46 +0100)]
Makefiles: Break some settings out into common.make

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Provide recvfrom
Ian Jackson [Sat, 12 Oct 2019 20:37:31 +0000 (21:37 +0100)]
test: udp-preload: Provide recvfrom

Now we can do a key exchange!

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Fix inet_ntop calling convention
Ian Jackson [Sat, 12 Oct 2019 20:29:37 +0000 (21:29 +0100)]
test: udp-preload: Fix inet_ntop calling convention

inet_ntop has a weird error return protocol.  And our code for calling
it never worked properly because we didn't strip the leading directory
names from the bound socket name.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Proxy udp packets
Ian Jackson [Sat, 12 Oct 2019 19:40:55 +0000 (20:40 +0100)]
test: Proxy udp packets

We must change the config to specify localhost addrs explicitly,
because we don't implement any special logic for IN[6]ADDR_ANY.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Cope with -ve fds
Ian Jackson [Sat, 12 Oct 2019 19:40:06 +0000 (20:40 +0100)]
test: udp-preload: Cope with -ve fds

Eg, Tcl passes -1 to close (!)

 #0  0x00007f62949883ca in close (fd=-1) at udp-preload.c:207
 #1  0x00007f6294719362 in Tcl_FinalizeNotifier () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Run secnet under strace
Ian Jackson [Sat, 12 Oct 2019 12:30:59 +0000 (13:30 +0100)]
test: Run secnet under strace

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Provide sendto
Ian Jackson [Sat, 12 Oct 2019 12:29:54 +0000 (13:29 +0100)]
test: udp-preload: Provide sendto

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Prepare for wrapping fns that don't return int
Ian Jackson [Sat, 12 Oct 2019 12:29:26 +0000 (13:29 +0100)]
test: udp-preload: Prepare for wrapping fns that don't return int

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Introduce sun_prep
Ian Jackson [Sat, 12 Oct 2019 12:23:27 +0000 (13:23 +0100)]
test: udp-preload: Introduce sun_prep

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Consolidate program name in argl
Ian Jackson [Sat, 12 Oct 2019 12:22:45 +0000 (13:22 +0100)]
test: Consolidate program name in argl

This avoids pratting about with the weird way execl takes its
arguments.  No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Provide close
Ian Jackson [Sat, 12 Oct 2019 12:09:37 +0000 (13:09 +0100)]
test: udp-preload: Provide close

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Provide getsockname
Ian Jackson [Sat, 12 Oct 2019 12:07:09 +0000 (13:07 +0100)]
test: udp-preload: Provide getsockname

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Provide setsockopt
Ian Jackson [Sat, 12 Oct 2019 11:42:47 +0000 (12:42 +0100)]
test: udp-preload: Provide setsockopt

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoiaddr_to_string: Do not falsely claim bad addrs are scoped IPv6
Ian Jackson [Sat, 12 Oct 2019 11:41:37 +0000 (12:41 +0100)]
iaddr_to_string: Do not falsely claim bad addrs are scoped IPv6

In particular, if the AF is neither INET nor INET6, adns_addr2text
quite rightly fails with EAFNOSUPPORT.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Remove now-obsolete `bound'
Ian Jackson [Sat, 12 Oct 2019 11:32:58 +0000 (12:32 +0100)]
test: udp-preload: Remove now-obsolete `bound'

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Fix binding, unlink
Ian Jackson [Sat, 12 Oct 2019 11:31:14 +0000 (12:31 +0100)]
test: udp-preload: Fix binding, unlink

Avoids EADDRINUSE from the real bind(2).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Fix binding
Ian Jackson [Sat, 12 Oct 2019 11:29:38 +0000 (12:29 +0100)]
test: udp-preload: Fix binding

inet_ntop needs just the addr field.  How "convenient".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: More actual implementation
Ian Jackson [Sat, 12 Oct 2019 11:12:45 +0000 (12:12 +0100)]
test: udp-preload: More actual implementation

Now needs to be invoked like this

  UDP_PRELOAD_DIR=test/tmp LD_PRELOAD=test/udp-preload.so test/invoke

It binds to test/tmp/...

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Beginning of actual implementation
Ian Jackson [Fri, 11 Oct 2019 23:57:27 +0000 (00:57 +0100)]
test: udp-preload: Beginning of actual implementation

  gcc -Wall -D_REENTRANT -fPIC -c udp-preload.c && \
  ld -shared -soname foo.so.1 udp-preload.o -o udp-preload.so -ldl -lc

produces a library with which

  LD_PRELOAD=test/udp-preload.so test/invoke

produces various complaints like

  udp (test/tmp/outside.conf:19): setsockopt(,IPV6_V6ONLY,&1,): Operation not supported
  udp (test/tmp/inside.conf:19): socket [::]:16913 experiencing some trouble transmitting IPv6 (to [::1]:16900): Bad file descriptor

This is progress.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Proof of concept wrapping (2)
Ian Jackson [Fri, 11 Oct 2019 23:30:02 +0000 (00:30 +0100)]
test: udp-preload: Proof of concept wrapping (2)

  gcc -D_REENTRANT -fPIC -c udp-preload.c && \
  ld -shared -soname foo.so.1 udp-preload.o -o udp-preload.so -ldl -lc

produces a library with which

  LD_PRELOAD=test/udp-preload.so test/invoke

still works.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Proof of concept wrapping
Ian Jackson [Fri, 11 Oct 2019 23:28:16 +0000 (00:28 +0100)]
test: udp-preload: Proof of concept wrapping

  gcc -D_REENTRANT -fPIC -c udp-preload.c -ldl -lc && \
  ld -shared -soname foo.so.1 udp-preload.o -o udp-preload.so

produces a library which makes secnet go

  secnet fatal error: Failed to initialise ADNS: Message too long

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: udp-preload: Import libauthbind.c
Ian Jackson [Fri, 11 Oct 2019 23:01:12 +0000 (00:01 +0100)]
test: udp-preload: Import libauthbind.c

This is from authbind 2.1.2 64b7841344fcc3cc.  It is GPLv2+ and
my own copyright so no licence problem.  I'm going to hack it up into
what is needed here.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Use dedicated tmp directory in variable
Ian Jackson [Fri, 11 Oct 2019 22:56:33 +0000 (23:56 +0100)]
test: Use dedicated tmp directory in variable

We are going to want to run multiple tests at once, so we'll need
this.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: if things aren't working time out rather than waiting forever
Ian Jackson [Fri, 11 Oct 2019 20:45:09 +0000 (21:45 +0100)]
test: if things aren't working time out rather than waiting forever

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: expect initial ping packet to come back on inside, for now
Ian Jackson [Fri, 11 Oct 2019 20:43:54 +0000 (21:43 +0100)]
test: expect initial ping packet to come back on inside, for now

We are pinging the remote secnet, which responds without sending the
packet to its host (ie, "outside.r" in our terms).

We can improve this later if we care.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: send an initial ping packet
Ian Jackson [Fri, 11 Oct 2019 20:41:18 +0000 (21:41 +0100)]
test: send an initial ping packet

The hex data came from
  ping -I secnet-test-i 172.18.232.1
  tcpdump -wt -isecnet-test-i
  tcpdump -rt -x

We send it twice because the first causes a key exchange and then gets
lost.

The result is that the script crashes with
  inside rx'd!

This is because we are pinging the remote secnet, which responds
without sending the packet to its host (ie, "outside.r" in our terms).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: use chiark-tcl-hbytes rather than ad-hoc \x quoting
Ian Jackson [Fri, 11 Oct 2019 20:33:01 +0000 (21:33 +0100)]
test: use chiark-tcl-hbytes rather than ad-hoc \x quoting

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Fix fd plumbing
Ian Jackson [Fri, 11 Oct 2019 20:31:44 +0000 (21:31 +0100)]
test: Fix fd plumbing

In a background process, stdin defaults to /dev/null, so we need to do
a little dance.  <&0 looks like it ought to work according to the bash
manual and does indeed work in bash, but not in dash.  This
construction seems to work in both.

Tested with:
  date | sh -exc 'cat <&0 >t &'

SuS says:
  If job control is disabled (see set, -m), the standard input for an
  asynchronous list, before any explicit redirections are performed,
  shall be considered to be assigned to a file that has the same
  properties as /dev/null. This shall not happen if job control is
  enabled. In all cases, explicit redirection of standard input shall
  override this activity.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Provide bgerror
Ian Jackson [Fri, 11 Oct 2019 19:14:49 +0000 (20:14 +0100)]
test: Provide bgerror

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Send initial confirmation byte, and wait for some rx
Ian Jackson [Fri, 11 Oct 2019 19:09:29 +0000 (20:09 +0100)]
test: Send initial confirmation byte, and wait for some rx

Now this hangs indefinitely because we don't send a packet.  That
comes next.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Fix names of stunt pipes
Ian Jackson [Fri, 11 Oct 2019 19:07:41 +0000 (20:07 +0100)]
test: Fix names of stunt pipes

"t" = transmit, ie packets written by us and read by secnet
"r" = receive, ie packets writeen by secnet and read by us

secnet is the network; we are the host.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Use stunt pipes and ipif shell script for netlink
Ian Jackson [Thu, 10 Oct 2019 23:30:22 +0000 (00:30 +0100)]
test: Use stunt pipes and ipif shell script for netlink

The overall effect is that now secnet crashes as soon as invoke
completes (ie, immediately) because there's no writer for the netlink
pipe.  This is good.  Also we no longer need "really".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Move common config into test script
Ian Jackson [Thu, 10 Oct 2019 19:29:10 +0000 (20:29 +0100)]
test: Move common config into test script

No functional change.  This duplicates the example, and we are going
to modify/parameterise the copy in "invoke".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Generate configs from pieces
Ian Jackson [Thu, 10 Oct 2019 16:52:25 +0000 (17:52 +0100)]
test: Generate configs from pieces

The resulting files are semantically equivalent to
test-example/{in,out}side.conf.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest: Provide first cut of invoke script
Ian Jackson [Thu, 10 Oct 2019 16:30:27 +0000 (17:30 +0100)]
test: Provide first cut of invoke script

This is going to be reorganised and improved a lot.  Right now it
doesn't do much and doesn't exit.  If ^C'd it leaks the secnet
processes.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoalg_msg_data: Remove "sig" from member names
Ian Jackson [Tue, 1 Oct 2019 12:12:40 +0000 (13:12 +0100)]
alg_msg_data: Remove "sig" from member names

We are going to want to use this for other algorithms too.

Suggested-by: Mark Wooding <mdw@distorted.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: hex_init: Call from enter_new_state
Ian Jackson [Sun, 29 Sep 2019 22:26:41 +0000 (23:26 +0100)]
site: hex_init: Call from enter_new_state

This seems more logical.  It also more clearly separates it from the
hacky_par system.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: kex_init: Have it return a boolean
Ian Jackson [Sun, 29 Sep 2019 22:24:37 +0000 (23:24 +0100)]
site: kex_init: Have it return a boolean

At some point this will become capable of failing.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Break out kex_init
Ian Jackson [Sun, 29 Sep 2019 19:47:08 +0000 (20:47 +0100)]
site: Break out kex_init

We are going to want to put some more things here.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agohash: Provide and use hash_hash connvenience function
Ian Jackson [Sun, 29 Sep 2019 12:47:39 +0000 (13:47 +0100)]
hash: Provide and use hash_hash connvenience function

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agohash: Put hash state on the caller's stack
Ian Jackson [Sun, 29 Sep 2019 12:29:09 +0000 (13:29 +0100)]
hash: Put hash state on the caller's stack

This makes the code simpler too!

We rename len to slen, to distinguish hlen and slen (to help avoid
bugs where the wrong amount is allocated).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Break out slog_start
Ian Jackson [Sun, 29 Sep 2019 12:01:46 +0000 (13:01 +0100)]
site: Break out slog_start

This will allow callers in site.c to build up messages bit by bit.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Pass msg into generate_msg
Ian Jackson [Sun, 29 Sep 2019 11:00:33 +0000 (12:00 +0100)]
site: Pass msg into generate_msg

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Pass msg into enter_new_state
Ian Jackson [Sun, 29 Sep 2019 10:46:22 +0000 (11:46 +0100)]
site: Pass msg into enter_new_state

The rules for when this is initialised, in site_incoming, are a
slightly complicated, so document them.

Examination of these rules reveals that the msg argument to
process_msg1 should be const, since process_msg1 (unlike the other
process_msgN functions) receives this, rather than generating it.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Move main `struct msg' into site_incoming
Ian Jackson [Sun, 29 Sep 2019 10:35:30 +0000 (11:35 +0100)]
site: Move main `struct msg' into site_incoming

We are going to want this in more places, and this is going to involve
threading it through site_incoming.  So make this a local variable
there, rather than in each of the process_msgN functions.

We rename the variable `named_msg' to `msg': it was called `named_msg'
because it was only valid after our calls to named_for_us, but now it
is valid after process_msgN too.

No overall functional change, except that stack usage is improved (by
removing a copy of struct msg).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Change `struct msg m' to `struct msg m[1]'
Ian Jackson [Sun, 29 Sep 2019 10:30:53 +0000 (11:30 +0100)]
site: Change `struct msg m' to `struct msg m[1]'

We are going to make this a pointer in a moment.  That implies a lot
of mechanical changes.  This [1] trick lets us do those changes now in
a separate patch, which makes things clearer.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoCOPY_OBJ: we use sizeof(dst) so relax restriction on src
Ian Jackson [Fri, 27 Sep 2019 23:14:47 +0000 (00:14 +0100)]
COPY_OBJ: we use sizeof(dst) so relax restriction on src

No code change, just interface docs.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosig: Move hashing into algorithm
Ian Jackson [Fri, 27 Sep 2019 18:09:22 +0000 (19:09 +0100)]
sig: Move hashing into algorithm

I think it should be up to the pk algorithm to decide on the hash
function, at least in the usual case.  When we have key rollover and
proper enrolment, a public key declaration by a site should specify
precisely the validation algorithm including the hash function.

For `rsa' we can't do that because in theory people might have bound
the `hash' config key to something unusual.  So provide a way for that
to work.  The approach is to have site.c (the only caller of the sig
closures) find out whether to do the `hash' config key lookup by
seeing whether the pk algorithm wants it.

Then we can move all the hash-related machinations into rsa.c.  (A
future pk algorithm can do this a lot more simply by calling the
appropriate hash functions directly.)

An effect is to move the allocation of the hash result buffer from
per-packet to initialisation (!)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosig: Move unmarshalling responsibility into algorithm
Ian Jackson [Fri, 27 Sep 2019 17:40:42 +0000 (18:40 +0100)]
sig: Move unmarshalling responsibility into algorithm

Because site wants to first unpick the packet, and only later actually
check the signature, we provide two entrypoints.  The first, `unpick',
basically just computes the length.  So the result of `unpick' is
simply a note of the part of the buffer which contains the signature.

The alternative would be to have site.c handle the length, so there
would be one entrypoint `check' which would get a byte block.  This
would move complexity from the `unpick'/`check' interface to the
`sign' interface (which would have to negotiate about space).  It
would mean that for algorithms where signatures are of fixed size, we
couldn't omit the length field.

rsa.c needs to do some shenanigans: because it wants to use
mpz_set_str (for historical reasons), it needs the buffer to be
nul-terminated.  So `unpick' checks that there will be a spare byte
afterwards into which we can write the nul.  `check' writes the nul -
and puts the previous character back, so that we don't have to write
weird stuff in the algorithm api.  Doing better than this would be
turd-polishing since this algorithm is obsolete.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosig: Move marshalling responsibility into sign function
Ian Jackson [Fri, 27 Sep 2019 17:37:40 +0000 (18:37 +0100)]
sig: Move marshalling responsibility into sign function

This is the first part of making the pk algorithm responsible for
understanding its signature format.

The sign function is expected to produce some bytes which (in a
moment) its companion functions will be able to parse.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosig: Make closure interface not contain sig alg name "rsa"
Ian Jackson [Thu, 26 Sep 2019 21:29:02 +0000 (22:29 +0100)]
sig: Make closure interface not contain sig alg name "rsa"

We intend to be able to support other signature algorithms.  This will
be done with this closure, but it ought to have a generic name.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Prepare for adding more MSG3 variants
Mark Wooding [Sun, 30 Apr 2017 23:11:25 +0000 (00:11 +0100)]
site: Prepare for adding more MSG3 variants

  * Introduce a macro listing the known MSG3 variants.  Use this in
    `type_is_msg34' and `site_incoming', and in the `process_msg3'
    molly-guard.

  * Break out MSG3-ish label minor numbers and analyse them using the
    sensible ordering, in `generate_msg' and `unpick_msg'.

  * Have `check_msg' fall back to trusting `process_msg3' for all
    MSG3-ish messages.  (It already has a more vicious molly-guard
    anyway.)

  * Reformat the decision tree in `generate_msg3' so that adding more
    branches is cleaner.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agosite: Replace remote's caps after verifying MSG3
Mark Wooding [Sat, 28 Sep 2019 15:13:45 +0000 (16:13 +0100)]
site: Replace remote's caps after verifying MSG3

Previously we'd just `or' the new capability bits into
`st->remote_capabilities' prior to verification, with the rather
unfortunate result that an adversary could convince us that the remote
site has features which it doesn't, in fact, implement.  At present, the
worst effect here is preventing key-exchange from completion, but it's
imaginable that future capability bits have worse effects.

Instead, (a) simply replace our idea of the remote site's capabilities
rather than accumulating a union of all mentioned capabilities, and (b)
do this /after/ verifying the signature on the message.  (This is safe
because there's no mention of `st->remote_capabilities' in the
intervening code in `process_msg3', or in the common message-
verification code in `process_msg3_msg4'.)

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agogitignore: add msgcode-test files
Ian Jackson [Sat, 28 Sep 2019 11:08:16 +0000 (12:08 +0100)]
gitignore: add msgcode-test files

This was erroneously omitted in 7b2ef2245c06
 "magic.h: Present message labels as an encoding of major and minor numbers."

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostyle: util.[ch]: Introduce hex_encode_alloc name
Ian Jackson [Sat, 28 Sep 2019 10:55:17 +0000 (11:55 +0100)]
style: util.[ch]: Introduce hex_encode_alloc name

Prompted by review of 7be31e47b2a8
  "util.[ch]: Factor out hex encoding and decoding utilities."
which says
  The interface is a bit odd, but it will fit with the uses
  I have in mind.

Not sure if it's the encode or decode interface which is referred to.
Certainly there should be a non-allocating variant.  I decided to
rename the allocating one.

The two separate buffer arguments to hex_decode are indeed a bit odd
but IMO tolerable.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostyle: util.[ch]: Move doc comments into header file
Ian Jackson [Sat, 28 Sep 2019 10:51:01 +0000 (11:51 +0100)]
style: util.[ch]: Move doc comments into header file

I think doc comments belong (only) in the header.

Spotted this anomaly during review of 7be31e47b2a8
  "util.[ch]: Factor out hex encoding and decoding utilities."
(although it wasn't introduced there).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostyle: util.h: Adjust comment style twice
Ian Jackson [Sat, 28 Sep 2019 10:44:15 +0000 (11:44 +0100)]
style: util.h: Adjust comment style twice

Prompted by review of 7be31e47b2a8
  "util.[ch]: Factor out hex encoding and decoding utilities."

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoconffile.fl: Use %option noyywrap rather than providing yywrap
Ian Jackson [Sat, 28 Sep 2019 10:39:04 +0000 (11:39 +0100)]
conffile.fl: Use %option noyywrap rather than providing yywrap

Prompted by review of fe0c91cce702
  "configure.in, conffile.fl: Remove dependency on `libfl.a'."

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite.c, magic.h, NOTES: Make early capabilities be dynamic.
Mark Wooding [Sun, 30 Apr 2017 23:18:39 +0000 (00:18 +0100)]
site.c, magic.h, NOTES: Make early capabilities be dynamic.

Replace the `CAPAB_EARLY' macro by a site member variable
`st->early_capabilities'.  The variable is always zero for now, like the
old macro, so there's no functional change.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agosecnet.8: Describe capability negotiation in its own section.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
secnet.8: Describe capability negotiation in its own section.

The notion is a little complicated, and we can give it the space it
deserves.  Also, this saves on a lot of repeated text, especially if we
add more things which require assignment of capability bits.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agosite.c: Abstract out the various parts of capability handling.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
site.c: Abstract out the various parts of capability handling.

Introduce macros for: setting the local capability flags from
crypto-algorithm closures; selecting a crypto algorithm based on the
capabilities reported by a peer site; and finding the local closure
based on the peer's algorithm decision.

This will make introducing new kinds of negotiation much less painful.
No functional change.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agomagic.h: Present message labels as an encoding of major and minor numbers.
Mark Wooding [Sun, 30 Apr 2017 23:03:08 +0000 (00:03 +0100)]
magic.h: Present message labels as an encoding of major and minor numbers.

The encoding is strange for historical reasons, but represents all pairs
of 16-bit major and minor codes.

I've exhaustively verified that the encoding is invertable, and that it
reproduces the old manually assigned labels; this program is
`msgcode-test.c', which I've added to the standard test run, though it's
rather slow to run.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agomagic.h: Put the CAPAB_... definitions together, under the big comment.
Mark Wooding [Sun, 30 Apr 2017 22:59:03 +0000 (23:59 +0100)]
magic.h: Put the CAPAB_... definitions together, under the big comment.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agosite.c: Rename `remote_transforms' in `process_msg2'.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
site.c: Rename `remote_transforms' in `process_msg2'.

As part of the drive to eliminate the idea of specific `transform
capabilities'.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agosecnet.8, magic.h: Rephrase documentation of `capab-num' settings.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
secnet.8, magic.h: Rephrase documentation of `capab-num' settings.

In particular, I've abolished the idea of a specific class of `transform
capabilities'.  They're all just capabilities, and they need to mean the
same thing at both ends.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agomagic.h, etc.: Rename the transform capability bits.
Mark Wooding [Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)]
magic.h, etc.: Rename the transform capability bits.

Mostly mechanical, with the following rune:

git grep -zil TRANSFORMNUM | xargs -0r sed -i '
s/TRANSFORMNUM/BIT/g
s/transformnum/bit/g
s/BIT_ANCIENT/&TRANSFORM/g'

But I renamed the `capab_transformnum' member of `struct msg' back by
hand, because it's referring specifically to a selected
transform.  (This will make sense later.)

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agosecnet-wireshark.lua: Add a Wireshark dissector.
Mark Wooding [Thu, 13 Jul 2017 11:30:57 +0000 (12:30 +0100)]
secnet-wireshark.lua: Add a Wireshark dissector.

(Some parts are a little strange, because it's been sent from the
future: it's structured to cope with protocol changes which haven't
happened yet.)

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agoutil.[ch]: Factor out hex encoding and decoding utilities.
Mark Wooding [Wed, 26 Apr 2017 10:53:05 +0000 (11:53 +0100)]
util.[ch]: Factor out hex encoding and decoding utilities.

Also improve the decoder's error handling.  The interface is a bit odd,
but it will fit with the uses I have in mind.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agopolypath.c: Fix missing include of <limits.h>.
Mark Wooding [Fri, 28 Apr 2017 18:41:30 +0000 (19:41 +0100)]
polypath.c: Fix missing include of <limits.h>.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agoconfigure.in, conffile.fl: Remove dependency on `libfl.a'.
Mark Wooding [Sat, 21 Sep 2019 13:35:44 +0000 (14:35 +0100)]
configure.in, conffile.fl: Remove dependency on `libfl.a'.

The `libfl' library contains two functions:

  * `main', which basically just calls `yylex' a lot, as an easy way to
    write simple programs in lex(1); and

  * `yywap', which lets a lex(1)-generated lexer know what to do when it
    encounters end-of-file.  Specifically, it can return nonzero to say
    `that's it, we're done', or zero to say `there's more: I've set up
    ``yyin'' so that you can read more stuff'.

The library doesn't do anything very sensible for `yywrap': it just
always returns 1.  (If you wanted to do something more complicated, you
should just write `yywrap' yourself.)

Secnet has its own `main' function which is fine.  It wants `yywrap',
though.  This causes trouble with upstream `flex', which nowadays builds
a shared `libfl.so' library.  This contains /both/ `yywrap' /and/
`main', which breaks the `configure' test: what happens is that the test
program requires `yywrap', which brings in `libfl.so', which brings in
its `main', which refers to an undefined symbol `yylex' that's not
defined in the test program.  This doesn't go wrong in Debian, because
Debian replaces the shared-library `libfl.so' with a linker script which
says `oh, no, you don't want this: you want that ``libfl_pic.a'' over
there'.  The latter is a traditional archive, and ld(1) can pick
`yywrap' out of it without pulling in the bogus `main' and its
dependency on `yylex'.

Anyway, this is all more trouble than it's worth.  Define our own
`yywrap' in `conffile.fl', and delete the `configure' machinery.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agoNOTES: Fix text, now than an early bit exists.
Mark Wooding [Sat, 21 Sep 2019 13:00:30 +0000 (14:00 +0100)]
NOTES: Fix text, now than an early bit exists.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
4 years agoMakefile.in: Drop dist target
Ian Jackson [Sat, 21 Sep 2019 11:42:29 +0000 (12:42 +0100)]
Makefile.in: Drop dist target

It is much easier to do this with dgit sbuild, like the release
checklist now suggests.  People who don't want to use dgit or sbuild
could use git-archive.  dist targets are IMO obsolete.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>