chiark / gitweb /
secnet.git
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>
4 years agorsa: Prepare rsa_loadpub_core for failure.
Ian Jackson [Sat, 23 Nov 2019 13:42:05 +0000 (13:42 +0000)]
rsa: Prepare rsa_loadpub_core for failure.

Now the whole of st is initialised, at least well enough for dispose.
We provide an error_out section which does so.

Nothing uses it yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Provide RSAPUB_INIT_ST_BN and _CLEAR_
Ian Jackson [Sat, 23 Nov 2019 14:14:31 +0000 (14:14 +0000)]
rsa: Provide RSAPUB_INIT_ST_BN and _CLEAR_

We are going to use these soon.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Introduce LDPUBFATAL
Ian Jackson [Sat, 23 Nov 2019 13:37:01 +0000 (13:37 +0000)]
rsa: Introduce LDPUBFATAL

Error handling, and thus the implementation, is going to change.
So move bring it into a common place.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Break out rsa_loadpub_core
Ian Jackson [Sat, 23 Nov 2019 13:25:01 +0000 (13:25 +0000)]
rsa: Break out rsa_loadpub_core

This involves some faff:

We provide macros for helping define and call loadpub_core.
We split RSAPUB_LOADCORE_DEFBN out of RSAPUB_APPLY_GETBN.
RSAPUB_APPLY_GETBN is reworked to do the missing parameter
check first, which lets us introduce e_loc and n_loc.

A side effect is that when we complain about "implausibly large" we
mention the specific rather than general loc.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Introduce RSAPUB_BNS and RSAPUB_APPLY_GETBN
Ian Jackson [Sat, 23 Nov 2019 13:11:57 +0000 (13:11 +0000)]
rsa: Introduce RSAPUB_BNS and RSAPUB_APPLY_GETBN

No functional change except to messages, which now all use the same
words to describe the same thing (!)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Move FREE macro up
Ian Jackson [Sat, 23 Nov 2019 13:49:22 +0000 (13:49 +0000)]
rsa: Move FREE macro up

The public key half of this file is going to want this too.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: sharing load_ctx: Introduce what
Ian Jackson [Sat, 23 Nov 2019 12:50:47 +0000 (12:50 +0000)]
rsa: sharing load_ctx: Introduce what

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agoprivcache: Pass a cloc to loadpriv and use it
Ian Jackson [Sat, 23 Nov 2019 12:26:46 +0000 (12:26 +0000)]
privcache: Pass a cloc to loadpriv and use it

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: sharing load_ctx: Move loc into common part
Ian Jackson [Sat, 23 Nov 2019 11:21:58 +0000 (11:21 +0000)]
rsa: sharing load_ctx: Move loc into common part

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: sharing load_ctx: Rename load_ctx
Ian Jackson [Sat, 23 Nov 2019 11:19:03 +0000 (11:19 +0000)]
rsa: sharing load_ctx: Rename load_ctx

Drop `rsapriv_'.  `rsa' is implied by the file we are in and `priv' is
going to become false.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: sharing load_ctx: Code motion
Ian Jackson [Sat, 23 Nov 2019 11:16:06 +0000 (11:16 +0000)]
rsa: sharing load_ctx: Code motion

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa: Do not do validity checks at runtime (in privcache load)
Ian Jackson [Sat, 19 Oct 2019 22:23:18 +0000 (23:23 +0100)]
rsa: Do not do validity checks at runtime (in privcache load)

These will slow things down and you really ought not to have a broken
private key file.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: Provide rsa1_loadpriv function
Ian Jackson [Sun, 6 Oct 2019 21:56:08 +0000 (22:56 +0100)]
rsa1: Provide rsa1_loadpriv function

We use the rsapriv_load_ctx infrastructure to provide a key loading
function suiting the scheme loadpriv interface.

I chose to use fmemopen because it is convenient.  We have an
autoconf-based portability fixup for eg BSDs (i.e., an implementation
in terms of funopen).

This is going to go in the schemes table.  It is not hooked in yet, so
won't be called.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: Drop filename from two error messages
Ian Jackson [Sun, 6 Oct 2019 22:14:48 +0000 (23:14 +0100)]
rsa1: Drop filename from two error messages

The scheme loading interface doesn't provide the filename (and it will
handle logging it if need be).  For the rsapriv_apply closure, the
config location will allow one to find the filename which seems
sufficient to me.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: Indirect postreadcheck via the context
Ian Jackson [Sun, 6 Oct 2019 22:08:01 +0000 (23:08 +0100)]
rsa1: Indirect postreadcheck via the context

Move this error check out of the keyfile_get_NN functions into the
KEYFILE_GET macro.  The macro uses a helper function from the context,
which can now cause the function to return early.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: Wrap calls to keyfile_get* in a macro
Ian Jackson [Sun, 6 Oct 2019 21:59:51 +0000 (22:59 +0100)]
rsa1: Wrap calls to keyfile_get* in a macro

This will allow us to factor out the error handling into a common
place.

We rename the two functions to 16 and 32, so we will be able to
generate type names if we want.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: rsa_loadpriv_core: Introduce rsapriv_load_ctx
Ian Jackson [Sun, 6 Oct 2019 20:42:10 +0000 (21:42 +0100)]
rsa1: rsa_loadpriv_core: Introduce rsapriv_load_ctx

Make the LD* macros call a new function load_error, and `goto
error_out'.

We must add a call to rsapriv_dispose on the error_out path so that
rsapriv_load_core now always frees everything at every LD* point - so
now this is OK from a memory management pov.

load_error calls a hook function verror.  This is going to let us
parameterise the way rsapriv_load_core works.

No overall functional change yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: rsa_loadpriv_core: Always free b, and zero things we free
Ian Jackson [Sun, 6 Oct 2019 21:16:01 +0000 (22:16 +0100)]
rsa1: rsa_loadpriv_core: Always free b, and zero things we free

Make the FREE macro zero its argument.  This makes it idempotent.

This means that at the end of the function, and at all points where
LD* is called, b is either from malloc and freeable, or null.  It is
never a free'd pointer.

So we can free it.  This is moving us towards always unconditionally
freeing everything on the exit path, to support non-fatal early
return.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: rsa_loadpriv_core: Make assume_valid do the frees
Ian Jackson [Sun, 6 Oct 2019 21:12:06 +0000 (22:12 +0100)]
rsa1: rsa_loadpriv_core: Make assume_valid do the frees

This regularises the exit path: now we always do these clears.  This
makes the function easier to think about and easier to amend in the
way we're just about to.

There is no overall functional change since these variables are
initialised with mpz_init right at the top, even on the assume_valid
path.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: Move "rsa-private" closure string into LDFATAL etc. macros
Ian Jackson [Sun, 6 Oct 2019 20:45:28 +0000 (21:45 +0100)]
rsa1: Move "rsa-private" closure string into LDFATAL etc. macros

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: Provide dispose functions
Ian Jackson [Sun, 6 Oct 2019 20:35:10 +0000 (21:35 +0100)]
rsa1: Provide dispose functions

This eliminates two xxx's introduced earlier.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: Break rsa_loadpriv_core out of rsapriv_apply
Ian Jackson [Sun, 6 Oct 2019 20:27:36 +0000 (21:27 +0100)]
rsa1: Break rsa_loadpriv_core out of rsapriv_apply

Pure code motion.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: rsapriv_apply: Initialise st mpz's early
Ian Jackson [Sun, 6 Oct 2019 20:15:14 +0000 (21:15 +0100)]
rsa1: rsapriv_apply: Initialise st mpz's early

This will make it easier to support non-fatal early return.

No overall functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: rsapriv_apply: Initialise local mpz's early
Ian Jackson [Sun, 6 Oct 2019 20:13:31 +0000 (21:13 +0100)]
rsa1: rsapriv_apply: Initialise local mpz's early

This will make it easier to support non-fatal early return.

No overall functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agorsa1: rsapriv_apply: Introduce macros for cfgfatal* and free
Ian Jackson [Sun, 6 Oct 2019 20:06:10 +0000 (21:06 +0100)]
rsa1: rsapriv_apply: Introduce macros for cfgfatal* and free

We now make a distinction in rsapriv_apply's body between errors which
mean the file is not an rsa private key file, from other errors.

We replace free with a macro too because we are going to change the
error handling so as to support non-fatal early return.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agopubkeys: Do not mind missing serial
Ian Jackson [Sat, 23 Nov 2019 18:28:41 +0000 (18:28 +0000)]
pubkeys: Do not mind missing serial

That just means 00000000

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
4 years agopubkeys: Better debug logging for syntax errors
Ian Jackson [Sat, 23 Nov 2019 17:46:39 +0000 (17:46 +0000)]
pubkeys: Better debug logging for syntax errors

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