chiark / gitweb /
pubkey handling: Call sethash when needed
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 23 Nov 2019 18:29:13 +0000 (18:29 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:51 +0000 (21:56 +0000)
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>
pubkeys.fl.pl
pubkeys.h
site.c

index 226f4ddbd319873e8e3da886cb55b003703d9deb..4c3009107701cb841dda38728e3cb58f965fe07b 100755 (executable)
@@ -161,6 +161,7 @@ struct pubkeyset_context {
     /* filled in during setup: */
     struct cloc loc; /* line is runtime */
     struct log_if *log;
+    struct hash_if *defhash;
     struct buffer_if *data_buf;
     struct peer_keyset *building;
     /* runtime: */
@@ -230,6 +231,13 @@ static struct pubkeyset_context c[1];
     bool_t ok=c->scheme->loadpub(c->scheme,c->data_buf,
                                 &pubkey,c->log,c->loc);
     if (!ok) break;
+    if (pubkey->sethash) {
+       if (!c->defhash) {
+           pubkey->dispose(pubkey->st);
+           DOSKIP("public key requires default hash to load");
+       }
+       pubkey->sethash(pubkey->st,c->defhash);
+    }
     memcpy(c->building->keys[c->building->nkeys].id.b,
           c->grpid,
            GRPIDSZ);
@@ -283,9 +291,11 @@ static struct pubkeyset_context c[1];
 
 extern struct peer_keyset *
 keyset_load(const char *path, struct buffer_if *data_buf,
-           struct log_if *log, int logcl_enoent) {
+           struct log_if *log, int logcl_enoent,
+           struct hash_if *defhash) {
     assert(!c->building);
     c->log=log;
+    c->defhash=defhash;
     c->loc.file=path;
     pkyyin = fopen(path, "r");
     if (!pkyyin) {
index 0901baa5dfe8c3d88dd17d2c8937b7aaa54aa855..782240fcdee850e487a3acddd1299067141973bd 100644 (file)
--- a/pubkeys.h
+++ b/pubkeys.h
@@ -38,7 +38,8 @@ struct peer_keyset {
 
 extern struct peer_keyset *
 keyset_load(const char *path, struct buffer_if *data_buf,
-           struct log_if *log, int logcl_enoent);
+           struct log_if *log, int logcl_enoent,
+           struct hash_if *defhash);
 
 extern void keyset_dispose(struct peer_keyset **ks);
 
diff --git a/site.c b/site.c
index e37c73bee2728f8b3dbe336beedefac8f871f20d..e8b507ff0540fc2302420f0eccbb959897e22072 100644 (file)
--- a/site.c
+++ b/site.c
@@ -903,7 +903,7 @@ static void peerkeys_maybe_incorporate(struct site *st, const char *file,
                                       int logcl_enoent)
 {
     struct peer_keyset *atsuffix=
-       keyset_load(file,&st->scratch,st->log,logcl_enoent);
+       keyset_load(file,&st->scratch,st->log,logcl_enoent,st->defhash);
     if (!atsuffix) return;
 
     if (st->peerkeys_current &&
@@ -2547,7 +2547,8 @@ static list_t *site_apply(closure_t *self, struct cloc loc, dict_t *context,
        pathprefix_template_init(&st->peerkeys_tmpl,st->peerkeys_path,
                                 PEERKEYS_SUFFIX_MAXLEN + 1 /* nul */);
        st->peerkeys_current=keyset_load(st->peerkeys_path,
-                                        &st->scratch,st->log,M_ERR);
+                                        &st->scratch,st->log,M_ERR,
+                                        st->defhash);
        if (fixed_pubkey) {
            fixed_pubkey->dispose(fixed_pubkey->st);
        }