4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
34 #define LIB_NSS_PATH "/usr/lib/mps/libnss3.so"
35 #define LIB_NSPR_PATH "/usr/lib/mps/libnspr4.so"
38 show_policy(KMF_POLICY_RECORD
*plc
)
44 (void) printf("Name: %s\n", plc
->name
);
46 (void) printf(gettext("Ignore Date: %s\n"),
47 plc
->ignore_date
? gettext("true") : gettext("false"));
49 (void) printf(gettext("Ignore Unknown EKUs: %s\n"),
50 plc
->ignore_unknown_ekus
? gettext("true") : gettext("false"));
52 (void) printf(gettext("Ignore TA: %s\n"),
53 plc
->ignore_trust_anchor
? gettext("true") : gettext("false"));
55 (void) printf(gettext("Validity Adjusted Time: %s\n"),
56 plc
->validity_adjusttime
? plc
->validity_adjusttime
: "<null>");
58 if (plc
->ta_name
== NULL
&& plc
->ta_serial
== NULL
) {
59 (void) printf(gettext("Trust Anchor Certificate: <null>\n"));
60 } else if (strcasecmp(plc
->ta_name
, "search") == 0) {
61 (void) printf(gettext("Trust Anchor Certificate: "
62 "Search by Issuer\n"));
64 (void) printf(gettext("Trust Anchor Certificate:\n"));
65 (void) printf(gettext("\tName: %s\n"),
66 plc
->ta_name
? plc
->ta_name
: "<null>");
67 (void) printf(gettext("\tSerial Number: %s\n"),
68 plc
->ta_serial
? plc
->ta_serial
: "<null>");
71 if (plc
->ku_bits
!= 0) {
72 (void) printf(gettext("Key Usage Bits: "));
73 for (i
= KULOWBIT
; i
<= KUHIGHBIT
; i
++) {
74 char *s
= kmf_ku_to_string(
75 (plc
->ku_bits
& (1<<i
)));
77 (void) printf("%s ", s
);
82 (void) printf(gettext("Key Usage Bits: 0\n"));
85 if (plc
->eku_set
.eku_count
> 0) {
86 (void) printf(gettext("Extended Key Usage Values:\n"));
87 for (i
= 0; i
< plc
->eku_set
.eku_count
; i
++) {
88 char *s
= kmf_oid_to_ekuname(
89 &plc
->eku_set
.ekulist
[i
]);
90 (void) printf("\t%s\t(%s)\n",
91 kmf_oid_to_string(&plc
->eku_set
.ekulist
[i
]),
95 (void) printf(gettext("Extended Key Usage Values: <null>\n"));
98 (void) printf(gettext("Validation Policy Information:\n"));
100 if (plc
->revocation
& KMF_REVOCATION_METHOD_OCSP
) {
101 (void) printf(gettext(" OCSP:\n"));
103 (void) printf(gettext("\tResponder URI: %s\n"),
104 plc
->VAL_OCSP_BASIC
.responderURI
?
105 plc
->VAL_OCSP_BASIC
.responderURI
: "<null>");
107 (void) printf(gettext("\tProxy: %s\n"),
108 plc
->VAL_OCSP_BASIC
.proxy
?
109 plc
->VAL_OCSP_BASIC
.proxy
: "<null>");
111 (void) printf(gettext("\tUse ResponderURI from Certificate: "
112 "%s\n"), plc
->VAL_OCSP_BASIC
.uri_from_cert
?
113 gettext("true") : gettext("false"));
115 (void) printf(gettext("\tResponse lifetime: %s\n"),
116 plc
->VAL_OCSP_BASIC
.response_lifetime
?
117 plc
->VAL_OCSP_BASIC
.response_lifetime
: "<null>");
119 (void) printf(gettext("\tIgnore Response signature: %s\n"),
120 plc
->VAL_OCSP_BASIC
.ignore_response_sign
?
121 gettext("true") : gettext("false"));
123 if (!plc
->VAL_OCSP
.has_resp_cert
) {
124 (void) printf(gettext("\tResponder Certificate:"
127 (void) printf(gettext("\tResponder Certificate:\n"));
128 (void) printf(gettext("\t\tName: %s\n"),
129 plc
->VAL_OCSP_RESP_CERT
.name
?
130 plc
->VAL_OCSP_RESP_CERT
.name
: "<null>");
131 (void) printf(gettext("\t\tSerial: %s\n"),
132 plc
->VAL_OCSP_RESP_CERT
.serial
?
133 plc
->VAL_OCSP_RESP_CERT
.serial
: "<null>");
137 if (plc
->revocation
& KMF_REVOCATION_METHOD_CRL
) {
138 (void) printf(gettext(" CRL:\n"));
140 (void) printf(gettext("\tBase filename: %s\n"),
141 plc
->validation_info
.crl_info
.basefilename
?
142 plc
->validation_info
.crl_info
.basefilename
: "<null>");
144 (void) printf(gettext("\tDirectory: %s\n"),
145 plc
->validation_info
.crl_info
.directory
?
146 plc
->validation_info
.crl_info
.directory
: "<null>");
148 (void) printf(gettext("\tDownload and cache CRL: %s\n"),
149 plc
->validation_info
.crl_info
.get_crl_uri
?
150 gettext("true") : gettext("false"));
152 (void) printf(gettext("\tProxy: %s\n"),
153 plc
->validation_info
.crl_info
.proxy
?
154 plc
->validation_info
.crl_info
.proxy
: "<null>");
156 (void) printf(gettext("\tIgnore CRL signature: %s\n"),
157 plc
->validation_info
.crl_info
.ignore_crl_sign
?
158 gettext("true") : gettext("false"));
160 (void) printf(gettext("\tIgnore CRL validity date: %s\n"),
161 plc
->validation_info
.crl_info
.ignore_crl_date
?
162 gettext("true") : gettext("false"));
164 (void) printf(gettext("Mapper name: %s\n"),
165 plc
->mapper
.mapname
? plc
->mapper
.mapname
: "<null>");
166 (void) printf(gettext("Mapper pathname: %s\n"),
167 plc
->mapper
.pathname
? plc
->mapper
.pathname
: "<null>");
168 (void) printf(gettext("Mapper directory: %s\n"),
169 plc
->mapper
.dir
? plc
->mapper
.dir
: "<null>");
170 (void) printf(gettext("Mapper options: %s\n"),
171 plc
->mapper
.options
? plc
->mapper
.options
: "<null>");
179 conf_entrylist_t
*phead
= NULL
;
182 (void) printf(gettext("KMF plugin information:\n"));
183 (void) printf(gettext("-----------------------\n"));
185 /* List the built-in plugins */
186 (void) printf("pkcs11:kmf_pkcs11.so.1 (built-in)\n");
187 (void) printf("file:kmf_openssl.so.1 (built-in)\n");
190 * If the NSS libraries are not installed in the system,
191 * then we will not show the nss plugin either.
193 if (stat(LIB_NSS_PATH
, &statbuf
) == 0 &&
194 stat(LIB_NSPR_PATH
, &statbuf
) == 0) {
195 (void) printf("nss:kmf_nss.so.1 (built-in)\n");
198 /* List non-default plugins, if there is any. */
199 if (get_entrylist(&phead
) == KMF_OK
) {
200 while (phead
!= NULL
) {
201 (void) printf("%s:%s", phead
->entry
->keystore
,
202 phead
->entry
->modulepath
);
204 if (phead
->entry
->option
== NULL
)
207 (void) printf(";option=%s\n",
208 phead
->entry
->option
);
211 free_entrylist(phead
);
217 kc_list(int argc
, char *argv
[])
221 extern int optind_av
;
222 extern char *optarg_av
;
223 char *filename
= NULL
;
224 char *policyname
= NULL
;
225 POLICY_LIST
*plclist
= NULL
, *pnode
;
227 boolean_t list_plugin
= B_FALSE
;
229 while ((opt
= getopt_av(argc
, argv
, "i:(dbfile)p:(policy)m(plugin)"))
236 filename
= get_string(optarg_av
, &rv
);
237 if (filename
== NULL
) {
238 (void) fprintf(stderr
,
239 gettext("Error dbfile input.\n"));
247 policyname
= get_string(optarg_av
, &rv
);
248 if (policyname
== NULL
) {
249 (void) fprintf(stderr
,
250 gettext("Error policy name.\n"));
255 list_plugin
= B_TRUE
;
258 (void) fprintf(stderr
,
259 gettext("Error input option.\n"));
267 /* No additional args allowed. */
270 (void) fprintf(stderr
,
271 gettext("Error input option\n"));
281 if (filename
== NULL
) {
282 filename
= strdup(KMF_DEFAULT_POLICY_FILE
);
283 if (filename
== NULL
) {
289 /* Check the access permission of the policy DB */
290 if (access(filename
, R_OK
) < 0) {
292 (void) fprintf(stderr
,
293 gettext("Cannot access \"%s\" for list - %s\n"), filename
,
299 rv
= load_policies(filename
, &plclist
);
305 while (pnode
!= NULL
) {
306 if (policyname
== NULL
||
307 strcmp(policyname
, pnode
->plc
.name
) == 0) {
308 KMF_POLICY_RECORD
*plc
= &pnode
->plc
;
311 rv
= kmf_verify_policy(plc
);
313 (void) fprintf(stderr
, gettext(
314 "Policy Name: '%s' is invalid\n"),
318 show_policy(&pnode
->plc
);
324 free_policy_list(plclist
);
328 (void) fprintf(stderr
, gettext(
329 "Cannot find policy '%s'\n"), policyname
);
331 (void) fprintf(stderr
, gettext("Cannot find "
332 "any policies to display\n"));
333 rv
= KC_ERR_FIND_POLICY
;
334 } else if (sanity_err
) {
335 rv
= KC_ERR_VERIFY_POLICY
;
340 if (filename
!= NULL
)
343 if (policyname
!= NULL
)