summaryrefslogtreecommitdiff
path: root/src/dnstlsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dnstlsa.c')
-rw-r--r--src/dnstlsa.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/dnstlsa.c b/src/dnstlsa.c
new file mode 100644
index 0000000..9871fff
--- /dev/null
+++ b/src/dnstlsa.c
@@ -0,0 +1,96 @@
+#include <unistd.h>
+#include "buffer.h"
+#include "stralloc.h"
+#include "dnsresolv.h"
+#include "dns.h"
+#include "exit.h"
+#include "logmsg.h"
+#include "getoptb.h"
+#include "str.h"
+#include "byte.h"
+
+#define WHO "dnstlsa"
+
+static stralloc cn = {0};
+static stralloc sa = {0};
+static stralloc out = {0};
+
+int main(int argc,char **argv)
+{
+ int r;
+ uint16 usage;
+ uint16 selector;
+ uint16 type;
+ char *port = "25";
+ char proto[7] = "._tcp.";
+ char *host;
+ unsigned char ch;
+ int opt;
+ int i, j, k;
+ int verbose = 0;
+
+ if (!argv[1])
+ logmsg(WHO,100,USAGE,"dnstlsa [-v] [-p port] [-u(dp)|-t(cp)] host (tcp on port 25 is default)" );
+
+ while ((opt = getopt(argc,argv,"vutp:")) != opteof) {
+ switch (opt) {
+ case 'p': port = optarg; break;
+ case 't': break;
+ case 'u': str_copy(proto,"._udp."); break;
+ case 'v': verbose = 1;
+ }
+ }
+ if (optind < argc)
+ host = argv[optind++];
+
+ if (!stralloc_copyb(&sa, "_",1)) logmsg(WHO,111,FATAL,"out of memory");
+ if (!stralloc_cats(&sa,port)) logmsg(WHO,111,FATAL,"out of memory");
+ if (!stralloc_cats(&sa,proto)) logmsg(WHO,111,FATAL,"out of memory");
+ if (!stralloc_cats(&sa,host)) logmsg(WHO,111,FATAL,"out of memory");
+
+ DNS_INIT
+ if (dns_cname(&cn,&sa) > 0)
+ { if ((r = dns_tlsa(&out,&cn)) < 0) _exit(1); }
+ else
+ if ((r = dns_tlsa(&out,&sa)) < 0) _exit(1);
+ if (!stralloc_0(&sa)) logmsg(WHO,111,FATAL,"out of memory");
+ if (verbose) logmsg(WHO,0,INFO,B("checking for TLSA records: ",sa.s,"\n"));
+
+ if (r > 0 && out.len > 4) {
+ for (i = 0; i <= out.len; i++) {
+ usage = (unsigned char) out.s[i];
+ selector = (unsigned char) out.s[i + 1];
+ type = (unsigned char) out.s[i + 2];
+
+ if (usage == 0) buffer_puts(buffer_1,"Usage: [0], ");
+ if (usage == 1) buffer_puts(buffer_1,"Usage: [1], ");
+ if (usage == 2) buffer_puts(buffer_1,"Usage: [2], ");
+ if (usage == 3) buffer_puts(buffer_1,"Usage: [3], ");
+
+ if (selector == 0) buffer_puts(buffer_1,"Selector: [0], ");
+ if (selector == 1) buffer_puts(buffer_1,"Selector: [1], ");
+
+ if (type == 0) buffer_puts(buffer_1,"Type: [0] "); // full cert
+ if (type == 1) buffer_puts(buffer_1,"Type: [1] "); // sha256
+ if (type == 2) buffer_puts(buffer_1,"Type: [2] "); // sha512
+
+ /* Staff of Ra
+ "(is) six kadams high." However, the builder (h)as
+ to subtract one kadam out of respect for the Hebrew God. */
+
+ for (j = i + 3, k = 0; j <= out.len; ++j) {
+ ch = (unsigned char) out.s[j];
+ if ((type == 1 && k == 32) || (type == 2 && k == 64)) {
+ buffer_putsflush(buffer_1,"\n");
+ i = j - 1; break;
+ } else {
+ buffer_put(buffer_1,"0123456789abcdef" + (ch >> 4),1);
+ buffer_put(buffer_1,"0123456789abcdef" + (ch & 0x0f),1);
+ k++;
+ }
+ }
+ }
+ }
+
+ _exit(0);
+}