forked from tobez/validns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for CAA (unfinished).
- Loading branch information
Showing
4 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Part of DNS zone file validator `validns`. | ||
* | ||
* Copyright 2011-2017 Anton Berezin <tobez@tobez.org> | ||
* Modified BSD license. | ||
* (See LICENSE file in the distribution.) | ||
* | ||
*/ | ||
#include <sys/types.h> | ||
#include <stdio.h> | ||
#include <netinet/in.h> | ||
#include <arpa/inet.h> | ||
|
||
#include "common.h" | ||
#include "textparse.h" | ||
#include "mempool.h" | ||
#include "carp.h" | ||
#include "rr.h" | ||
|
||
static struct rr* caa_parse(char *name, long ttl, int type, char *s) | ||
{ | ||
struct rr_caa *rr = getmem(sizeof(*rr)); | ||
int algorithm, fp_type; | ||
|
||
algorithm = extract_integer(&s, "algorithm", NULL); | ||
if (algorithm < 0) return NULL; | ||
if (algorithm != 1 && algorithm != 2 && algorithm != 3 && algorithm != 4) | ||
return bitch("unsupported algorithm"); | ||
rr->algorithm = algorithm; | ||
|
||
fp_type = extract_integer(&s, "fp type", NULL); | ||
if (fp_type < 0) return NULL; | ||
if (fp_type != 1 && fp_type != 2) | ||
return bitch("unsupported fp_type"); | ||
rr->fp_type = fp_type; | ||
|
||
rr->fingerprint = extract_hex_binary_data(&s, "fingerprint", EXTRACT_EAT_WHITESPACE); | ||
if (rr->fingerprint.length < 0) return NULL; | ||
|
||
if (rr->fp_type == 1 && rr->fingerprint.length != SHA1_BYTES) { | ||
return bitch("wrong SHA-1 fingerprint length: %d bytes found, %d bytes expected", | ||
rr->fingerprint.length, SHA1_BYTES); | ||
} | ||
if (rr->fp_type == 2 && rr->fingerprint.length != SHA256_BYTES) { | ||
return bitch("wrong SHA-256 fingerprint length: %d bytes found, %d bytes expected", | ||
rr->fingerprint.length, SHA256_BYTES); | ||
} | ||
|
||
if (*s) { | ||
return bitch("garbage after valid SSHFP data"); | ||
} | ||
return store_record(type, name, ttl, rr); | ||
} | ||
|
||
static char* caa_human(struct rr *rrv) | ||
{ | ||
RRCAST(caa); | ||
char ss[4096]; | ||
char *s = ss; | ||
int l; | ||
int i; | ||
|
||
l = snprintf(s, 4096, "%u %u ", rr->algorithm, rr->fp_type); | ||
s += l; | ||
for (i = 0; i < rr->fingerprint.length; i++) { | ||
l = snprintf(s, 4096-(s-ss), "%02X", (unsigned char)rr->fingerprint.data[i]); | ||
s += l; | ||
} | ||
return quickstrdup_temp(ss); | ||
} | ||
|
||
static struct binary_data caa_wirerdata(struct rr *rrv) | ||
{ | ||
RRCAST(caa); | ||
|
||
return compose_binary_data("11d", 1, | ||
rr->algorithm, rr->fp_type, | ||
rr->fingerprint); | ||
} | ||
|
||
struct rr_methods caa_methods = { caa_parse, caa_human, caa_wirerdata, NULL, NULL }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters