chiark / gitweb /
secnet.git
4 years agoparallel bisect scripts: ad-hoc
Ian Jackson [Sun, 8 Dec 2019 02:07:02 +0000 (02:07 +0000)]
parallel bisect scripts: ad-hoc

This is as I just used to bisect a P(1/256) bug.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Move earlier all things needed for slog
Ian Jackson [Sun, 8 Dec 2019 10:19:19 +0000 (10:19 +0000)]
site: Move earlier all things needed for slog

Before this we actually read uninitialised memory!
But it was st->log_events which was generally all-bit-zero.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agolog: Remove a now-redundant conditional
Ian Jackson [Sun, 8 Dec 2019 10:19:02 +0000 (10:19 +0000)]
log: Remove a now-redundant conditional

system_log is always non-NULL now.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agolog: Provide system_log from the very start
Ian Jackson [Sun, 8 Dec 2019 10:17:27 +0000 (10:17 +0000)]
log: Provide system_log from the very start

It is just too inconvenient not to have this while reading the config.
Set up a default system_log which logs to stderr.  When setup_log
is called, system_log will be overwritten and this struct is no
longer used.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agolog: Break out logfile_file_init
Ian Jackson [Sun, 8 Dec 2019 10:16:55 +0000 (10:16 +0000)]
log: Break out logfile_file_init

We are going to reuse this.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Add test for load-private
Ian Jackson [Sat, 7 Dec 2019 16:05:37 +0000 (16:05 +0000)]
stest: Add test for load-private

The resulting interface for privkey() is a bit odd: it's either a list
of a string, and we look at both ends.  Ah well, it's only test code.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoload-private: Use cfgfile_log, not system_log
Ian Jackson [Sat, 7 Dec 2019 16:30:17 +0000 (16:30 +0000)]
load-private: Use cfgfile_log, not system_log

Otherwise if this goes wrong, we segfault, because system_log is in
fact not available this early.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosecnet: Provide `load-private' verb
Ian Jackson [Sat, 7 Dec 2019 14:25:53 +0000 (14:25 +0000)]
secnet: Provide `load-private' verb

This allows the config file to specify the use of the scheme loadpriv
call with an arbitrary private key file and algorithm, without having
to enable the private key negotiation system.

This is the private key counterpart to
  secnet: Provide `make-public' verb

Like the first provision of `make-public', there is a bug: we use
system_log for reporting errors, but that is not set up until after
the configuration is read.  So errors turn into segfaults.  We will
fix that in a moment.

Aside from that, with this change, new public key schemes can just
provide an entry in the sigschemes table.  They do not need to (and
should not) define their own toplevel config bindings.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: Break out DEFAULT_MAXPRIV_BYTES
Ian Jackson [Sat, 7 Dec 2019 16:31:08 +0000 (16:31 +0000)]
privcache: Break out DEFAULT_MAXPRIV_BYTES

We're going to reuse this.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosecnet: loadpriv interface: Return a closure_t too
Ian Jackson [Sat, 7 Dec 2019 14:57:04 +0000 (14:57 +0000)]
secnet: loadpriv interface: Return a closure_t too

We are going to want this for the `load-private' verb.
This is the private key counterpart to:
   secnet: loadpub interface: Return a closure_t too

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: Minor style fixes
Ian Jackson [Sat, 7 Dec 2019 15:41:06 +0000 (15:41 +0000)]
privcache: Minor style fixes

We had some unconventional-for-secnet whitespace around `='.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: Regularise error handling in missing defhash case
Ian Jackson [Sat, 7 Dec 2019 14:49:50 +0000 (14:49 +0000)]
privcache: Regularise error handling in missing defhash case

Now it is clearer to see that we don't leak sigpriv;

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache; uncached_load_file: Introduce error_out
Ian Jackson [Sat, 7 Dec 2019 14:43:54 +0000 (14:43 +0000)]
privcache; uncached_load_file: Introduce error_out

The error handling here is a bit fragile: we rely on not having set
`ok' inappropriately.  Indeed actually we *do* set `ok'
inappropriately if we lack defhash, but in that case we set sigpriv to
0 so do return 0 as needed.  So we are fixing a latent bug.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoCL_GET_STR_ARG: Move into util.h
Ian Jackson [Sat, 7 Dec 2019 14:19:44 +0000 (14:19 +0000)]
CL_GET_STR_ARG: Move into util.h

Move this handy macro from pubkeys.c so that we can reuse it.
(And rename it appropriately.)

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: Break out uncached_load_file
Ian Jackson [Sat, 7 Dec 2019 14:13:24 +0000 (14:13 +0000)]
privcache: Break out uncached_load_file

We are going to want to reuse this to make a new entrypoint.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: Transpose scheme lookup and file opening
Ian Jackson [Sat, 7 Dec 2019 14:04:58 +0000 (14:04 +0000)]
privcache: Transpose scheme lookup and file opening

This makes no real difference, except that it provides a different
error message if both things are wrong.

This new odrering is more consistent with a change we are about to
make.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: uncached_get: Introduce `databuf' local
Ian Jackson [Sat, 7 Dec 2019 14:02:49 +0000 (14:02 +0000)]
privcache: uncached_get: Introduce `databuf' local

This is a bit more convenient and will also make a future commit much
easier too read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: uncached_get: Introduce `defhash' local
Ian Jackson [Sat, 7 Dec 2019 14:01:57 +0000 (14:01 +0000)]
privcache: uncached_get: Introduce `defhash' local

This is a bit more convenient and will also make a future commit much
easier too read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: uncached_get: Introduce `path' local
Ian Jackson [Sat, 7 Dec 2019 13:01:32 +0000 (13:01 +0000)]
privcache: uncached_get: Introduce `path' local

This is a bit more convenient and will also make a future commit much
easier too read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest/t-Cnonnego-onr: New test
Ian Jackson [Thu, 5 Dec 2019 01:24:02 +0000 (01:24 +0000)]
stest/t-Cnonnego-onr: New test

Check that the new site can initiate key exchange when talking to a
old one, as well as vice versa.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Make it possible to have kex initiated by `outside'
Ian Jackson [Thu, 5 Dec 2019 01:23:16 +0000 (01:23 +0000)]
stest: Make it possible to have kex initiated by `outside'

Introduce new `initiator' variable.  No functional change (other than
to messages) with existing tests.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosest/t-Cnonnego-on: New test
Ian Jackson [Thu, 5 Dec 2019 00:58:16 +0000 (00:58 +0000)]
sest/t-Cnonnego-on: New test

See if we can do key exchange with an older secnet, if the user has
told us where to find one to try it with.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Machinery for runing an old secnet if a test wants
Ian Jackson [Thu, 5 Dec 2019 00:58:10 +0000 (00:58 +0000)]
stest: Machinery for runing an old secnet if a test wants

Tests can now set oldsecnet(SITE).

Old secnets want a "filename" key in their log config.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-common: Framework for compatibility tests
Ian Jackson [Fri, 6 Dec 2019 23:00:53 +0000 (23:00 +0000)]
test-common: Framework for compatibility tests

Now normal tests must start with a letter.  Ones starting with C
require OLD_SECNET_DIR.  (Right now that must be both source and build
dir because it's tedious to have to distinguish them and pass both.)

Update comprehensive-test to (i) notice if the user forgot to set
this (ii) make it into an absolute path.  Note that comprehensive-test
therefore has a different default to `make check': If OLD_SECNET_DIR
is not set, `make check' will do none of those tests, but
comprehensive-test will complain (and wants "" to disable those
tests).

We do not need to print this variable in our debugging output about
how we are running secnet (or how the user who specifies _DIVERT_=i
should run it).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-common: Use $(wildcard ) rather than $(shell echo )
Ian Jackson [Thu, 5 Dec 2019 01:18:26 +0000 (01:18 +0000)]
test-common: Use $(wildcard ) rather than $(shell echo )

This is probably a bit faster, but more relevantly it would DTRT if
for some reason there were no applicable tests.  Which is going to
happen in a moment, when we add some machinery before the applicable
test.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomtest/t-filter: New test for --filter mode
Ian Jackson [Wed, 4 Dec 2019 22:06:37 +0000 (22:06 +0000)]
mtest/t-filter: New test for --filter mode

Checked the output with
  env -u LESS git-diff --color --word-diff -w :test-example/sites :mtest/e-filter.sites
and it looks right.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Provide --filter mode
Ian Jackson [Wed, 4 Dec 2019 16:56:31 +0000 (16:56 +0000)]
make-secnet-sites: Provide --filter mode

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoREADME.make-secnet-sites: Slightly restructure mode docs
Ian Jackson [Wed, 4 Dec 2019 16:54:59 +0000 (16:54 +0000)]
README.make-secnet-sites: Slightly restructure mode docs

This will make it easier to add a new mode.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: OpConf: Move positional_args to OpBase
Ian Jackson [Wed, 4 Dec 2019 16:51:52 +0000 (16:51 +0000)]
make-secnet-sites: OpConf: Move positional_args to OpBase

This is actually a general-purpose input/output file handler.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: OpUserv: Rename sitesfile to outputfile
Ian Jackson [Wed, 4 Dec 2019 16:50:48 +0000 (16:50 +0000)]
make-secnet-sites: OpUserv: Rename sitesfile to outputfile

This is not entirely right for OpUserv because OpUserv reads it too.
But this is going to make sense when we reuse more of OpBase.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: OpBase.write_out: Move heading back into OpUserv
Ian Jackson [Wed, 4 Dec 2019 16:44:58 +0000 (16:44 +0000)]
make-secnet-sites: OpBase.write_out: Move heading back into OpUserv

This relies on self.user, and in more general cases we want the output
to be reproducible so don't want the time either.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: OpBase.write_out: Tolerate sitesfile is None
Ian Jackson [Wed, 4 Dec 2019 16:42:46 +0000 (16:42 +0000)]
make-secnet-sites: OpBase.write_out: Tolerate sitesfile is None

This will let us write to stdout.  The only user right now is OpUserv
which always sets sitesfile so no functional change yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Abolish now-obsolete `service' variable
Ian Jackson [Wed, 4 Dec 2019 16:38:02 +0000 (16:38 +0000)]
make-secnet-sites: Abolish now-obsolete `service' variable

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Provide explicit --conf mode option
Ian Jackson [Wed, 4 Dec 2019 16:35:44 +0000 (16:35 +0000)]
make-secnet-sites: Provide explicit --conf mode option

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: OpBase.read_in: save read lines
Ian Jackson [Wed, 4 Dec 2019 16:33:52 +0000 (16:33 +0000)]
make-secnet-sites: OpBase.read_in: save read lines

We are going to use this for a new filtering mode.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Move sites file writing into OpBase
Ian Jackson [Wed, 4 Dec 2019 16:32:41 +0000 (16:32 +0000)]
make-secnet-sites: Move sites file writing into OpBase

We provide a callback for the contents.

This is in OpBase rather than OpUserv because we are going to want to
reuse it.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Refactor operational code into OpModes
Ian Jackson [Wed, 4 Dec 2019 16:19:23 +0000 (16:19 +0000)]
make-secnet-sites: Refactor operational code into OpModes

Everywhere we had conditionals on `service', move the two arms of the
if into methods on OpConf and OpUserv (of which we make one
singleton).

Many global variables become instance variables on the OpMode object.

The read_in method of OpConf is in OpBase because we are going to want
to reuse it.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Introduce new OpMod classes
Ian Jackson [Wed, 4 Dec 2019 16:06:58 +0000 (16:06 +0000)]
make-secnet-sites: Introduce new OpMod classes

This is going to replace the use of the `service' boolean.
Mode-specific functionality will be moved into these classes.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest/t-nonnego-oo: Use `make-public' verb
Ian Jackson [Tue, 3 Dec 2019 23:33:16 +0000 (23:33 +0000)]
stest/t-nonnego-oo: Use `make-public' verb

This was previously untested.  It is awkward to get make-secnet-sites
to generate this right now because it wants to generate `rsa-public'
calls for rsa1 keys for compatibility reasons.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Honour new sitesconf_hook
Ian Jackson [Tue, 3 Dec 2019 23:26:20 +0000 (23:26 +0000)]
stest: Honour new sitesconf_hook

This lets individual tests fiddle with the sites.conf.

By default, we provide a proc that does nothing.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomtest: Use --pubkeys-elide instead of --output-version
Ian Jackson [Sun, 1 Dec 2019 14:00:41 +0000 (14:00 +0000)]
mtest: Use --pubkeys-elide instead of --output-version

We don't want our basic tests of make-secnet-sites to produce an
artificially old output version.

But also it's not really convenient for these tests to make a pubkeys
directory.  (That functionality is tested by test-example's sites.conf
generator and stest's uses of the resulting pubkeys directory.)

So use --pubkeys-elide, conveniently producing a test case for that
option, which we were previously lacking.

Because we don't pass --pubkeys-dir, the result is that the output
paths contain the default pubkeys directory.  That's OK.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Fix an entry in &DEPS
Ian Jackson [Wed, 4 Dec 2019 21:54:31 +0000 (21:54 +0000)]
stest: Fix an entry in &DEPS

We don't want to refer to all-privkeys, actually.  This is a phony
target and causes needless rebuilds (well, retests).

Instead, depend on the now-provided $(test-example_PRIVKEYS).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: all-privkeys: Define, and indirect through, a variable
Ian Jackson [Wed, 4 Dec 2019 21:58:54 +0000 (21:58 +0000)]
test-example: all-privkeys: Define, and indirect through, a variable

This seems more natural.  Also it provides a variable
$(test-example_PRIVKEYS) which can be used elsewhere.  (We are in fact
going to want that.)

One resulting change is that now the keys in *.privkeys/ are part of
&TARGETS too.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: Test new long-term key arrangements
Ian Jackson [Sat, 16 Nov 2019 17:39:50 +0000 (17:39 +0000)]
test-example: Test new long-term key arrangements

Finally we can test this!

Specifically, we switch the defaults to the privkeys directories,
which affects the existing t-basic-kex test.  We introduce two new
tests for testing the old arrangements.

The consequences for the t-basic-kex test are:
 * Use the sites file generated with --install-pubkeys, thus
   testing the new make-secnet-sites.
 * Use peer-keys, so testing secnet's new pubkey loading
   mechanisms.
 * Use priv-cache, so testing secnet's new privkey loading
   mechanisms.
 * Test the new public key choice negotation mechanism.

The old tests tests the compatibility of the key choice negotiation
mechanism, as well as the capability to generate
old-style (compatible) sites.conf files.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: Generate new style sites.conf
Ian Jackson [Sun, 29 Dec 2019 14:44:59 +0000 (14:44 +0000)]
test-example: Generate new style sites.conf

The key change here is to make the `normal' test-exampple/sites.conf
file be new-style, with peer-keys entries.

We also switch the tests to use the old-style file.  So the tests in
fact run just as before.

The directory we give to make-secnet-sites is already mkdir'd, and
cleaned, appropriately.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: Make sites.conf variable, in principle
Ian Jackson [Tue, 3 Dec 2019 21:52:07 +0000 (21:52 +0000)]
test-example: Make sites.conf variable, in principle

In this commit we split the setting of the sites.conf into two
branches depending on the value of privkey($site).  The path prefix
is common - only the leafname varies.

Right now there isn't actually any change because both branches use
the same sites.conf.  The new-style arrangement needs a new-style
sites file which isn't there yet.

So no functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: Provide a new-style public key set for site outside
Ian Jackson [Fri, 8 Nov 2019 20:09:39 +0000 (20:09 +0000)]
test-example: Provide a new-style public key set for site outside

With --output-version=1, this produces the same output.

The base91 data here is the output of
  base91s/base91s -w0 <test-example/rsa1-sites2.key.pub

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotests: Pass --output-version=1 to make-secnet-sites
Ian Jackson [Sun, 1 Dec 2019 11:35:02 +0000 (11:35 +0000)]
tests: Pass --output-version=1 to make-secnet-sites

We are going to introduce some new public keys in the sites file but
for now we don't want to change the sites.conf output.  This is what
--output-version is for.

Later we will relegate this to compatibility tests, and make the new
approach the default.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Honour new privkey() hash
Ian Jackson [Tue, 3 Dec 2019 21:03:46 +0000 (21:03 +0000)]
stest: Honour new privkey() hash

If set to a path not ending in /, it refers to a key file, and we
generate the "rsa-private" call.  With the default value, this
produces the same path as before.

But now it can be set to a directory ending in /, in which case we
specify a priv-cache.

No functional change yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Provide a global `hash' key
Ian Jackson [Tue, 3 Dec 2019 21:00:24 +0000 (21:00 +0000)]
stest: Provide a global `hash' key

This is mostly going to be for the benefit of priv-cache, which we are
going to start using.  But putting it at the top level seems sensible.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agostest: Transfer pubkeys from test-example
Ian Jackson [Tue, 3 Dec 2019 20:56:42 +0000 (20:56 +0000)]
stest: Transfer pubkeys from test-example

We are going to have tests which use the peer-keys site config key,
which refers to external key files from a pubkeys directory.  In the
case of stest, these are pubkeys from test-example.

Because secnet may rename files etc. in this directory, we need a
private one per test.  So, for each test, when making the config file,
make a copy of the pubkeys directory.  Of course this means that
directory needs to exist, so mkdir it (and clean it), although the
machinery for populating it doesn't exist yet.

Also, when copying the sites.conf file, adjust references to
test-example to refer to the copy.  (Currently there won't be any such
references.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: Add a 2nd rsa1 key
Ian Jackson [Sat, 16 Nov 2019 15:50:49 +0000 (15:50 +0000)]
test-example: Add a 2nd rsa1 key

We add it to the build rules so we install it in privkeys, and so on,
but right now we don't do anything with it.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: Add the inside.key to the privcache too
Ian Jackson [Sun, 24 Nov 2019 00:28:38 +0000 (00:28 +0000)]
test-example: Add the inside.key to the privcache too

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: Make privkeys by default
Ian Jackson [Sat, 23 Nov 2019 18:55:20 +0000 (18:55 +0000)]
test-example: Make privkeys by default

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agotest-example: Rules for making a privkeys directory
Ian Jackson [Mon, 2 Dec 2019 13:45:16 +0000 (13:45 +0000)]
test-example: Rules for making a privkeys directory

This generates a directory suitable for use with the priv-cache
closure.  Nothing uses it yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Declare `pubkey' directive old
Ian Jackson [Fri, 8 Nov 2019 23:32:31 +0000 (23:32 +0000)]
make-secnet-sites: Declare `pubkey' directive old

In help output and error messages.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: New --pubkeys-elide mode
Ian Jackson [Sun, 1 Dec 2019 21:41:01 +0000 (21:41 +0000)]
make-secnet-sites: New --pubkeys-elide mode

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Rework --pubkeys-MODE, provide --pubkeys-single
Ian Jackson [Sun, 1 Dec 2019 12:45:15 +0000 (12:45 +0000)]
make-secnet-sites: Rework --pubkeys-MODE, provide --pubkeys-single

Replace the open-coded ifs in sitelevel's sites.conf writer and public
key installation code with calls to a class which manages the
behaviour.

This provides a new --pubkeys-single option which does what
--no-pubkeys-install would have done if it were permitted.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Rework with new `inpub' class
Ian Jackson [Sun, 1 Dec 2019 17:38:31 +0000 (17:38 +0000)]
make-secnet-sites: Rework with new `inpub' class

The use of k.forsites(,None,) was rather unprincipled and required a
strange comment.  Instead, invent a `forpub' method for this use.
`forsites' can be implemented, for these classes, in terms of forpub.

Likewise testing whether the return from forsites was []; replace that
with an okforonlykey method.  (The implementation uses the same trick
but now it's inside the class.)

We transpose the if `pubkeys_install' with the `for k' loop.  The `not
pubkeys_install' arm is rather different now, accumulating in outk.

The one nontrivial consquence is that now if there are multiple
eligible keys to be written to a sites.conf, we fail, rather than just
choosing the first.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: In v1 output, ignore keys for non-0 groups
Ian Jackson [Sun, 1 Dec 2019 17:55:32 +0000 (17:55 +0000)]
make-secnet-sites: In v1 output, ignore keys for non-0 groups

This helps makes us conform to the spec in NOTES.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Support `pkg' and `pkgf'
Ian Jackson [Sun, 1 Dec 2019 17:55:09 +0000 (17:55 +0000)]
make-secnet-sites: Support `pkg' and `pkgf'

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Support `serial'
Ian Jackson [Sun, 1 Dec 2019 17:54:03 +0000 (17:54 +0000)]
make-secnet-sites: Support `serial'

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Without --pubkeys-install, write appropriate key
Ian Jackson [Sat, 7 Dec 2019 17:37:41 +0000 (17:37 +0000)]
make-secnet-sites: Without --pubkeys-install, write appropriate key

Rather than hoping that the first thing in the list is appropriate,
write out the first *key* we come across.

This is needed because we are going to introduce into the 'pub' list
things that are not keys.  We don't want to somehow try to write to a
.conf file something corresponding to `serial' or `pkg' or `pkgf'.

The `indefault' variable will tracks whether we are in the default
pubkey group.  Right now we don't understand pubkey groups so it is
just `True'.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: New --pubkeys-install option
Ian Jackson [Sun, 1 Dec 2019 16:53:01 +0000 (16:53 +0000)]
make-secnet-sites: New --pubkeys-install option

This diverts public keys from the sites.conf to the pubkeys directory
and uses the `peer-keys' conf key instead of `key'.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Add new pubkeys-dir option, and pubkey paths
Ian Jackson [Sun, 1 Dec 2019 16:51:24 +0000 (16:51 +0000)]
make-secnet-sites: Add new pubkeys-dir option, and pubkey paths

This is where we are going to store peer public keys for each site.

Nothing uses it yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Handle `pub rsa1' properties specially
Ian Jackson [Sun, 1 Dec 2019 16:47:36 +0000 (16:47 +0000)]
make-secnet-sites: Handle `pub rsa1' properties specially

We construct these as a special kind of `rsakey' object, rather than
`pubkey' objects.  This means they will be written out to sites files
the way rsa1 keys are: ie in v1, using `pubkey' rather than `pub' in
sites files and using the rsa-public verb rather than make-public.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Write rsa1 keys as `pub rsa1 ...' in >=v2
Ian Jackson [Sun, 1 Dec 2019 18:45:44 +0000 (18:45 +0000)]
make-secnet-sites: Write rsa1 keys as `pub rsa1 ...' in >=v2

This effectively deprecates the `pubkey' keyword, relegating it to a
compatibility feature.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Do not use `copy' in pubkey forsites
Ian Jackson [Sun, 1 Dec 2019 18:39:36 +0000 (18:39 +0000)]
make-secnet-sites: Do not use `copy' in pubkey forsites

We are going to make some new call sites which don't have a suitable
`copy' available.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Do not write `pub' entries in v1 output
Ian Jackson [Sun, 1 Dec 2019 16:45:28 +0000 (16:45 +0000)]
make-secnet-sites: Do not write `pub' entries in v1 output

This introduces file version 2.

We document the ultimately intended meaning of version 2 even though
we don't implement all that yet.  The remaining pieces are on their
way.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Make the `pub' key name primary
Ian Jackson [Sat, 9 Nov 2019 00:13:52 +0000 (00:13 +0000)]
make-secnet-sites: Make the `pub' key name primary

No outward functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Support new `pub' directive
Ian Jackson [Sat, 9 Nov 2019 00:08:21 +0000 (00:08 +0000)]
make-secnet-sites: Support new `pub' directive

This is how we are going to support multiple public key algorithms.

Right now there is no backward-combinatibility support and no key
negotiation support.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Prepare for multiple public key types
Ian Jackson [Sat, 9 Nov 2019 00:03:49 +0000 (00:03 +0000)]
make-secnet-sites: Prepare for multiple public key types

* Introduce a general base typee for public keys.

* Indirect public key object construction through a function
  which is suitable for passing to listof(), and which will
  despatch appropriately.  This allows a heterogenous list.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Provide `serial' property class
Ian Jackson [Fri, 29 Nov 2019 21:32:37 +0000 (21:32 +0000)]
make-secnet-sites: Provide `serial' property class

This will be used for public key groupids and key set ids.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Provide ArgActionLambda
Ian Jackson [Sun, 1 Dec 2019 15:55:48 +0000 (15:55 +0000)]
make-secnet-sites: Provide ArgActionLambda

optparse has a helpful lambda facility, so you can pass a lambda
directly to add_argument.  But optparse is deprecated so we are using
argparse, in which this facility was unaccountably removed.

Instead you have to subclass argparse.Action.

The resulting ArgActionLambda will still be a bit awkward to use but a
lot better than lifting what ought to be each lambda body into its own
subclass.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Allow properties to control output to sites
Ian Jackson [Fri, 29 Nov 2019 20:07:45 +0000 (20:07 +0000)]
make-secnet-sites: Allow properties to control output to sites

When lines containing properties are being copied to an output sites
file, the property can now control what gets written.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Provide --output-version option
Ian Jackson [Fri, 29 Nov 2019 21:42:01 +0000 (21:42 +0000)]
make-secnet-sites: Provide --output-version option

This will be used to have make-secnet-sites produce
backward-compatible output for older readers.

This is mostly going to be used for a filtering mode, where
make-secnet sites will copy its input to its output downgrading things
as it goes.

It is also going to have the effect of limiting the secnet.conf file
output when --pubkeys-install is not specified, so that the peer key
that appears in the generated sites.conf is the old-style
pre-negotiation RSA key, as demanded by the spec.

The users of this variable, and the whole --pubkeys-install option,
and the filtering mode, are yet to come.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Provide base91s_encode and base91s_decode
Ian Jackson [Fri, 29 Nov 2019 21:27:00 +0000 (21:27 +0000)]
make-secnet-sites: Provide base91s_encode and base91s_decode

We will use these in a moment.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: pline: Break up `copyout'
Ian Jackson [Fri, 29 Nov 2019 20:08:40 +0000 (20:08 +0000)]
make-secnet-sites: pline: Break up `copyout'

Now we have `copyout_core' and `indent', too.

We are going to want to reuse these.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Introduce FilterState
Ian Jackson [Fri, 29 Nov 2019 20:05:21 +0000 (20:05 +0000)]
make-secnet-sites: Introduce FilterState

This is going to let us be more stateful as we copy lines from the
input to an output sites file, and as we process public keys into
output secnet.conf files.

No functional change yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Tainted: Provide some commented-out debug
Ian Jackson [Fri, 29 Nov 2019 19:55:49 +0000 (19:55 +0000)]
make-secnet-sites: Tainted: Provide some commented-out debug

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Provide --debug and debugrepr
Ian Jackson [Fri, 29 Nov 2019 19:54:42 +0000 (19:54 +0000)]
make-secnet-sites: Provide --debug and debugrepr

Useful for debugging.  So far our only caller helps with debugging the
argument parser itself.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: pubkeys: Allow multiple
Ian Jackson [Sat, 9 Nov 2019 00:10:16 +0000 (00:10 +0000)]
make-secnet-sites: pubkeys: Allow multiple

Make `pubkey' listish, so you can specify several.  It is still
required.  And only the first is used right now.

A harmless side effect is to reorder the output: `key' entries now
come before the more general properties.  But we must update the
expected test case output.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: set_property: Support "aliases"
Ian Jackson [Fri, 8 Nov 2019 21:19:58 +0000 (21:19 +0000)]
make-secnet-sites: set_property: Support "aliases"

No functional change with existing `keywords' data.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: set_property: Break out propname
Ian Jackson [Fri, 8 Nov 2019 21:28:23 +0000 (21:28 +0000)]
make-secnet-sites: set_property: Break out propname

This will make for a nicer diff, in a moemnt.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: set_property: Break out kw
Ian Jackson [Fri, 8 Nov 2019 21:18:44 +0000 (21:18 +0000)]
make-secnet-sites: set_property: Break out kw

This will make for a nicer diff, in a moemnt.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Tainted: Provide hexid and base91
Ian Jackson [Fri, 8 Nov 2019 22:00:51 +0000 (22:00 +0000)]
make-secnet-sites: Tainted: Provide hexid and base91

These will be used for new-style public key specifictions.
No callers yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Tainted.name: take `what'
Ian Jackson [Fri, 8 Nov 2019 21:54:47 +0000 (21:54 +0000)]
make-secnet-sites: Tainted.name: take `what'

No functional change with existing callers.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Write output to ...~tmp~ and rename
Ian Jackson [Thu, 7 Nov 2019 00:42:02 +0000 (00:42 +0000)]
make-secnet-sites: Write output to ...~tmp~ and rename

This avoids leaving a truncated output file if we crash.  It also
avoids concurrent readers ever seeing a truncated output file.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Tolerate late `complain'
Ian Jackson [Sun, 1 Dec 2019 17:35:27 +0000 (17:35 +0000)]
make-secnet-sites: Tolerate late `complain'

In e5baf0cd0e91353194df02c4c376b0c472f49ec2
  make-secnet-sites: Crash if complain() is called too late
we checked for this.

But actually we want to support it.  Do so by exiting right away.

So, early enough complaints are saved up.  Late ones cause immediate
exit.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-secnet-sites: Deduplicate `complain'
Ian Jackson [Sun, 1 Dec 2019 17:34:57 +0000 (17:34 +0000)]
make-secnet-sites: Deduplicate `complain'

The body contains much of moan.  Call it, instead.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agomake-public: Use cfgfile_log, not system_log
Ian Jackson [Sat, 7 Dec 2019 16:32:55 +0000 (16:32 +0000)]
make-public: Use cfgfile_log, not system_log

Otherwise if this goes wrong, we segfault, because system_log is in
fact not available this early.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agolog: Provide struct cfgfile_log
Ian Jackson [Sat, 7 Dec 2019 16:29:21 +0000 (16:29 +0000)]
log: Provide struct cfgfile_log

This can be used as a logger during config reading.  system_log is not
available yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agovcfgfatal_maybefile: New suffix argument
Ian Jackson [Sat, 7 Dec 2019 16:27:17 +0000 (16:27 +0000)]
vcfgfatal_maybefile: New suffix argument

We are going to want to provide a log_if that calls *cfgfatal*.
Messages sent to a log_if do not have a \n, but messages passed to
cfgfatal do.  (This is daft, btw.)

To help resolve this impedance mismatch, provide a "suffix" parameter.
We only need this for vcfgfatal_maybefile, not for any of the other
variants.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosecnet: Provide `make-public' verb
Ian Jackson [Tue, 3 Dec 2019 22:57:25 +0000 (22:57 +0000)]
secnet: Provide `make-public' verb

This allows the config file to specify the use of the scheme loadpub
call without having to put public keys in separate files.  That will
be useful for testing and perhaps in installations that just want
fixed keys.

There is a bug here: we use system_log for reporting errors, but that
is not set up until after the configuration is read.  So errors turn
into segfaults.  We will fix that in a moment.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosecnet: loadpub interface: Return a closure_t too
Ian Jackson [Tue, 3 Dec 2019 22:57:15 +0000 (22:57 +0000)]
secnet: loadpub interface: Return a closure_t too

We are going to want this for the `make-public' verb.  In principle we
could just return the closure and the call site that wants the ops
could fish it out, but given that we have both this seems nicer.

(The secnet closure interface paradigm is not particularly pretty but
I don't fancy reworking it now...)

We will want this for loadpriv, too.  That will come (considerably)
later.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agopubkeys: Introduce `fill' variable to make code prettier
Ian Jackson [Sun, 24 Nov 2019 10:27:54 +0000 (10:27 +0000)]
pubkeys: Introduce `fill' variable to make code prettier

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Include key indices in log output
Ian Jackson [Sun, 24 Nov 2019 01:39:23 +0000 (01:39 +0000)]
site: Include key indices in log output

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Better logging of key ids etc.
Ian Jackson [Sun, 24 Nov 2019 01:00:30 +0000 (01:00 +0000)]
site: Better logging of key ids etc.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agodocs: Move peer-keys documentation into a README file
Ian Jackson [Mon, 2 Dec 2019 13:14:09 +0000 (13:14 +0000)]
docs: Move peer-keys documentation into a README file

This is externally visible and should be in documentation.  For now we
put it in NOTES.peer-keys.  At some point the secnet docs really need
to be (re)organised...

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agodocs: Fix rsapriv/rsapub closure names
Ian Jackson [Wed, 27 Nov 2019 13:56:01 +0000 (13:56 +0000)]
docs: Fix rsapriv/rsapub closure names

In a04dfe0d448e
  sig: Make closure interface not contain sig alg name "rsa"
we changed the code, but not the documentation.  Repair this.

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