2012-06-25 13:57:32 +10:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2012-06-25 13:57:32 +10:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2012-06-25 13:57:32 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <isc/app.h>
|
|
|
|
#include <isc/base32.h>
|
|
|
|
#include <isc/commandline.h>
|
|
|
|
#include <isc/event.h>
|
|
|
|
#include <isc/file.h>
|
|
|
|
#include <isc/hash.h>
|
|
|
|
#include <isc/hex.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/mutex.h>
|
|
|
|
#include <isc/os.h>
|
|
|
|
#include <isc/print.h>
|
|
|
|
#include <isc/random.h>
|
|
|
|
#include <isc/rwlock.h>
|
|
|
|
#include <isc/serial.h>
|
|
|
|
#include <isc/stdio.h>
|
|
|
|
#include <isc/stdlib.h>
|
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/time.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
#include <dns/db.h>
|
|
|
|
#include <dns/dbiterator.h>
|
|
|
|
#include <dns/diff.h>
|
|
|
|
#include <dns/dnssec.h>
|
|
|
|
#include <dns/ds.h>
|
|
|
|
#include <dns/fixedname.h>
|
|
|
|
#include <dns/keyvalues.h>
|
|
|
|
#include <dns/log.h>
|
|
|
|
#include <dns/master.h>
|
|
|
|
#include <dns/masterdump.h>
|
|
|
|
#include <dns/nsec.h>
|
|
|
|
#include <dns/nsec3.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/rdatasetiter.h>
|
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
#include <dns/rdatatype.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/soa.h>
|
|
|
|
#include <dns/time.h>
|
|
|
|
|
|
|
|
#include <dst/dst.h>
|
|
|
|
|
2018-05-22 15:24:37 +02:00
|
|
|
#if HAVE_PKCS11
|
2014-03-12 20:52:01 -07:00
|
|
|
#include <pk11/result.h>
|
|
|
|
#endif
|
|
|
|
|
2012-06-25 13:57:32 +10:00
|
|
|
#include "dnssectool.h"
|
|
|
|
|
|
|
|
const char *program = "dnssec-verify";
|
|
|
|
int verbose;
|
|
|
|
|
|
|
|
static isc_stdtime_t now;
|
|
|
|
static isc_mem_t *mctx = NULL;
|
|
|
|
static dns_masterformat_t inputformat = dns_masterformat_text;
|
|
|
|
static dns_db_t *gdb; /* The database */
|
|
|
|
static dns_dbversion_t *gversion; /* The database version */
|
|
|
|
static dns_rdataclass_t gclass; /* The class */
|
|
|
|
static dns_name_t *gorigin; /* The database origin */
|
|
|
|
static isc_boolean_t ignore_kskflag = ISC_FALSE;
|
|
|
|
static isc_boolean_t keyset_kskonly = ISC_FALSE;
|
|
|
|
|
|
|
|
/*%
|
|
|
|
* Load the zone file from disk
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
loadzone(char *file, char *origin, dns_rdataclass_t rdclass, dns_db_t **db) {
|
|
|
|
isc_buffer_t b;
|
|
|
|
int len;
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
dns_name_t *name;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
len = strlen(origin);
|
|
|
|
isc_buffer_init(&b, origin, len);
|
|
|
|
isc_buffer_add(&b, len);
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(&fname);
|
2012-06-25 13:57:32 +10:00
|
|
|
result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("failed converting name '%s' to dns format: %s",
|
|
|
|
origin, isc_result_totext(result));
|
|
|
|
|
|
|
|
result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone,
|
|
|
|
rdclass, 0, NULL, db);
|
|
|
|
check_result(result, "dns_db_create()");
|
|
|
|
|
2018-04-03 13:22:09 +02:00
|
|
|
result = dns_db_load(*db, file, inputformat, 0);
|
2017-08-04 10:45:30 +02:00
|
|
|
switch (result) {
|
|
|
|
case DNS_R_SEENINCLUDE:
|
|
|
|
case ISC_R_SUCCESS:
|
|
|
|
break;
|
|
|
|
case DNS_R_NOTZONETOP:
|
|
|
|
/*
|
|
|
|
* Comparing pointers (vs. using strcmp()) is intentional: we
|
|
|
|
* want to check whether -o was supplied on the command line,
|
|
|
|
* not whether origin and file contain the same string.
|
|
|
|
*/
|
|
|
|
if (origin == file) {
|
|
|
|
fatal("failed loading zone '%s' from file '%s': "
|
|
|
|
"use -o to specify a different zone origin",
|
|
|
|
origin, file);
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
2012-06-25 13:57:32 +10:00
|
|
|
fatal("failed loading zone from '%s': %s",
|
|
|
|
file, isc_result_totext(result));
|
2017-08-04 10:45:30 +02:00
|
|
|
}
|
2012-06-25 13:57:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
ISC_PLATFORM_NORETURN_PRE static void
|
|
|
|
usage(void) ISC_PLATFORM_NORETURN_POST;
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void) {
|
|
|
|
fprintf(stderr, "Usage:\n");
|
|
|
|
fprintf(stderr, "\t%s [options] zonefile [keys]\n", program);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
fprintf(stderr, "Version: %s\n", VERSION);
|
|
|
|
|
|
|
|
fprintf(stderr, "Options: (default value in parenthesis) \n");
|
|
|
|
fprintf(stderr, "\t-v debuglevel (0)\n");
|
2014-06-13 06:27:43 +05:30
|
|
|
fprintf(stderr, "\t-V:\tprint version information\n");
|
2012-06-25 13:57:32 +10:00
|
|
|
fprintf(stderr, "\t-o origin:\n");
|
|
|
|
fprintf(stderr, "\t\tzone origin (name of zonefile)\n");
|
|
|
|
fprintf(stderr, "\t-I format:\n");
|
|
|
|
fprintf(stderr, "\t\tfile format of input zonefile (text)\n");
|
|
|
|
fprintf(stderr, "\t-c class (IN)\n");
|
|
|
|
fprintf(stderr, "\t-E engine:\n");
|
2018-05-22 15:24:37 +02:00
|
|
|
#if HAVE_PKCS11
|
2014-01-14 15:40:56 -08:00
|
|
|
fprintf(stderr, "\t\tpath to PKCS#11 provider library "
|
|
|
|
"(default is %s)\n", PK11_LIB_LOCATION);
|
|
|
|
#elif defined(USE_PKCS11)
|
2012-06-25 13:57:32 +10:00
|
|
|
fprintf(stderr, "\t\tname of an OpenSSL engine to use "
|
|
|
|
"(default is \"pkcs11\")\n");
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "\t\tname of an OpenSSL engine to use\n");
|
|
|
|
#endif
|
|
|
|
fprintf(stderr, "\t-x:\tDNSKEY record signed with KSKs only, "
|
|
|
|
"not ZSKs\n");
|
|
|
|
fprintf(stderr, "\t-z:\tAll records signed with KSKs\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
char *origin = NULL, *file = NULL;
|
|
|
|
char *inputformatstr = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_log_t *log = NULL;
|
|
|
|
#ifdef USE_PKCS11
|
2014-01-14 15:40:56 -08:00
|
|
|
const char *engine = PKCS11_ENGINE;
|
2012-06-25 13:57:32 +10:00
|
|
|
#else
|
|
|
|
const char *engine = NULL;
|
|
|
|
#endif
|
|
|
|
char *classname = NULL;
|
|
|
|
dns_rdataclass_t rdclass;
|
2014-03-04 10:42:25 -08:00
|
|
|
char *endp;
|
|
|
|
int ch;
|
2012-06-25 13:57:32 +10:00
|
|
|
|
|
|
|
#define CMDLINE_FLAGS \
|
2014-06-13 06:27:43 +05:30
|
|
|
"hm:o:I:c:E:v:Vxz"
|
2012-06-25 13:57:32 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process memory debugging argument first.
|
|
|
|
*/
|
|
|
|
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'm':
|
|
|
|
if (strcasecmp(isc_commandline_argument, "record") == 0)
|
|
|
|
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
|
|
|
|
if (strcasecmp(isc_commandline_argument, "trace") == 0)
|
|
|
|
isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
|
|
|
|
if (strcasecmp(isc_commandline_argument, "usage") == 0)
|
|
|
|
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
|
|
|
|
if (strcasecmp(isc_commandline_argument, "size") == 0)
|
|
|
|
isc_mem_debugging |= ISC_MEM_DEBUGSIZE;
|
|
|
|
if (strcasecmp(isc_commandline_argument, "mctx") == 0)
|
|
|
|
isc_mem_debugging |= ISC_MEM_DEBUGCTX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isc_commandline_reset = ISC_TRUE;
|
|
|
|
check_result(isc_app_start(), "isc_app_start");
|
|
|
|
|
|
|
|
result = isc_mem_create(0, 0, &mctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("out of memory");
|
|
|
|
|
2018-05-22 15:24:37 +02:00
|
|
|
#if HAVE_PKCS11
|
2014-03-12 20:52:01 -07:00
|
|
|
pk11_result_register();
|
|
|
|
#endif
|
2012-06-25 13:57:32 +10:00
|
|
|
dns_result_register();
|
|
|
|
|
|
|
|
isc_commandline_errprint = ISC_FALSE;
|
|
|
|
|
|
|
|
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'c':
|
|
|
|
classname = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'E':
|
|
|
|
engine = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
inputformatstr = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
origin = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
endp = NULL;
|
|
|
|
verbose = strtol(isc_commandline_argument, &endp, 0);
|
|
|
|
if (*endp != '\0')
|
|
|
|
fatal("verbose level must be numeric");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
keyset_kskonly = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'z':
|
|
|
|
ignore_kskflag = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
if (isc_commandline_option != '?')
|
|
|
|
fprintf(stderr, "%s: invalid argument -%c\n",
|
|
|
|
program, isc_commandline_option);
|
2014-06-13 06:27:43 +05:30
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
/* Does not return. */
|
2012-06-25 13:57:32 +10:00
|
|
|
usage();
|
2014-06-13 06:27:43 +05:30
|
|
|
|
|
|
|
case 'V':
|
|
|
|
/* Does not return. */
|
|
|
|
version(program);
|
2012-06-25 13:57:32 +10:00
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: unhandled option -%c\n",
|
|
|
|
program, isc_commandline_option);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-22 14:56:28 +02:00
|
|
|
result = dst_lib_init(mctx, engine);
|
2012-06-25 13:57:32 +10:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("could not initialize dst: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
|
|
|
|
isc_stdtime_get(&now);
|
|
|
|
|
|
|
|
rdclass = strtoclass(classname);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
setup_logging(mctx, &log);
|
2012-06-25 13:57:32 +10:00
|
|
|
|
|
|
|
argc -= isc_commandline_index;
|
|
|
|
argv += isc_commandline_index;
|
|
|
|
|
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
file = argv[0];
|
|
|
|
|
|
|
|
argc -= 1;
|
|
|
|
argv += 1;
|
|
|
|
|
2012-10-06 14:20:45 +10:00
|
|
|
POST(argc);
|
|
|
|
POST(argv);
|
|
|
|
|
2012-06-25 13:57:32 +10:00
|
|
|
if (origin == NULL)
|
|
|
|
origin = file;
|
|
|
|
|
|
|
|
if (inputformatstr != NULL) {
|
|
|
|
if (strcasecmp(inputformatstr, "text") == 0)
|
|
|
|
inputformat = dns_masterformat_text;
|
|
|
|
else if (strcasecmp(inputformatstr, "raw") == 0)
|
|
|
|
inputformat = dns_masterformat_raw;
|
|
|
|
else
|
|
|
|
fatal("unknown file format: %s\n", inputformatstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb = NULL;
|
|
|
|
fprintf(stderr, "Loading zone '%s' from file '%s'\n", origin, file);
|
|
|
|
loadzone(file, origin, rdclass, &gdb);
|
|
|
|
gorigin = dns_db_origin(gdb);
|
|
|
|
gclass = dns_db_class(gdb);
|
|
|
|
|
|
|
|
gversion = NULL;
|
|
|
|
result = dns_db_newversion(gdb, &gversion);
|
|
|
|
check_result(result, "dns_db_newversion()");
|
|
|
|
|
|
|
|
verifyzone(gdb, gversion, gorigin, mctx,
|
|
|
|
ignore_kskflag, keyset_kskonly);
|
|
|
|
|
|
|
|
dns_db_closeversion(gdb, &gversion, ISC_FALSE);
|
|
|
|
dns_db_detach(&gdb);
|
|
|
|
|
|
|
|
cleanup_logging(&log);
|
|
|
|
dst_lib_destroy();
|
|
|
|
dns_name_destroy();
|
|
|
|
if (verbose > 10)
|
|
|
|
isc_mem_stats(mctx, stdout);
|
|
|
|
isc_mem_destroy(&mctx);
|
|
|
|
|
|
|
|
(void) isc_app_finish();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|