1 /* $NetBSD: pkcs11-tokens.c,v 1.1.1.4 2014/12/10 03:34:27 christos Exp $ */
4 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
21 /* pkcs11-tokens [-m module] */
32 #include <sys/types.h>
34 #include <isc/commandline.h>
36 #include <isc/result.h>
37 #include <isc/types.h>
39 #include <pk11/pk11.h>
40 #include <pk11/result.h>
43 main(int argc
, char *argv
[]) {
45 char *lib_name
= NULL
;
47 isc_mem_t
*mctx
= NULL
;
50 while ((c
= isc_commandline_parse(argc
, argv
, ":m:")) != -1) {
53 lib_name
= isc_commandline_argument
;
56 fprintf(stderr
, "Option -%c requires an operand\n",
57 isc_commandline_option
);
62 fprintf(stderr
, "Unrecognised option: -%c\n",
63 isc_commandline_option
);
69 fprintf(stderr
, "Usage:\n");
70 fprintf(stderr
, "\tpkcs11-tokens [-m module]\n");
74 if (isc_mem_create(0, 0, &mctx
) != ISC_R_SUCCESS
) {
75 fprintf(stderr
, "isc_mem_create() failed\n");
79 pk11_result_register();
81 /* Initialize the CRYPTOKI library */
83 pk11_set_lib_name(lib_name
);
85 result
= pk11_get_session(&pctx
, OP_ANY
, ISC_FALSE
, ISC_FALSE
,
87 if (result
== PK11_R_NORANDOMSERVICE
||
88 result
== PK11_R_NODIGESTSERVICE
||
89 result
== PK11_R_NOAESSERVICE
) {
90 fprintf(stderr
, "Warning: %s\n", isc_result_totext(result
));
91 fprintf(stderr
, "This HSM will not work with BIND 9 "
92 "using native PKCS#11.\n\n");
93 } else if (result
!= ISC_R_SUCCESS
) {
94 fprintf(stderr
, "Unrecoverable error initializing "
95 "PKCS#11: %s\n", isc_result_totext(result
));
101 if (pctx
.handle
!= NULL
)
102 pk11_return_session(&pctx
);
103 (void) pk11_finalize();
105 isc_mem_destroy(&mctx
);