1 /* make-dns-cert.c - An OpenPGP-to-DNS CERT conversion tool
2 * Copyright (C) 2006, 2008 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
33 #include <sys/types.h>
37 /* We use TYPE37 instead of CERT since not all nameservers can handle
41 cert_key(const char *name
,const char *keyfile
)
46 fd
=open(keyfile
,O_RDONLY
);
49 fprintf(stderr
,"Cannot open key file %s: %s\n",keyfile
,strerror(errno
));
53 err
=fstat(fd
,&statbuf
);
56 fprintf(stderr
,"Unable to stat key file %s: %s\n",
57 keyfile
,strerror(errno
));
61 if(statbuf
.st_size
>65536)
63 fprintf(stderr
,"Key %s too large for CERT encoding\n",keyfile
);
67 if(statbuf
.st_size
>16384)
68 fprintf(stderr
,"Warning: key file %s is larger than the default"
69 " GnuPG max-cert-size\n",keyfile
);
71 printf("%s\tTYPE37\t\\# %u 0003 0000 00 ",
72 name
,(unsigned int)statbuf
.st_size
+5);
77 unsigned char buffer
[1024];
80 err
= read (fd
,buffer
,1024);
81 while (err
== -1 && errno
== EINTR
);
84 fprintf(stderr
,"Unable to read key file %s: %s\n",
85 keyfile
,strerror(errno
));
90 printf("%02X",buffer
[i
]);
104 url_key(const char *name
,const char *fpr
,const char *url
)
110 const char *tmp
= fpr
;
113 if ((*tmp
>= 'A' && *tmp
<= 'F') ||
114 (*tmp
>= 'a' && *tmp
<= 'f') ||
115 (*tmp
>= '0' && *tmp
<= '9'))
119 else if (*tmp
!= ' ' && *tmp
!= '\t')
121 fprintf(stderr
,"Fingerprint must consist of only hex digits"
122 " and whitespace\n");
131 fprintf(stderr
,"Fingerprint must be an even number of characters\n");
145 "Cannot generate a CERT without either a fingerprint or URL\n");
149 printf("%s\tTYPE37\t\\# %d 0006 0000 00 %02X",name
,len
,fprlen
);
170 fprintf(stream
,"make-dns-cert\n");
171 fprintf(stream
,"\t-f\tfingerprint\n");
172 fprintf(stream
,"\t-u\tURL\n");
173 fprintf(stream
,"\t-k\tkey file\n");
174 fprintf(stream
,"\t-n\tDNS name\n");
178 main(int argc
,char *argv
[])
181 char *fpr
=NULL
,*url
=NULL
,*keyfile
=NULL
,*name
=NULL
;
188 else if(argc
>1 && strcmp(argv
[1],"--version")==0)
190 #if defined(HAVE_CONFIG_H) && defined(VERSION)
191 printf ("make-dns-cert (GnuPG) " VERSION
"\n");
193 printf ("make-dns-cert gnupg-svn%d\n", atoi (10+"$Revision$"));
197 else if(argc
>1 && strcmp(argv
[1],"--help")==0)
203 while((arg
=getopt(argc
,argv
,"hf:u:k:n:"))!=-1)
230 fprintf(stderr
,"No name provided\n");
234 if(keyfile
&& (fpr
|| url
))
236 fprintf(stderr
,"Cannot generate a CERT record with both a keyfile and"
237 " a fingerprint or URL\n");
242 err
=cert_key(name
,keyfile
);
244 err
=url_key(name
,fpr
,url
);