1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
/* gck-dump - the GObject PKCS#11 wrapper library
4
Copyright (C) 2010 Collabora Ltd
6
The Gnome Keyring Library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public License as
8
published by the Free Software Foundation; either version 2 of the
9
License, or (at your option) any later version.
11
The Gnome Keyring Library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public
17
License along with the Gnome Library; see the file COPYING.LIB. If not,
18
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
21
Author: Stef Walter <stefw@collabora.co.uk>
27
#include "gck-private.h"
29
#include "egg/egg-hex.h"
34
#include "pkcs11/pkcs11i.h"
35
#include "pkcs11/pkcs11x.h"
38
dump_class_value (gulong klass)
41
#define DX(x) case x: g_printerr ("%s", #x); break;
48
DX(CKO_DOMAIN_PARAMETERS);
53
DX(CKO_X_TRUST_ASSERTION);
57
g_printerr ("%s0x%08x",
58
(klass & CKO_VENDOR_DEFINED) == CKA_VENDOR_DEFINED ?
59
"CKO_VENDOR_DEFINED|" : "",
66
dump_assertion_type_value (gulong type)
69
#define DX(x) case x: g_printerr ("%s", #x); break;
70
DX(CKT_X_DISTRUSTED_CERTIFICATE);
71
DX(CKT_X_PINNED_CERTIFICATE);
72
DX(CKT_X_ANCHORED_CERTIFICATE);
76
g_printerr ("%u", (unsigned int)type);
82
dump_attribute_value (GckAttribute *attr)
87
g_assert (attr->length != G_MAXULONG);
89
if (attr->value == NULL) {
90
g_printerr ("[null]");
96
if (attr->length == sizeof (CK_OBJECT_CLASS)) {
97
dump_class_value (*(CK_ULONG_PTR)attr->value);
102
case CKA_X_ASSERTION_TYPE:
103
if (attr->length == sizeof (CK_X_ASSERTION_TYPE)) {
104
dump_assertion_type_value (*(CK_X_ASSERTION_TYPE*)attr->value);
109
case CKA_CERTIFICATE_TYPE:
110
case CKA_CERTIFICATE_CATEGORY:
111
case CKA_JAVA_MIDP_SECURITY_DOMAIN:
114
case CKA_SUB_PRIME_BITS:
117
case CKA_KEY_GEN_MECHANISM:
118
case CKA_HW_FEATURE_TYPE:
123
case CKA_CHAR_COLUMNS:
124
case CKA_BITS_PER_PIXEL:
125
case CKA_MECHANISM_TYPE:
126
case CKA_G_DESTRUCT_IDLE:
127
case CKA_G_DESTRUCT_AFTER:
128
case CKA_G_DESTRUCT_USES:
130
case CKA_G_CREDENTIAL:
131
if (attr->length == sizeof (CK_ULONG)) {
132
g_printerr ("%llu", (unsigned long long)*(CK_ULONG_PTR)attr->value);
146
case CKA_SIGN_RECOVER:
148
case CKA_VERIFY_RECOVER:
150
case CKA_EXTRACTABLE:
152
case CKA_NEVER_EXTRACTABLE:
153
case CKA_ALWAYS_SENSITIVE:
155
case CKA_ALWAYS_AUTHENTICATE:
156
case CKA_WRAP_WITH_TRUSTED:
157
case CKA_RESET_ON_INIT:
161
case CKA_G_LOGIN_COLLECTION:
162
if (attr->length == sizeof (CK_BBOOL)) {
163
g_printerr ("%s", (*(CK_BBOOL*)attr->value) ? "TRUE" : "FALSE");
171
case CKA_ENCODING_METHODS:
173
case CKA_G_COLLECTION:
177
if (g_utf8_validate (attr->value, attr->length, NULL)) {
178
int length = MIN (32, attr->length);
179
g_printerr ("%.*s%s", length, (gchar*)attr->value,
180
length < attr->length ? "..." : "");
189
if (attr->length == sizeof (CK_DATE)) {
190
const CK_DATE* date = attr->value;
191
g_printerr ("%.4s-%.2s-%.2s", date->year, date->month, date->day);
200
len = MIN (20, attr->length);
201
data = egg_hex_encode_full (attr->value, len, TRUE, ':', 1);
202
g_printerr ("%s%s", data, len < attr->length ? "..." : "");
207
dump_attribute_type (GckAttribute *attr)
209
switch (attr->type) {
210
#define DX(x) case x: g_printerr ("%s", #x); break;
218
DX(CKA_CERTIFICATE_TYPE);
220
DX(CKA_SERIAL_NUMBER);
225
DX(CKA_CERTIFICATE_CATEGORY);
226
DX(CKA_JAVA_MIDP_SECURITY_DOMAIN);
228
DX(CKA_HASH_OF_SUBJECT_PUBLIC_KEY);
229
DX(CKA_HASH_OF_ISSUER_PUBLIC_KEY);
240
DX(CKA_SIGN_RECOVER);
242
DX(CKA_VERIFY_RECOVER);
247
DX(CKA_MODULUS_BITS);
248
DX(CKA_PUBLIC_EXPONENT);
249
DX(CKA_PRIVATE_EXPONENT);
259
DX(CKA_SUB_PRIME_BITS);
264
DX(CKA_NEVER_EXTRACTABLE);
265
DX(CKA_ALWAYS_SENSITIVE);
266
DX(CKA_KEY_GEN_MECHANISM);
268
/* DX(CKA_ECDSA_PARAMS); */
271
DX(CKA_SECONDARY_AUTH);
272
DX(CKA_AUTH_PIN_FLAGS);
273
DX(CKA_ALWAYS_AUTHENTICATE);
274
DX(CKA_WRAP_WITH_TRUSTED);
275
DX(CKA_HW_FEATURE_TYPE);
276
DX(CKA_RESET_ON_INIT);
282
DX(CKA_CHAR_COLUMNS);
284
DX(CKA_BITS_PER_PIXEL);
286
DX(CKA_ENCODING_METHODS);
288
DX(CKA_MECHANISM_TYPE);
289
DX(CKA_REQUIRED_CMS_ATTRIBUTES);
290
DX(CKA_DEFAULT_CMS_ATTRIBUTES);
291
DX(CKA_SUPPORTED_CMS_ATTRIBUTES);
292
DX(CKA_WRAP_TEMPLATE);
293
DX(CKA_UNWRAP_TEMPLATE);
294
DX(CKA_ALLOWED_MECHANISMS);
301
DX(CKA_G_COLLECTION);
304
DX(CKA_G_LOGIN_COLLECTION);
305
DX(CKA_G_DESTRUCT_IDLE);
306
DX(CKA_G_DESTRUCT_AFTER);
307
DX(CKA_G_DESTRUCT_USES);
309
DX(CKA_G_CREDENTIAL);
310
DX(CKA_G_CREDENTIAL_TEMPLATE);
311
DX(CKA_X_ASSERTION_TYPE);
312
DX(CKA_X_CERTIFICATE_VALUE);
318
g_printerr ("%s0x%08x",
319
(attr->type & CKA_VENDOR_DEFINED) == CKA_VENDOR_DEFINED ?
320
"CKA_VENDOR_DEFINED|" : "",
321
(unsigned int)attr->type);
327
gck_attribute_dump (GckAttribute *attr)
329
dump_attribute_type (attr);
330
if (attr->length == G_MAXULONG) {
331
g_printerr ("\n [invalid]\n");
333
g_printerr ("\n [%lu] ", (unsigned long)attr->length);
334
dump_attribute_value (attr);
340
gck_attributes_dump (GckAttributes *attrs)
345
for (i = 0, count = gck_attributes_count (attrs); i < count; ++i) {
346
attr = gck_attributes_at (attrs, i);
347
gck_attribute_dump (attr);