1 /* make-dns-cert.c - An OpenPGP-to-DNS CERT conversion tool
2 * Copyright (C) 2006 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 2 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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
31 #include <sys/types.h>
35 /* We use TYPE37 instead of CERT since not all nameservers can handle
39 cert_key(const char *name
,const char *keyfile
)
44 fd
=open(keyfile
,O_RDONLY
);
47 fprintf(stderr
,"Cannot open key file %s: %s\n",keyfile
,strerror(errno
));
51 err
=fstat(fd
,&statbuf
);
54 fprintf(stderr
,"Unable to stat key file %s: %s\n",
55 keyfile
,strerror(errno
));
59 if(statbuf
.st_size
>65536)
61 fprintf(stderr
,"Key %s too large for CERT encoding\n",keyfile
);
65 if(statbuf
.st_size
>16384)
66 fprintf(stderr
,"Warning: key file %s is larger than the default"
67 " GnuPG max-cert-size\n",keyfile
);
69 printf("%s\tTYPE37\t\\# %u 0003 0000 00 ",
70 name
,(unsigned int)statbuf
.st_size
+5);
75 unsigned char buffer
[1024];
77 err
=read(fd
,buffer
,1024);
80 fprintf(stderr
,"Unable to read key file %s: %s\n",
81 keyfile
,strerror(errno
));
86 printf("%02X",buffer
[i
]);
100 url_key(const char *name
,const char *fpr
,const char *url
)
106 const char *tmp
= fpr
;
109 if ((*tmp
>= 'A' && *tmp
<= 'F') ||
110 (*tmp
>= 'a' && *tmp
<= 'f') ||
111 (*tmp
>= '0' && *tmp
<= '9'))
115 else if (*tmp
!= ' ' && *tmp
!= '\t')
117 fprintf(stderr
,"Fingerprint must consist of only hex digits"
118 " and whitespace\n");
127 fprintf(stderr
,"Fingerprint must be an even number of characters\n");
141 "Cannot generate a CERT without either a fingerprint or URL\n");
145 printf("%s\tTYPE37\t\\# %d 0006 0000 00 %02X",name
,len
,fprlen
);
166 fprintf(stream
,"make-dns-cert\n");
167 fprintf(stream
,"\t-f\tfingerprint\n");
168 fprintf(stream
,"\t-u\tURL\n");
169 fprintf(stream
,"\t-k\tkey file\n");
170 fprintf(stream
,"\t-n\tDNS name\n");
174 main(int argc
,char *argv
[])
177 char *fpr
=NULL
,*url
=NULL
,*keyfile
=NULL
,*name
=NULL
;
184 else if(argc
>1 && strcmp(argv
[1],"--version")==0)
186 printf("make-dns-cert (GnuPG) " VERSION
"\n");
189 else if(argc
>1 && strcmp(argv
[1],"--help")==0)
195 while((arg
=getopt(argc
,argv
,"hf:u:k:n:"))!=-1)
222 fprintf(stderr
,"No name provided\n");
226 if(keyfile
&& (fpr
|| url
))
228 fprintf(stderr
,"Cannot generate a CERT record with both a keyfile and"
229 " a fingerprint or URL\n");
234 err
=cert_key(name
,keyfile
);
236 err
=url_key(name
,fpr
,url
);