chiark / gitweb /
secnet.git
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>
4 years agopubkey handling: Call sethash when needed
Ian Jackson [Sat, 23 Nov 2019 18:29:13 +0000 (18:29 +0000)]
pubkey handling: Call sethash when needed

Pass defhash about.

Without this, attempts to use these new arrangements (in particular,
keyset_load when there are rsa1 keys involved, which will be the usual
new arrangement) would segfault.

This fixes the bug introduced in:
  site: Read public peer keys from key file

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Move defhash from setup to st variable
Ian Jackson [Sat, 23 Nov 2019 18:27:35 +0000 (18:27 +0000)]
site: Move defhash from setup to st variable

We tolerate it being missing when we actually look it up.
setup_sethash gains an explicit error check.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoREADME: Document new semantics for `hash'
Ian Jackson [Wed, 27 Nov 2019 13:49:46 +0000 (13:49 +0000)]
README: Document new semantics for `hash'

Since 13b8fbf4548f3457b02afd36e9284d39839d6f85
  sig: Move hashing into algorithm
new public key internal APIs use this rather differently.

So far the difference has been nugatory, because there's only rsa1.
But we should change the documentation.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Remove a spurious \n in a message
Ian Jackson [Sat, 16 Nov 2019 21:18:47 +0000 (21:18 +0000)]
site: Remove a spurious \n in a message

Once again.  I really oughtn't to have done this, but there is much
code in secnet which sets a bad example.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Reserve <peer-keys>~tmp for make-secnet-sites
Ian Jackson [Sat, 16 Nov 2019 11:30:08 +0000 (11:30 +0000)]
site: Reserve <peer-keys>~tmp for make-secnet-sites

We don't use this yet, but make-secnet-sites will do so, later.
So reserve it now.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: key update soundness argument: deal with concurrency
Ian Jackson [Thu, 31 Oct 2019 00:33:44 +0000 (00:33 +0000)]
site: key update soundness argument: deal with concurrency

This completes this argument.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Write an argument for the soundness of key file update
Ian Jackson [Thu, 28 Nov 2019 13:26:03 +0000 (13:26 +0000)]
site: Write an argument for the soundness of key file update

This argument is not yet in its final form.  There are two further
commits which come along in a moment.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Update peer keys from ~update file
Ian Jackson [Tue, 8 Oct 2019 23:04:54 +0000 (00:04 +0100)]
site: Update peer keys from ~update file

We use the pathprefix_template facility for our public key set files.

Right now we document this behaviour in a comment in site.c, which is
the wrong place really.  We'll move it out later.

This commit introduces one spurious \n in a message, which will be
tidied up later.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Read public peer keys from key file
Ian Jackson [Sat, 7 Dec 2019 18:21:11 +0000 (18:21 +0000)]
site: Read public peer keys from key file

Instead of a sigpubkey_if, we maintain a peer_keyset for the peer.

We try to get this from the new "peer-keys" configuration key which
specifies a file (to be parsed with the parser pubkeys.fl.pl).
Failing that we fall back to the old "key" (for key id 0000000000).

We actually keep up to two peer_keysets, because we don't want the set
to change during the middle of a key exchange.  (In the future, peer
keysets might change during operation.)  We make a "copy" (actually a
reference) at the start of key exchange.

We advertise the keyids we will accept in our MSG2/MSG3.  We expect
the peer to state in their MSG3/MSG4 which key they have actually
signed the message with.

This commit has a bug: it never calls sethash.  Our only algorithm
right now is rsa1 and needs sethash.  So attempts to use this will
segfault.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Be able to use multiple private keys
Ian Jackson [Sat, 7 Dec 2019 18:17:05 +0000 (18:17 +0000)]
site: Be able to use multiple private keys

Replace the single permanent sigprivkey_if with a reference to a
private key cache, privcache_if.  (We retain the old single privkey
variable as privkey_fixed, and set that if the cache is not
specified.)

When processing MSG1/MSG2, we hope the peer told us the keyids, of up
to MAX_SIG_KEYS, that it will accept.

When generating MSG3/MSG4, we feed those keyids to the cache to see if
we have any of them.  If not we log a message with the wanted keyids.

We have to provide type_is_msg23 and keyid_zero.

(The corresponding other half of this protocol is in the next commit.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Introduce `pubkey' variable (twice)
Ian Jackson [Sat, 7 Dec 2019 18:20:54 +0000 (18:20 +0000)]
site: Introduce `pubkey' variable (twice)

No functional change, but this will make a forthcoming commit easier
to read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: generate_msg: Introduce `privkey' variable
Ian Jackson [Sat, 7 Dec 2019 18:15:42 +0000 (18:15 +0000)]
site: generate_msg: Introduce `privkey' variable

No functional change, but this will make a forthcoming commit easier
to read.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoNOTES: Add protocol elements for public key negotiation
Ian Jackson [Sun, 29 Sep 2019 10:07:53 +0000 (11:07 +0100)]
NOTES: Add protocol elements for public key negotiation

There is no implementation of this yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Move declaration/initialisation of `hash'
Ian Jackson [Tue, 8 Oct 2019 18:44:41 +0000 (19:44 +0100)]
site: Move declaration/initialisation of `hash'

We are going to want this a bit sooner.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: Introduce SETUP_SETHASH
Ian Jackson [Sat, 5 Oct 2019 10:15:22 +0000 (11:15 +0100)]
site: Introduce SETUP_SETHASH

This seems like overkill but this repetition will get worse later, so
eliminate it now.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agosite: New SIGKEYS log class, at level INFO, enabled by default
Ian Jackson [Sun, 29 Sep 2019 22:41:58 +0000 (23:41 +0100)]
site: New SIGKEYS log class, at level INFO, enabled by default

Nothing uses this yet, but we are going to log information about
which signing keys we are using (both as signer and relier).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: Reorganise private key loading
Ian Jackson [Wed, 4 Dec 2019 13:57:09 +0000 (13:57 +0000)]
privcache: Reorganise private key loading

Now that we only call one sigscheme's entry point, we should
restructure this so it doesn't look like we call scheme->loadpriv in a
loop.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Drop `unsup' parameter to load_err, verror, etc.
Ian Jackson [Wed, 4 Dec 2019 13:51:25 +0000 (13:51 +0000)]
rsa: Drop `unsup' parameter to load_err, verror, etc.

We do not tread `unsupported' differently, now.
All call sites pass 0.  So delete this unused parameter.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agopriv-cache etc.: private key algorithm is specified in key id
Ian Jackson [Mon, 2 Dec 2019 13:08:35 +0000 (13:08 +0000)]
priv-cache etc.: private key algorithm is specified in key id

The idea that we would try various different algorithms to see who
could load a private key was a remnant of a previous design of key id
system.  The actually implemnted arrangements identify the algorithm
in the key id, so there is no need for probing.

In this commit we fix the spec, and change the calling convention for
loadpriv.  Now that we only call loadpriv once, it is allowed to
modify the buffer contents (although nothing makes use of this
relaxation right now).

We change loadpriv's one call site in privcache.c and its (currently
only) implementation, in rsa.c.

In privcache, the error message now definitely means that the algid
was unrecognised, so change it.

In rsa.c we make the log level M_ERR unconditionally (although in fact
verror_tryload now always gets unsup==0).  We delete the now-unused
LDUNSUP from rsa.c, but there is some more intrusive refactoring to do
next to tidy up now-unused stuff.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Strip a couple of spurious newlines from pub key messages
Ian Jackson [Sat, 23 Nov 2019 23:38:58 +0000 (23:38 +0000)]
rsa: Strip a couple of spurious newlines from pub key messages

Neither cfgfatal nor slilog want a trailing newline.

There are lots of this kind of problem in secnet.  I'm just fixing two
I noticed here, in code I touched.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Provide rsa1_loadpub and therefore rsa1 sigscheme
Ian Jackson [Sat, 23 Nov 2019 17:21:00 +0000 (17:21 +0000)]
rsa: Provide rsa1_loadpub and therefore rsa1 sigscheme

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: loadpriv: Use FREE
Ian Jackson [Sat, 23 Nov 2019 17:16:19 +0000 (17:16 +0000)]
rsa: loadpriv: Use FREE

This is a tiny cleanup.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: LDPUBFATAL: Move & before lc into callers
Ian Jackson [Sat, 23 Nov 2019 17:07:11 +0000 (17:07 +0000)]
rsa: LDPUBFATAL: Move & before lc into callers

We are going to want to add a new call site that passes 0.

And format it nicely.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: rsa_loadpub_core: Make it take a load_ctx and use load_err
Ian Jackson [Sat, 7 Dec 2019 11:33:45 +0000 (11:33 +0000)]
rsa: rsa_loadpub_core: Make it take a load_ctx and use load_err

Error handling goes via verror.

Now rsa_loadpub_core is ready to provide the non-fatal rsa1_loadpub
interface.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: rsapub_dispose: Use RSAPUB_CLEAR_ST_BN
Ian Jackson [Sat, 23 Nov 2019 14:11:59 +0000 (14:11 +0000)]
rsa: rsapub_dispose: Use RSAPUB_CLEAR_ST_BN

This is a small cleanup.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: rsapub_dispose: Make passing 0 OK
Ian Jackson [Sat, 23 Nov 2019 14:11:37 +0000 (14:11 +0000)]
rsa: rsapub_dispose: Make passing 0 OK

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: De-indirect a lot of `loc's
Ian Jackson [Sat, 23 Nov 2019 14:05:32 +0000 (14:05 +0000)]
rsa: De-indirect a lot of `loc's

These were at some point intended to be possibly-null, but they aren't
now, so make them values not pointers.  This way we know they're not
null, indeed.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Move load_err earlier
Ian Jackson [Sat, 23 Nov 2019 14:02:06 +0000 (14:02 +0000)]
rsa: Move load_err earlier

Code motion.  We're going to want to use this for public keys.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Pass an additional maybe_loc to load_err
Ian Jackson [Sat, 23 Nov 2019 13:55:56 +0000 (13:55 +0000)]
rsa: Pass an additional maybe_loc to load_err

Use it instead of l->loc if it is non-0.  But it isn't, yet, so no
functional change.

This will allow us to use load_err for handling errors in loadpub,
without regressing the error reporting: the individual bignums have
individual locs.  (Perhaps retaining this is gold-plating, but it is
not particularly hard.)

Rename the function to keep the table within 80 columns.

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