chiark / gitweb /
rsa: Drop `unsup' parameter to load_err, verror, etc.
[secnet.git] / privcache.c
index 0ad6a0eb8ca1912dfba9d2dcb41810b47ea54015..b8dc2adee323ce23b2625ac6fe9a313901d0b388 100644 (file)
@@ -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,12 +61,12 @@ 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;
     }
@@ -76,9 +76,13 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
     for (const struct sigscheme_info *scheme=sigschemes;
         scheme->name;
         scheme++) {
+       if (scheme->algid != id->b[GRPIDSZ])
+           continue;
+
        st->databuf.start=st->databuf.base;
        st->databuf.size=got;
-       ok=scheme->loadpriv(scheme, &st->databuf, &sigpriv, log);
+       struct cloc loc = { .file=st->path.buffer, .line=0 };
+       ok=scheme->loadpriv(scheme, &st->databuf, &sigpriv, log, loc);
        if (ok) {
            if (sigpriv->sethash) {
                if (!st->defhash) {
@@ -93,9 +97,11 @@ static struct sigprivkey_if *uncached_get(struct privcache *st,
            }
            goto out;
        }
+       /* loadpriv will have logged */
+       goto out;
     }
 
-    slilog(log,M_ERR,"private key file %s not loaded (not recognised?)\n",
+    slilog(log,M_ERR,"private key file %s not loaded (unknown algid)",
           st->path.buffer);
 
   out:
@@ -171,10 +177,7 @@ static list_t *privcache_apply(closure_t *self, struct cloc loc,
     buffer_new(&st->databuf,buflen+1);
 
     const char *path=dict_read_string(dict,"privkeys",True,"privcache",loc);
-    int l=strlen(path);
-    NEW_ARY(st->path.buffer,l+KEYIDSZ*2+1);
-    strcpy(st->path.buffer,path);
-    st->path.write_here=st->path.buffer+l;
+    pathprefix_template_init(&st->path,path,KEYIDSZ*2);
 
     st->defhash=find_cl_if(dict,"hash",CL_HASH,False,"site",loc);