]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/tsig-tests.cc
dnsdist: Add HTTPStatusAction to return a specific HTTP response
[thirdparty/pdns.git] / pdns / tsig-tests.cc
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 #include "dnsparser.hh"
5 #include "dnswriter.hh"
6 #include "sstuff.hh"
7 #include "misc.hh"
8 #include "dnswriter.hh"
9 #include "dnsrecords.hh"
10 #include "statbag.hh"
11 #include "digests.hh"
12 #include "base64.hh"
13 #include "dnssecinfra.hh"
14 #include "resolver.hh"
15 #include "arguments.hh"
16 #include "dns_random.hh"
17
18 StatBag S;
19
20 ArgvMap& arg()
21 {
22 static ArgvMap theArg;
23 return theArg;
24 }
25
26 int main(int argc, char** argv)
27 try
28 {
29 ::arg().set("query-local-address","Source IP address for sending queries")="0.0.0.0";
30 ::arg().set("query-local-address6","Source IPv6 address for sending queries")="::";
31
32 reportAllTypes();
33
34 if(argc < 4) {
35 cerr<<"tsig-tests: ask a TSIG signed question, verify the TSIG signed answer"<<endl;
36 cerr<<"Syntax: tsig IP-address port question question-type\n";
37 exit(EXIT_FAILURE);
38 }
39
40 vector<uint8_t> packet;
41
42 DNSPacketWriter pw(packet, DNSName(argv[3]), DNSRecordContent::TypeToNumber(argv[4]));
43
44 pw.getHeader()->id=htons(0x4831);
45
46 string key;
47 B64Decode("Syq9L9WrBWdxBC+HxKok2g==", key);
48
49 DNSName keyname("pdns-b-aa");
50
51 TSIGRecordContent trc;
52 trc.d_algoName=DNSName("hmac-md5.sig-alg.reg.int");
53 trc.d_time=time(0);
54 trc.d_fudge=300;
55 trc.d_origID=ntohs(pw.getHeader()->id);
56 trc.d_eRcode=0;
57
58 addTSIG(pw, trc, keyname, key, "", false);
59
60 Socket sock(AF_INET, SOCK_DGRAM);
61 ComboAddress dest(argv[1] + (*argv[1]=='@'), atoi(argv[2]));
62 cerr<<"Keyname: '"<<keyname<<"', algo: '"<<trc.d_algoName<<"', key: '"<<Base64Encode(key)<<"'\n";
63 TSIGTriplet tt;
64 tt.name=keyname;
65 tt.algo=DNSName("hmac-md5");
66 tt.secret=key;
67 AXFRRetriever axfr(dest, DNSName("b.aa"), tt);
68 vector<DNSResourceRecord> res;
69 while(axfr.getChunk(res)) {
70 }
71 return 0;
72 }
73 catch(std::exception &e)
74 {
75 cerr<<"Fatal: "<<e.what()<<endl;
76 return 1;
77 }
78 catch(PDNSException& ae)
79 {
80 cerr<<"Fatal 2: "<<ae.reason<<endl;
81 return 1;
82 }