version 1.1.1.2, 2019/01/09 16:48:17 |
version 1.1.1.3, 2020/05/24 19:36:36 |
|
|
* information regarding copyright ownership. |
* information regarding copyright ownership. |
*/ |
*/ |
|
|
#include <config.h> |
#include <stdarg.h> |
|
|
#include <stdbool.h> |
#include <stdbool.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdarg.h> |
|
|
|
#include <isc/base32.h> |
#include <isc/base32.h> |
#include <isc/buffer.h> |
#include <isc/buffer.h> |
Line 53 fatal(const char *format, ...) { |
|
Line 51 fatal(const char *format, ...) { |
|
|
|
static void |
static void |
check_result(isc_result_t result, const char *message) { |
check_result(isc_result_t result, const char *message) { |
if (result != ISC_R_SUCCESS) |
if (result != ISC_R_SUCCESS) { |
fatal("%s: %s", message, isc_result_totext(result)); |
fatal("%s: %s", message, isc_result_totext(result)); |
|
} |
} |
} |
|
|
static void |
static void |
|
|
exit(1); |
exit(1); |
} |
} |
|
|
typedef void nsec3printer(unsigned algo, unsigned flags, unsigned iters, |
typedef void |
const char *saltstr, const char *domain, |
nsec3printer(unsigned algo, unsigned flags, unsigned iters, const char *saltstr, |
const char *digest); |
const char *domain, const char *digest); |
|
|
static void |
static void |
nsec3hash(nsec3printer *nsec3print, const char *algostr, const char *flagstr, |
nsec3hash(nsec3printer *nsec3print, const char *algostr, const char *flagstr, |
const char *iterstr, const char *saltstr, const char *domain) |
const char *iterstr, const char *saltstr, const char *domain) { |
{ |
|
dns_fixedname_t fixed; |
dns_fixedname_t fixed; |
dns_name_t *name; |
dns_name_t *name; |
isc_buffer_t buffer; |
isc_buffer_t buffer; |
Line 97 nsec3hash(nsec3printer *nsec3print, cons |
|
Line 95 nsec3hash(nsec3printer *nsec3print, cons |
|
result = isc_hex_decodestring(saltstr, &buffer); |
result = isc_hex_decodestring(saltstr, &buffer); |
check_result(result, "isc_hex_decodestring(salt)"); |
check_result(result, "isc_hex_decodestring(salt)"); |
salt_length = isc_buffer_usedlength(&buffer); |
salt_length = isc_buffer_usedlength(&buffer); |
if (salt_length > DNS_NSEC3_SALTSIZE) |
if (salt_length > DNS_NSEC3_SALTSIZE) { |
fatal("salt too long"); |
fatal("salt too long"); |
if (salt_length == 0) |
} |
|
if (salt_length == 0) { |
saltstr = dash; |
saltstr = dash; |
|
} |
} |
} |
hash_alg = atoi(algostr); |
hash_alg = atoi(algostr); |
if (hash_alg > 255U) |
if (hash_alg > 255U) { |
fatal("hash algorithm too large"); |
fatal("hash algorithm too large"); |
|
} |
flags = flagstr == NULL ? 0 : atoi(flagstr); |
flags = flagstr == NULL ? 0 : atoi(flagstr); |
if (flags > 255U) |
if (flags > 255U) { |
fatal("flags too large"); |
fatal("flags too large"); |
|
} |
iterations = atoi(iterstr); |
iterations = atoi(iterstr); |
if (iterations > 0xffffU) |
if (iterations > 0xffffU) { |
fatal("iterations to large"); |
fatal("iterations to large"); |
|
} |
|
|
name = dns_fixedname_initname(&fixed); |
name = dns_fixedname_initname(&fixed); |
isc_buffer_constinit(&buffer, domain, strlen(domain)); |
isc_buffer_constinit(&buffer, domain, strlen(domain)); |
Line 119 nsec3hash(nsec3printer *nsec3print, cons |
|
Line 122 nsec3hash(nsec3printer *nsec3print, cons |
|
check_result(result, "dns_name_fromtext() failed"); |
check_result(result, "dns_name_fromtext() failed"); |
|
|
dns_name_downcase(name, name, NULL); |
dns_name_downcase(name, name, NULL); |
length = isc_iterated_hash(hash, hash_alg, iterations, salt, |
length = isc_iterated_hash(hash, hash_alg, iterations, salt, |
salt_length, name->ndata, name->length); |
salt_length, name->ndata, name->length); |
if (length == 0) |
if (length == 0) { |
fatal("isc_iterated_hash failed"); |
fatal("isc_iterated_hash failed"); |
|
} |
region.base = hash; |
region.base = hash; |
region.length = length; |
region.length = length; |
isc_buffer_init(&buffer, text, sizeof(text)); |
isc_buffer_init(&buffer, text, sizeof(text)); |
Line 134 nsec3hash(nsec3printer *nsec3print, cons |
|
Line 138 nsec3hash(nsec3printer *nsec3print, cons |
|
|
|
static void |
static void |
nsec3hash_print(unsigned algo, unsigned flags, unsigned iters, |
nsec3hash_print(unsigned algo, unsigned flags, unsigned iters, |
const char *saltstr, const char *domain, const char *digest) |
const char *saltstr, const char *domain, const char *digest) { |
{ |
|
UNUSED(flags); |
UNUSED(flags); |
UNUSED(domain); |
UNUSED(domain); |
|
|
fprintf(stdout, "%s (salt=%s, hash=%u, iterations=%u)\n", |
fprintf(stdout, "%s (salt=%s, hash=%u, iterations=%u)\n", digest, |
digest, saltstr, algo, iters); |
saltstr, algo, iters); |
} |
} |
|
|
static void |
static void |
nsec3hash_rdata_print(unsigned algo, unsigned flags, unsigned iters, |
nsec3hash_rdata_print(unsigned algo, unsigned flags, unsigned iters, |
const char *saltstr, const char *domain, |
const char *saltstr, const char *domain, |
const char *digest) |
const char *digest) { |
{ |
fprintf(stdout, "%s NSEC3 %u %u %u %s %s\n", domain, algo, flags, iters, |
fprintf(stdout, "%s NSEC3 %u %u %u %s %s\n", |
saltstr, digest); |
domain, algo, flags, iters, saltstr, digest); |
|
} |
} |
|
|
int |
int |
Line 170 main(int argc, char *argv[]) { |
|
Line 172 main(int argc, char *argv[]) { |
|
} |
} |
} |
} |
|
|
skip: |
skip: |
argc -= isc_commandline_index; |
argc -= isc_commandline_index; |
argv += isc_commandline_index; |
argv += isc_commandline_index; |
|
|
Line 178 main(int argc, char *argv[]) { |
|
Line 180 main(int argc, char *argv[]) { |
|
if (argc != 5) { |
if (argc != 5) { |
usage(); |
usage(); |
} |
} |
nsec3hash(nsec3hash_rdata_print, |
nsec3hash(nsec3hash_rdata_print, argv[0], argv[1], argv[2], |
argv[0], argv[1], argv[2], argv[3], argv[4]); |
argv[3], argv[4]); |
} else { |
} else { |
if (argc != 4) { |
if (argc != 4) { |
usage(); |
usage(); |
} |
} |
nsec3hash(nsec3hash_print, |
nsec3hash(nsec3hash_print, argv[1], NULL, argv[2], argv[0], |
argv[1], NULL, argv[2], argv[0], argv[3]); |
argv[3]); |
} |
} |
return(0); |
return (0); |
} |
} |