/* $NetBSD: pkcs11-tokens.c,v 1.1.1.4 2014/12/10 03:34:27 christos Exp $ */ /* * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ /* Id */ /* pkcs11-tokens [-m module] */ /*! \file */ #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { isc_result_t result; char *lib_name = NULL; int c, errflg = 0; isc_mem_t *mctx = NULL; pk11_context_t pctx; while ((c = isc_commandline_parse(argc, argv, ":m:")) != -1) { switch (c) { case 'm': lib_name = isc_commandline_argument; break; case ':': fprintf(stderr, "Option -%c requires an operand\n", isc_commandline_option); errflg++; break; case '?': default: fprintf(stderr, "Unrecognised option: -%c\n", isc_commandline_option); errflg++; } } if (errflg) { fprintf(stderr, "Usage:\n"); fprintf(stderr, "\tpkcs11-tokens [-m module]\n"); exit(1); } if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) { fprintf(stderr, "isc_mem_create() failed\n"); exit(1); } pk11_result_register(); /* Initialize the CRYPTOKI library */ if (lib_name != NULL) pk11_set_lib_name(lib_name); result = pk11_get_session(&pctx, OP_ANY, ISC_FALSE, ISC_FALSE, ISC_FALSE, NULL, 0); if (result == PK11_R_NORANDOMSERVICE || result == PK11_R_NODIGESTSERVICE || result == PK11_R_NOAESSERVICE) { fprintf(stderr, "Warning: %s\n", isc_result_totext(result)); fprintf(stderr, "This HSM will not work with BIND 9 " "using native PKCS#11.\n\n"); } else if (result != ISC_R_SUCCESS) { fprintf(stderr, "Unrecoverable error initializing " "PKCS#11: %s\n", isc_result_totext(result)); exit(1); } pk11_dump_tokens(); if (pctx.handle != NULL) pk11_return_session(&pctx); (void) pk11_finalize(); isc_mem_destroy(&mctx); exit(0); }