Lines Matching refs:dkp
71 dki_t *dkp = malloc (sizeof (dki_t));
73 if ( dkp != NULL )
75 memset (dkp, 0, sizeof (dki_t));
76 return dkp;
84 static int dki_readfile (FILE *fp, dki_t *dkp)
93 assert (dkp != NULL);
110 case 'g': dkp->gentime = timestr2time (val); break;
111 case 'e': dkp->exptime = timestr2time (val); break;
112 case 'l': dkp->lifetime = atoi (val) * DAYSEC; break;
126 if ( strcmp (buf, dkp->name) != 0 )
142 if ( type != 3 || algo != dkp->algo )
146 dkp->flags = flags;
156 dkp->pubkey = strdup (p);
161 static int dki_writeinfo (const dki_t *dkp, const char *path)
165 assert (dkp != NULL);
171 if ( dki_prt_dnskey_raw (dkp, fp) == 0 )
174 touch (path, dkp->time); /* restore time of key file */
179 static int dki_setstat (dki_t *dkp, int status, int preserve_time);
188 void dki_free (dki_t *dkp)
190 assert (dkp != NULL);
192 if ( dkp->pubkey )
193 free (dkp->pubkey);
194 free (dkp);
291 dki_t *dkp;
300 if ( (dkp = dki_alloc ()) == NULL )
318 assert (strlen (dirname)+1 < sizeof (dkp->dname));
319 strcpy (dkp->dname, dirname);
321 assert (strlen (fname)+1 < sizeof (dkp->fname));
322 strcpy (dkp->fname, fname);
324 if ( sscanf (fname, "K%254[^+]+%hd+%d", dkp->name, &dkp->algo, &dkp->tag) != 3 )
331 pathname (path, sizeof (path), dkp->dname, dkp->fname, DKI_KEY_FILEEXT);
341 if ( (err = dki_readfile (fp, dkp)) != 0 )
357 dkp->time = st.st_mtime;
360 pathname (path, sizeof (path), dkp->dname, dkp->fname, DKI_ACT_FILEEXT);
363 if ( dki_isrevoked (dkp) )
364 dkp->status = DKI_REV;
366 dkp->status = DKI_ACT;
370 pathname (path, sizeof (path), dkp->dname, dkp->fname, DKI_PUB_FILEEXT);
372 dkp->status = DKI_PUB;
375 pathname (path, sizeof (path), dkp->dname, dkp->fname, DKI_DEP_FILEEXT);
377 dkp->status = DKI_DEP;
379 dkp->status = DKI_SEP;
387 return dkp;
397 dki_t *dkp;
419 if ( (dkp = dki_read (dir, dentp->d_name)) )
420 dki_add (listp, dkp);
431 int dki_setstatus_preservetime (dki_t *dkp, int status)
433 return dki_setstat (dkp, status, 1);
441 int dki_setstatus (dki_t *dkp, int status)
443 return dki_setstat (dkp, status, 0);
450 static int dki_setstat (dki_t *dkp, int status, int preserve_time)
457 if ( dkp == NULL )
462 switch ( dkp->status ) /* look at old status */
471 pathname (frompath, sizeof (frompath), dkp->dname, dkp->fname, DKI_ACT_FILEEXT);
476 pathname (frompath, sizeof (frompath), dkp->dname, dkp->fname, DKI_DEP_FILEEXT);
481 pathname (frompath, sizeof (frompath), dkp->dname, dkp->fname, DKI_PUB_FILEEXT);
493 if ( status == 'r' || (status == 'a' && dki_isrevoked (dkp)) )
495 pathname (topath, sizeof (topath), dkp->dname, dkp->fname, DKI_KEY_FILEEXT);
498 dki_setflag (dkp, DK_FLAG_REVOKE); /* set REVOKE bit */
500 dki_unsetflag (dkp, DK_FLAG_REVOKE); /* clear REVOKE bit */
503 dki_writeinfo (dkp, topath); /* ..and write it to the key file */
520 pathname (topath, sizeof (topath), dkp->dname, dkp->fname, DKI_ACT_FILEEXT);
523 pathname (topath, sizeof (topath), dkp->dname, dkp->fname, DKI_DEP_FILEEXT);
526 if ( !dki_isksk (dkp) )
531 pathname (topath, sizeof (topath), dkp->dname, dkp->fname, DKI_PUB_FILEEXT);
540 dkp->status = status;
543 pathname (topath, sizeof (topath), dkp->dname, dkp->fname, DKI_KEY_FILEEXT);
557 dki_t *dki_remove (dki_t *dkp)
570 if ( dkp == NULL )
573 strncpy (newfile, dkp->fname, sizeof (newfile));
577 pathname (path, sizeof (path), dkp->dname, dkp->fname, *pext);
580 pathname (newpath, sizeof (newpath), dkp->dname, newfile, *pext);
586 next = dkp->next;
587 dki_free (dkp);
596 dki_t *dki_destroy (dki_t *dkp)
607 if ( dkp == NULL )
612 pathname (path, sizeof (path), dkp->dname, dkp->fname, *pext);
619 next = dkp->next;
620 dki_free (dkp);
679 int dki_prt_dnskey (const dki_t *dkp, FILE *fp)
681 return dki_prt_dnskeyttl (dkp, fp, 0);
687 int dki_prt_dnskeyttl (const dki_t *dkp, FILE *fp, int ttl)
691 if ( dkp == NULL )
694 fprintf (fp, "%s ", dkp->name);
698 fprintf (fp, "%d 3 %d (", dkp->flags, dkp->algo);
700 for ( p = dkp->pubkey; *p ; p++ )
706 if ( dki_isrevoked (dkp) )
707 fprintf (fp, ") ; key id = %u (original key id = %u)", (dkp->tag + 128) % 65535, dkp->tag);
709 fprintf (fp, ") ; key id = %u", dkp->tag);
718 int dki_prt_dnskey_raw (const dki_t *dkp, FILE *fp)
722 if ( dkp == NULL )
725 if ( dkp->gentime )
726 fprintf (fp, ";%%\tgenerationtime=%s\n", time2isostr (dkp->gentime, 's'));
727 if ( (days = dki_lifetimedays (dkp)) )
729 if ( dkp->exptime )
730 fprintf (fp, ";%%\texpirationtime=%s\n", time2isostr (dkp->exptime, 's'));
732 fprintf (fp, "%s ", dkp->name);
738 fprintf (fp, "%d 3 %d ", dkp->flags, dkp->algo);
739 fprintf (fp, "%s\n", dkp->pubkey);
747 int dki_prt_comment (const dki_t *dkp, FILE *fp)
751 if ( dkp == NULL )
753 len += fprintf (fp, "; %s ", dkp->name);
754 len += fprintf (fp, "tag=%u ", dkp->tag);
755 len += fprintf (fp, "algo=%s ", dki_algo2str(dkp->algo));
756 len += fprintf (fp, "generated %s\n", time2str (dkp->time, 's'));
764 int dki_prt_trustedkey (const dki_t *dkp, FILE *fp)
770 if ( dkp == NULL )
772 len += fprintf (fp, "\"%s\" ", dkp->name);
773 spaces = 22 - (strlen (dkp->name) + 3);
775 len += fprintf (fp, "%d 3 %d ", dkp->flags, dkp->algo);
779 for ( p = dkp->pubkey; *p ; p++ )
785 if ( dki_isrevoked (dkp) )
786 len += fprintf (fp, "\" ; # key id = %u (original key id = %u)\n\n", (dkp->tag + 128) % 65535, dkp->tag);
788 len += fprintf (fp, "\" ; # key id = %u\n\n", dkp->tag);
891 time_t dki_algo (const dki_t *dkp)
893 assert (dkp != NULL);
894 return (dkp->algo);
900 time_t dki_time (const dki_t *dkp)
902 assert (dkp != NULL);
903 return (dkp->time);
909 time_t dki_exptime (const dki_t *dkp)
911 assert (dkp != NULL);
912 return (dkp->exptime);
916 ** dki_lifetime (dkp) return the lifetime of the key in sec!
918 time_t dki_lifetime (const dki_t *dkp)
920 assert (dkp != NULL);
921 return (dkp->lifetime);
925 ** dki_lifetimedays (dkp) return the lifetime of the key in days!
927 ushort dki_lifetimedays (const dki_t *dkp)
929 assert (dkp != NULL);
930 return (dkp->lifetime / DAYSEC);
934 ** dki_gentime (dkp) return the generation timestamp of the key
936 time_t dki_gentime (const dki_t *dkp)
938 assert (dkp != NULL);
939 return (dkp->gentime > 0L ? dkp->gentime: dkp->time);
943 ** dki_setlifetime (dkp, int days)
947 ushort dki_setlifetime (dki_t *dkp, int days)
952 assert (dkp != NULL);
954 lifetsec = dkp->lifetime; /* old lifetime */
955 dkp->lifetime = days * DAYSEC; /* set new lifetime */
959 dkp->gentime = dkp->time;
961 pathname (path, sizeof (path), dkp->dname, dkp->fname, DKI_KEY_FILEEXT);
962 dki_writeinfo (dkp, path);
968 ** dki_setexptime (dkp, time_t sec)
972 time_t dki_setexptime (dki_t *dkp, time_t sec)
977 assert (dkp != NULL);
980 oldexptime = dkp->exptime;
981 dkp->exptime = sec;
983 pathname (path, sizeof (path), dkp->dname, dkp->fname, DKI_KEY_FILEEXT);
984 dki_writeinfo (dkp, path);
995 int dki_age (const dki_t *dkp, time_t curr)
997 assert (dkp != NULL);
998 return ((ulong)curr - (ulong)dkp->time);
1004 dk_flag_t dki_getflag (const dki_t *dkp, time_t curr)
1006 return dkp->flags;
1012 dk_flag_t dki_setflag (dki_t *dkp, dk_flag_t flag)
1014 return dkp->flags |= (ushort)flag;
1020 dk_flag_t dki_unsetflag (dki_t *dkp, dk_flag_t flag)
1022 return dkp->flags &= ~((ushort)flag);
1028 int dki_isksk (const dki_t *dkp)
1030 assert (dkp != NULL);
1031 return (dkp->flags & DK_FLAG_KSK) == DK_FLAG_KSK;
1037 int dki_isrevoked (const dki_t *dkp)
1039 assert (dkp != NULL);
1040 return (dkp->flags & DK_FLAG_REVOKE) == DK_FLAG_REVOKE;
1046 int dki_isdepreciated (const dki_t *dkp)
1048 return dki_status (dkp) == DKI_DEPRECIATED;
1054 int dki_isactive (const dki_t *dkp)
1056 return dki_status (dkp) == DKI_ACTIVE;
1062 int dki_ispublished (const dki_t *dkp)
1064 return dki_status (dkp) == DKI_PUBLISHED;
1071 dk_status_t dki_status (const dki_t *dkp)
1073 assert (dkp != NULL);
1074 return (dkp->status);
1080 const char *dki_statusstr (const dki_t *dkp)
1082 assert (dkp != NULL);
1083 switch ( dkp->status )
1086 case DKI_PUB: if ( dki_isksk (dkp) )
1195 const dki_t *dkp;
1199 for ( dkp = list; no > 0 && dkp; dkp = dkp->next )
1200 if ( dki_isksk (dkp) == ksk && dki_status (dkp) == status )
1203 last = dkp;
1215 const dki_t *dkp;
1219 for ( dkp = list; no > 0 && dkp; dkp = dkp->next )
1220 if ( dki_isksk (dkp) == ksk && dki_algo (dkp) == alg &&
1221 dki_status (dkp) == status )
1224 last = dkp;