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 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/>.
29 #include <sys/types.h>
33 /* We use TYPE37 instead of CERT since not all nameservers can handle
37 cert_key(const char *name,const char *keyfile)
42 fd=open(keyfile,O_RDONLY);
45 fprintf(stderr,"Cannot open key file %s: %s\n",keyfile,strerror(errno));
49 err=fstat(fd,&statbuf);
52 fprintf(stderr,"Unable to stat key file %s: %s\n",
53 keyfile,strerror(errno));
57 if(statbuf.st_size>65536)
59 fprintf(stderr,"Key %s too large for CERT encoding\n",keyfile);
63 if(statbuf.st_size>16384)
64 fprintf(stderr,"Warning: key file %s is larger than the default"
65 " GnuPG max-cert-size\n",keyfile);
67 printf("%s\tTYPE37\t\\# %u 0003 0000 00 ",
68 name,(unsigned int)statbuf.st_size+5);
73 unsigned char buffer[1024];
75 err=read(fd,buffer,1024);
78 fprintf(stderr,"Unable to read key file %s: %s\n",
79 keyfile,strerror(errno));
84 printf("%02X",buffer[i]);
98 url_key(const char *name,const char *fpr,const char *url)
104 const char *tmp = fpr;
107 if ((*tmp >= 'A' && *tmp <= 'F') ||
108 (*tmp >= 'a' && *tmp <= 'f') ||
109 (*tmp >= '0' && *tmp <= '9'))
113 else if (*tmp != ' ' && *tmp != '\t')
115 fprintf(stderr,"Fingerprint must consist of only hex digits"
116 " and whitespace\n");
125 fprintf(stderr,"Fingerprint must be an even number of characters\n");
139 "Cannot generate a CERT without either a fingerprint or URL\n");
143 printf("%s\tTYPE37\t\\# %d 0006 0000 00 %02X",name,len,fprlen);
164 fprintf(stream,"make-dns-cert\n");
165 fprintf(stream,"\t-f\tfingerprint\n");
166 fprintf(stream,"\t-u\tURL\n");
167 fprintf(stream,"\t-k\tkey file\n");
168 fprintf(stream,"\t-n\tDNS name\n");
172 main(int argc,char *argv[])
175 char *fpr=NULL,*url=NULL,*keyfile=NULL,*name=NULL;
182 else if(argc>1 && strcmp(argv[1],"--version")==0)
184 printf("make-dns-cert (GnuPG) " VERSION "\n");
187 else if(argc>1 && strcmp(argv[1],"--help")==0)
193 while((arg=getopt(argc,argv,"hf:u:k:n:"))!=-1)
220 fprintf(stderr,"No name provided\n");
224 if(keyfile && (fpr || url))
226 fprintf(stderr,"Cannot generate a CERT record with both a keyfile and"
227 " a fingerprint or URL\n");
232 err=cert_key(name,keyfile);
234 err=url_key(name,fpr,url);