X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=privcache.c;h=790281df61fa4e48608fceb7f9335f135a7116db;hb=b65782b25170087bef9556729d7168395770b42b;hp=50da4b5a5611950b637432ba1fc1964aedf83ca8;hpb=c52b7f938b6bd42d73f557b8b07ac9d751add3be;p=secnet.git diff --git a/privcache.c b/privcache.c index 50da4b5..790281d 100644 --- a/privcache.c +++ b/privcache.c @@ -48,10 +48,10 @@ static struct sigprivkey_if *uncached_get(struct privcache *st, f = fopen(st->path.buffer,"rb"); if (!f) { if (errno == ENOENT) { - slilog(log,M_DEBUG,"private key %s not found\n", - st->path.write_here); + slilog(log,M_DEBUG,"private key %s not found", + st->path.buffer); } else { - slilog(log,M_ERR,"failed to open private key file %s\n", + slilog(log,M_ERR,"failed to open private key file %s", st->path.buffer); } goto out; @@ -61,43 +61,48 @@ static struct sigprivkey_if *uncached_get(struct privcache *st, buffer_init(&st->databuf,0); ssize_t got=fread(st->databuf.base,1,st->databuf.alloclen,f); if (ferror(f)) { - slilog(log,M_ERR,"failed to read private-key file %s\n", + slilog(log,M_ERR,"failed to read private-key file %s", st->path.buffer); goto out; } if (!feof(f)) { - slilog(log,M_ERR,"private key file %s longer than max %d\n", + slilog(log,M_ERR,"private key file %s longer than max %d", st->path.buffer, (int)st->databuf.alloclen); goto out; } fclose(f); f=0; struct sigprivkey_if *sigpriv=0; - for (const struct sigscheme_info *scheme=sigschemes; + const struct sigscheme_info *scheme; + for (scheme=sigschemes; scheme->name; - scheme++) { - st->databuf.start=st->databuf.base; - st->databuf.size=got; - ok=scheme->loadpriv(scheme, &st->databuf, &sigpriv, log); - if (ok) { - if (sigpriv->sethash) { - if (!st->defhash) { - slilog(log,M_ERR, + scheme++) + if (scheme->algid == id->b[GRPIDSZ]) + goto found; + + slilog(log,M_ERR,"private key file %s not loaded (unknown algid)", + st->path.buffer); + goto out; + + found: + st->databuf.start=st->databuf.base; + st->databuf.size=got; + struct cloc loc = { .file=st->path.buffer, .line=0 }; + ok=scheme->loadpriv(scheme, &st->databuf, &sigpriv, log, loc); + if (!ok) goto out; /* loadpriv will have logged */ + + if (sigpriv->sethash) { + if (!st->defhash) { + slilog(log,M_ERR, "private key %s requires `hash' config key for privcache to load", - st->path.buffer); - sigpriv->dispose(sigpriv->st); - sigpriv=0; - goto out; - } - sigpriv->sethash(sigpriv->st,st->defhash); - } + st->path.buffer); + sigpriv->dispose(sigpriv->st); + sigpriv=0; goto out; } + sigpriv->sethash(sigpriv->st,st->defhash); } - slilog(log,M_ERR,"private key file %s not loaded (not recognised?)\n", - st->path.buffer); - out: if (f) fclose(f); return ok ? sigpriv : 0;