struct hash_if *defhash;
};
+static struct sigprivkey_if *uncached_load_file(
+ const struct sigscheme_info *scheme,
+ const char *path,
+ struct buffer_if *databuf,
+ struct hash_if *defhash,
+ struct log_if *log);
+
static struct sigprivkey_if *uncached_get(struct privcache *st,
const struct sigkeyid *id, struct log_if *log)
{
- bool_t ok=False;
- FILE *f=0;
-
sprintf(st->path.write_here, SIGKEYID_PR_FMT, SIGKEYID_PR_VAL(id));
const char *path=st->path.buffer;
- struct hash_if *defhash=st->defhash;
- struct buffer_if *databuf=&st->databuf;
+ const struct sigscheme_info *scheme;
+ for (scheme=sigschemes;
+ scheme->name;
+ scheme++)
+ if (scheme->algid == id->b[GRPIDSZ])
+ goto found;
+
+ slilog(log,M_ERR,"private key file %s not loaded (unknown algid)",
+ path);
+ return 0;
+
+ found:
+ return uncached_load_file(scheme,
+ path,
+ &st->databuf,
+ st->defhash,
+ log);
+}
+
+static struct sigprivkey_if *uncached_load_file(
+ const struct sigscheme_info *scheme,
+ const char *path,
+ struct buffer_if *databuf,
+ struct hash_if *defhash,
+ struct log_if *log)
+{
+ bool_t ok=False;
+ FILE *f=0;
+ struct sigprivkey_if *sigpriv=0;
f = fopen(path,"rb");
if (!f) {
slilog(log,M_ERR,"failed to open private key file %s",
path);
}
- goto out;
+ goto error_out;
}
setbuf(f,0);
if (ferror(f)) {
slilog(log,M_ERR,"failed to read private-key file %s",
path);
- goto out;
+ goto error_out;
}
if (!feof(f)) {
slilog(log,M_ERR,"private key file %s longer than max %d",
path, (int)databuf->alloclen);
- goto out;
+ goto error_out;
}
fclose(f); f=0;
- struct sigprivkey_if *sigpriv=0;
- const struct sigscheme_info *scheme;
- for (scheme=sigschemes;
- scheme->name;
- scheme++)
- if (scheme->algid == id->b[GRPIDSZ])
- goto found;
-
- slilog(log,M_ERR,"private key file %s not loaded (unknown algid)",
- path);
- goto out;
-
- found:
databuf->start=databuf->base;
databuf->size=got;
struct cloc loc = { .file=path, .line=0 };
ok=scheme->loadpriv(scheme, databuf, &sigpriv, log, loc);
- if (!ok) goto out; /* loadpriv will have logged */
+ if (!ok) goto error_out; /* loadpriv will have logged */
if (sigpriv->sethash) {
if (!defhash) {
slilog(log,M_ERR,
"private key %s requires `hash' config key for privcache to load",
path);
- sigpriv->dispose(sigpriv->st);
- sigpriv=0;
- goto out;
+ goto error_out;
}
sigpriv->sethash(sigpriv->st,defhash);
}
out:
if (f) fclose(f);
return ok ? sigpriv : 0;
+
+ error_out:
+ if (sigpriv) sigpriv->dispose(sigpriv->st);
+ ok=False;
+ goto out;
}
static struct sigprivkey_if *privcache_lookup(void *sst,