1 /*
2 * COPYRIGHT (c) International Business Machines Corp. 2001-2017
3 *
4 * This program is provided under the terms of the Common Public License,
5 * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
6 * software constitutes recipient's acceptance of CPL-1.0 terms which can be
7 * found in the file LICENSE file or at
8 * https://opensource.org/licenses/cpl1.0.php
9 */
10
11 #include <errno.h>
12 #include <signal.h>
13 #include <stdarg.h>
14 #include <sys/types.h>
15
16 #include "log.h"
17 #include "slotmgr.h"
18 #include "err.h"
19
20
21 static ConstInfo SysErrorInfo[] = {
22
23 CONSTINFO(EPERM),
24 CONSTINFO(ENOENT),
25 CONSTINFO(ESRCH),
26 CONSTINFO(EINTR),
27 CONSTINFO(EIO),
28 CONSTINFO(ENXIO),
29 CONSTINFO(E2BIG),
30 CONSTINFO(ENOEXEC),
31 CONSTINFO(EBADF),
32 CONSTINFO(ECHILD),
33 CONSTINFO(EAGAIN),
34 CONSTINFO(ENOMEM),
35 CONSTINFO(EACCES),
36 CONSTINFO(EFAULT),
37 CONSTINFO(ENOTBLK),
38 CONSTINFO(EBUSY),
39 CONSTINFO(EEXIST),
40 CONSTINFO(EXDEV),
41 CONSTINFO(ENODEV),
42 CONSTINFO(ENOTDIR),
43 CONSTINFO(EISDIR),
44 CONSTINFO(EINVAL),
45 CONSTINFO(ENFILE),
46 CONSTINFO(EMFILE),
47 CONSTINFO(ENOTTY),
48 CONSTINFO(ETXTBSY),
49 CONSTINFO(EFBIG),
50 CONSTINFO(ENOSPC),
51 CONSTINFO(ESPIPE),
52 CONSTINFO(EROFS),
53 CONSTINFO(EMLINK),
54 CONSTINFO(EPIPE),
55 CONSTINFO(EDOM),
56 CONSTINFO(ERANGE),
57 CONSTINFO(ENOMSG),
58 CONSTINFO(EIDRM),
59 #ifdef ECHRNG
60 CONSTINFO(ECHRNG),
61 #endif
62 #ifdef EL2NSYNC
63 CONSTINFO(EL2NSYNC),
64 #endif
65 #ifdef EL3HLT
66 CONSTINFO(EL3HLT),
67 #endif
68 #ifdef EL3RST
69 CONSTINFO(EL3RST),
70 #endif
71 #ifdef ELNRNG
72 CONSTINFO(ELNRNG),
73 #endif
74 #ifdef EUNATCH
75 CONSTINFO(EUNATCH),
76 #endif
77 #ifdef ENOCSI
78 CONSTINFO(ENOCSI),
79 #endif
80 #ifdef EL2HLT
81 CONSTINFO(EL2HLT),
82 #endif
83 CONSTINFO(EDEADLK),
84 CONSTINFO(ESTALE),
85 CONSTINFO(EWOULDBLOCK),
86 CONSTINFO(EINPROGRESS),
87 CONSTINFO(EALREADY),
88 CONSTINFO(ENOTSOCK),
89 CONSTINFO(EDESTADDRREQ),
90 CONSTINFO(EMSGSIZE),
91 CONSTINFO(EPROTOTYPE),
92 CONSTINFO(ENOPROTOOPT),
93 CONSTINFO(EPROTONOSUPPORT),
94 CONSTINFO(ESOCKTNOSUPPORT),
95 CONSTINFO(EOPNOTSUPP),
96 CONSTINFO(EPFNOSUPPORT),
97 CONSTINFO(EAFNOSUPPORT),
98 CONSTINFO(EADDRINUSE),
99 CONSTINFO(EADDRNOTAVAIL),
100 CONSTINFO(ENETDOWN),
101 CONSTINFO(ENETUNREACH),
102 CONSTINFO(ENETRESET),
103 CONSTINFO(ECONNABORTED),
104 CONSTINFO(ECONNRESET),
105 CONSTINFO(ENOBUFS),
106 CONSTINFO(EISCONN),
107 CONSTINFO(ENOTCONN),
108 CONSTINFO(ESHUTDOWN),
109 CONSTINFO(ETIMEDOUT),
110 CONSTINFO(ECONNREFUSED),
111 CONSTINFO(EHOSTDOWN),
112 CONSTINFO(EHOSTUNREACH),
113 #ifdef ERESTART
114 CONSTINFO(ERESTART),
115 #endif
116 CONSTINFO(EUSERS),
117 CONSTINFO(ELOOP),
118 CONSTINFO(ENAMETOOLONG),
119 CONSTINFO(ENOTEMPTY),
120 CONSTINFO(EDQUOT),
121 CONSTINFO(EREMOTE),
122 CONSTINFO(ENOSYS),
123 CONSTINFO(ETOOMANYREFS),
124 CONSTINFO(EILSEQ),
125 CONSTINFO(ECANCELED),
126 #ifdef ENOSR
127 CONSTINFO(ENOSR),
128 #endif
129 #ifdef ETIME
130 CONSTINFO(ETIME),
131 #endif
132 #ifdef EBADMSG
133 CONSTINFO(EBADMSG),
134 #endif
135 #ifdef EPROTO
136 CONSTINFO(EPROTO),
137 #endif
138 #ifdef ENODATA
139 CONSTINFO(ENODATA),
140 #endif
141 #ifdef ENOSTR
142 CONSTINFO(ENOSTR),
143 #endif
144 CONSTINFO(ENOTSUP),
145 #ifdef EMULTIHOP
146 CONSTINFO(EMULTIHOP),
147 #endif
148 #ifdef ENOLINK
149 CONSTINFO(ENOLINK),
150 #endif
151 #ifdef EOVERFLOW
152 CONSTINFO(EOVERFLOW),
153 #endif
154
155 };
156
157 static int SysErrorSize = (sizeof(SysErrorInfo) / sizeof(SysErrorInfo[0]));
158
159
160
161 static ConstInfo SignalInfo[] = {
162
163 CONSTINFO(SIGHUP),
164 CONSTINFO(SIGINT),
165 CONSTINFO(SIGQUIT),
166 CONSTINFO(SIGILL),
167 CONSTINFO(SIGTRAP),
168 CONSTINFO(SIGABRT),
169 CONSTINFO(SIGFPE),
170 CONSTINFO(SIGKILL),
171 CONSTINFO(SIGBUS),
172 CONSTINFO(SIGSEGV),
173 CONSTINFO(SIGSYS),
174 CONSTINFO(SIGPIPE),
175 CONSTINFO(SIGALRM),
176 CONSTINFO(SIGTERM),
177 CONSTINFO(SIGURG),
178 CONSTINFO(SIGSTOP),
179 CONSTINFO(SIGTSTP),
180 CONSTINFO(SIGCONT),
181 CONSTINFO(SIGCHLD),
182 CONSTINFO(SIGTTIN),
183 CONSTINFO(SIGTTOU),
184 CONSTINFO(SIGIO),
185 CONSTINFO(SIGXCPU),
186 CONSTINFO(SIGXFSZ),
187 CONSTINFO(SIGWINCH),
188 #ifdef SIGPWR
189 CONSTINFO(SIGPWR),
190 #endif
191 CONSTINFO(SIGUSR1),
192 CONSTINFO(SIGUSR2),
193 CONSTINFO(SIGPROF),
194 CONSTINFO(SIGVTALRM),
195 CONSTINFO(SIGIOT),
196 #ifdef SIGCLD
197 CONSTINFO(SIGCLD),
198 #endif
199 #ifdef SIGPOLL
200 CONSTINFO(SIGPOLL),
201 #endif
202 #if 0
203 CONSTINFO(SIG_DFL),
204 CONSTINFO(SIG_IGN),
205 CONSTINFO(SIG_HOLD),
206 CONSTINFO(SIG_CATCH),
207 CONSTINFO(SIG_ERR),
208 #endif /* 0 */
209
210 };
211
212 static int SignalInfoSize = (sizeof(SignalInfo) / sizeof(SignalInfo[0]));
213
214 static ConstInfo PkcsReturnInfo[] = {
215
216 CONSTINFO(CKR_OK),
217 CONSTINFO(CKR_CANCEL),
218 CONSTINFO(CKR_HOST_MEMORY),
219 CONSTINFO(CKR_SLOT_ID_INVALID),
220 CONSTINFO(CKR_GENERAL_ERROR),
221 CONSTINFO(CKR_FUNCTION_FAILED),
222 CONSTINFO(CKR_ARGUMENTS_BAD),
223 CONSTINFO(CKR_NO_EVENT),
224 CONSTINFO(CKR_NEED_TO_CREATE_THREADS),
225 CONSTINFO(CKR_CANT_LOCK),
226 CONSTINFO(CKR_ATTRIBUTE_READ_ONLY),
227 CONSTINFO(CKR_ATTRIBUTE_SENSITIVE),
228 CONSTINFO(CKR_ATTRIBUTE_TYPE_INVALID),
229 CONSTINFO(CKR_ATTRIBUTE_VALUE_INVALID),
230 CONSTINFO(CKR_DATA_INVALID),
231 CONSTINFO(CKR_DATA_LEN_RANGE),
232 CONSTINFO(CKR_DEVICE_ERROR),
233 CONSTINFO(CKR_DEVICE_MEMORY),
234 CONSTINFO(CKR_DEVICE_REMOVED),
235 CONSTINFO(CKR_ENCRYPTED_DATA_INVALID),
236 CONSTINFO(CKR_ENCRYPTED_DATA_LEN_RANGE),
237 CONSTINFO(CKR_FUNCTION_CANCELED),
238 CONSTINFO(CKR_FUNCTION_NOT_PARALLEL),
239 CONSTINFO(CKR_FUNCTION_NOT_SUPPORTED),
240 CONSTINFO(CKR_KEY_HANDLE_INVALID),
241 CONSTINFO(CKR_KEY_SIZE_RANGE),
242 CONSTINFO(CKR_KEY_TYPE_INCONSISTENT),
243 CONSTINFO(CKR_KEY_NOT_NEEDED),
244 CONSTINFO(CKR_KEY_CHANGED),
245 CONSTINFO(CKR_KEY_NEEDED),
246 CONSTINFO(CKR_KEY_INDIGESTIBLE),
247 CONSTINFO(CKR_KEY_FUNCTION_NOT_PERMITTED),
248 CONSTINFO(CKR_KEY_NOT_WRAPPABLE),
249 CONSTINFO(CKR_KEY_UNEXTRACTABLE),
250 CONSTINFO(CKR_MECHANISM_INVALID),
251 CONSTINFO(CKR_MECHANISM_PARAM_INVALID),
252 CONSTINFO(CKR_OBJECT_HANDLE_INVALID),
253 CONSTINFO(CKR_OPERATION_ACTIVE),
254 CONSTINFO(CKR_OPERATION_NOT_INITIALIZED),
255 CONSTINFO(CKR_PIN_INCORRECT),
256 CONSTINFO(CKR_PIN_INVALID),
257 CONSTINFO(CKR_PIN_LEN_RANGE),
258 CONSTINFO(CKR_PIN_EXPIRED),
259 CONSTINFO(CKR_PIN_LOCKED),
260 CONSTINFO(CKR_SESSION_CLOSED),
261 CONSTINFO(CKR_SESSION_COUNT),
262 CONSTINFO(CKR_SESSION_HANDLE_INVALID),
263 CONSTINFO(CKR_SESSION_PARALLEL_NOT_SUPPORTED),
264 CONSTINFO(CKR_SESSION_READ_ONLY),
265 CONSTINFO(CKR_SESSION_EXISTS),
266 CONSTINFO(CKR_SESSION_READ_ONLY_EXISTS),
267 CONSTINFO(CKR_SESSION_READ_WRITE_SO_EXISTS),
268 CONSTINFO(CKR_SIGNATURE_INVALID),
269 CONSTINFO(CKR_SIGNATURE_LEN_RANGE),
270 CONSTINFO(CKR_TEMPLATE_INCOMPLETE),
271 CONSTINFO(CKR_TEMPLATE_INCONSISTENT),
272 CONSTINFO(CKR_TOKEN_NOT_PRESENT),
273 CONSTINFO(CKR_TOKEN_NOT_RECOGNIZED),
274 CONSTINFO(CKR_TOKEN_WRITE_PROTECTED),
275 CONSTINFO(CKR_UNWRAPPING_KEY_HANDLE_INVALID),
276 CONSTINFO(CKR_UNWRAPPING_KEY_SIZE_RANGE),
277 CONSTINFO(CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT),
278 CONSTINFO(CKR_USER_ALREADY_LOGGED_IN),
279 CONSTINFO(CKR_USER_NOT_LOGGED_IN),
280 CONSTINFO(CKR_USER_PIN_NOT_INITIALIZED),
281 CONSTINFO(CKR_USER_TYPE_INVALID),
282 CONSTINFO(CKR_USER_ANOTHER_ALREADY_LOGGED_IN),
283 CONSTINFO(CKR_USER_TOO_MANY_TYPES),
284 CONSTINFO(CKR_WRAPPED_KEY_INVALID),
285 CONSTINFO(CKR_WRAPPED_KEY_LEN_RANGE),
286 CONSTINFO(CKR_WRAPPING_KEY_HANDLE_INVALID),
287 CONSTINFO(CKR_WRAPPING_KEY_SIZE_RANGE),
288 CONSTINFO(CKR_WRAPPING_KEY_TYPE_INCONSISTENT),
289 CONSTINFO(CKR_RANDOM_SEED_NOT_SUPPORTED),
290 CONSTINFO(CKR_RANDOM_NO_RNG),
291 CONSTINFO(CKR_DOMAIN_PARAMS_INVALID),
292 CONSTINFO(CKR_CURVE_NOT_SUPPORTED),
293 CONSTINFO(CKR_BUFFER_TOO_SMALL),
294 CONSTINFO(CKR_SAVED_STATE_INVALID),
295 CONSTINFO(CKR_INFORMATION_SENSITIVE),
296 CONSTINFO(CKR_STATE_UNSAVEABLE),
297 CONSTINFO(CKR_CRYPTOKI_NOT_INITIALIZED),
298 CONSTINFO(CKR_CRYPTOKI_ALREADY_INITIALIZED),
299 CONSTINFO(CKR_MUTEX_BAD),
300 CONSTINFO(CKR_MUTEX_NOT_LOCKED),
301 CONSTINFO(CKR_FUNCTION_REJECTED),
302 CONSTINFO(CKR_VENDOR_DEFINED),
303
304 };
305
306
307 static int PkcsReturnSize =
308 (sizeof(PkcsReturnInfo) / sizeof(PkcsReturnInfo[0]));
309
310
311
312
313 static ConstInfo PkcsFlagsInfo[] = {
314
315 CONSTINFO((CKF_RNG | CKF_HW | CKF_LIBRARY_CANT_CREATE_OS_THREADS |
316 CKF_TOKEN_PRESENT)),
317 CONSTINFO((CKF_REMOVABLE_DEVICE | CKF_OS_LOCKING_OK | CKF_RW_SESSION |
318 CKF_WRITE_PROTECTED)),
319 CONSTINFO((CKF_SERIAL_SESSION | CKF_HW_SLOT | CKF_LOGIN_REQUIRED)),
320 CONSTINFO(CKF_USER_PIN_INITIALIZED),
321 CONSTINFO(CKF_RESTORE_KEY_NOT_NEEDED),
322 CONSTINFO(CKF_CLOCK_ON_TOKEN),
323 CONSTINFO((CKF_PROTECTED_AUTHENTICATION_PATH | CKF_ENCRYPT)),
324 CONSTINFO((CKF_DUAL_CRYPTO_OPERATIONS | CKF_DECRYPT)),
325 CONSTINFO(CKF_DIGEST),
326 CONSTINFO(CKF_SIGN),
327 CONSTINFO(CKF_SIGN_RECOVER),
328 CONSTINFO(CKF_VERIFY),
329 CONSTINFO(CKF_VERIFY_RECOVER),
330 CONSTINFO(CKF_GENERATE),
331 CONSTINFO((CKF_GENERATE_KEY_PAIR | CKF_USER_PIN_COUNT_LOW)),
332 CONSTINFO((CKF_USER_PIN_FINAL_TRY | CKF_WRAP)),
333 CONSTINFO((CKF_UNWRAP | CKF_USER_PIN_LOCKED)),
334 CONSTINFO((CKF_DERIVE /*| CKF_USER_PIN_MANUFACT_VALUE */ )),
335 CONSTINFO(CKF_SO_PIN_DERIVED),
336 CONSTINFO(CKF_SO_CARD),
337 CONSTINFO(CKF_SO_PIN_COUNT_LOW),
338 CONSTINFO(CKF_SO_PIN_FINAL_TRY),
339 CONSTINFO(CKF_SO_PIN_LOCKED),
340 /*CONSTINFO(CKF_SO_PIN_MANUFACT_VALUE), */
341 CONSTINFO(CKF_EXTENSION),
342
343 };
344
345 static int PkcsFlagsSize = (sizeof(PkcsFlagsInfo) / sizeof(PkcsFlagsInfo[0]));
346
347
348
349 static ConstInfo PkcsMechanismInfo[] = {
350
351 CONSTINFO(CKM_RSA_PKCS_KEY_PAIR_GEN),
352 CONSTINFO(CKM_RSA_PKCS),
353 CONSTINFO(CKM_RSA_9796),
354 CONSTINFO(CKM_RSA_X_509),
355 CONSTINFO(CKM_MD2_RSA_PKCS),
356 CONSTINFO(CKM_MD5_RSA_PKCS),
357 CONSTINFO(CKM_SHA1_RSA_PKCS),
358 CONSTINFO(CKM_DSA_KEY_PAIR_GEN),
359 CONSTINFO(CKM_DSA),
360 CONSTINFO(CKM_DSA_SHA1),
361 CONSTINFO(CKM_DH_PKCS_KEY_PAIR_GEN),
362 CONSTINFO(CKM_DH_PKCS_DERIVE),
363 CONSTINFO(CKM_RC2_KEY_GEN),
364 CONSTINFO(CKM_RC2_ECB),
365 CONSTINFO(CKM_RC2_CBC),
366 CONSTINFO(CKM_RC2_MAC),
367 CONSTINFO(CKM_RC2_MAC_GENERAL),
368 CONSTINFO(CKM_RC2_CBC_PAD),
369 CONSTINFO(CKM_RC4_KEY_GEN),
370 CONSTINFO(CKM_RC4),
371 CONSTINFO(CKM_DES_KEY_GEN),
372 CONSTINFO(CKM_DES_ECB),
373 CONSTINFO(CKM_DES_CBC),
374 CONSTINFO(CKM_DES_MAC),
375 CONSTINFO(CKM_DES_MAC_GENERAL),
376 CONSTINFO(CKM_DES_CBC_PAD),
377 CONSTINFO(CKM_DES2_KEY_GEN),
378 CONSTINFO(CKM_DES3_KEY_GEN),
379 CONSTINFO(CKM_DES3_ECB),
380 CONSTINFO(CKM_DES3_CBC),
381 CONSTINFO(CKM_DES3_MAC),
382 CONSTINFO(CKM_DES3_MAC_GENERAL),
383 CONSTINFO(CKM_DES3_CBC_PAD),
384 CONSTINFO(CKM_CDMF_KEY_GEN),
385 CONSTINFO(CKM_CDMF_ECB),
386 CONSTINFO(CKM_CDMF_CBC),
387 CONSTINFO(CKM_CDMF_MAC),
388 CONSTINFO(CKM_CDMF_MAC_GENERAL),
389 CONSTINFO(CKM_CDMF_CBC_PAD),
390 CONSTINFO(CKM_MD2),
391 CONSTINFO(CKM_MD2_HMAC),
392 CONSTINFO(CKM_MD2_HMAC_GENERAL),
393 CONSTINFO(CKM_MD5),
394 CONSTINFO(CKM_MD5_HMAC),
395 CONSTINFO(CKM_MD5_HMAC_GENERAL),
396 CONSTINFO(CKM_SHA_1),
397 CONSTINFO(CKM_SHA_1_HMAC),
398 CONSTINFO(CKM_SHA_1_HMAC_GENERAL),
399 CONSTINFO(CKM_SHA224),
400 CONSTINFO(CKM_SHA224_HMAC),
401 CONSTINFO(CKM_SHA224_HMAC_GENERAL),
402 CONSTINFO(CKM_SHA256),
403 CONSTINFO(CKM_SHA256_HMAC),
404 CONSTINFO(CKM_SHA256_HMAC_GENERAL),
405 CONSTINFO(CKM_SHA384),
406 CONSTINFO(CKM_SHA384_HMAC),
407 CONSTINFO(CKM_SHA384_HMAC_GENERAL),
408 CONSTINFO(CKM_SHA512),
409 CONSTINFO(CKM_SHA512_HMAC),
410 CONSTINFO(CKM_SHA512_HMAC_GENERAL),
411 CONSTINFO(CKM_SHA512_224),
412 CONSTINFO(CKM_SHA512_224_HMAC),
413 CONSTINFO(CKM_SHA512_224_HMAC_GENERAL),
414 CONSTINFO(CKM_SHA512_256),
415 CONSTINFO(CKM_SHA512_256_HMAC),
416 CONSTINFO(CKM_SHA512_256_HMAC_GENERAL),
417 CONSTINFO(CKM_CAST_KEY_GEN),
418 CONSTINFO(CKM_CAST_ECB),
419 CONSTINFO(CKM_CAST_CBC),
420 CONSTINFO(CKM_CAST_MAC),
421 CONSTINFO(CKM_CAST_MAC_GENERAL),
422 CONSTINFO(CKM_CAST_CBC_PAD),
423 CONSTINFO(CKM_CAST3_KEY_GEN),
424 CONSTINFO(CKM_CAST3_ECB),
425 CONSTINFO(CKM_CAST3_CBC),
426 CONSTINFO(CKM_CAST3_MAC),
427 CONSTINFO(CKM_CAST3_MAC_GENERAL),
428 CONSTINFO(CKM_CAST3_CBC_PAD),
429 CONSTINFO(CKM_CAST5_KEY_GEN),
430 CONSTINFO(CKM_CAST128_KEY_GEN),
431 CONSTINFO(CKM_CAST5_ECB),
432 CONSTINFO(CKM_CAST128_ECB),
433 CONSTINFO(CKM_CAST5_CBC),
434 CONSTINFO(CKM_CAST128_CBC),
435 CONSTINFO(CKM_CAST5_MAC),
436 CONSTINFO(CKM_CAST128_MAC),
437 CONSTINFO(CKM_CAST5_MAC_GENERAL),
438 CONSTINFO(CKM_CAST128_MAC_GENERAL),
439 CONSTINFO(CKM_CAST5_CBC_PAD),
440 CONSTINFO(CKM_CAST128_CBC_PAD),
441 CONSTINFO(CKM_RC5_KEY_GEN),
442 CONSTINFO(CKM_RC5_ECB),
443 CONSTINFO(CKM_RC5_CBC),
444 CONSTINFO(CKM_RC5_MAC),
445 CONSTINFO(CKM_RC5_MAC_GENERAL),
446 CONSTINFO(CKM_RC5_CBC_PAD),
447 CONSTINFO(CKM_IDEA_KEY_GEN),
448 CONSTINFO(CKM_IDEA_ECB),
449 CONSTINFO(CKM_IDEA_CBC),
450 CONSTINFO(CKM_IDEA_MAC),
451 CONSTINFO(CKM_IDEA_MAC_GENERAL),
452 CONSTINFO(CKM_IDEA_CBC_PAD),
453 CONSTINFO(CKM_GENERIC_SECRET_KEY_GEN),
454 CONSTINFO(CKM_CONCATENATE_BASE_AND_KEY),
455 CONSTINFO(CKM_CONCATENATE_BASE_AND_DATA),
456 CONSTINFO(CKM_CONCATENATE_DATA_AND_BASE),
457 CONSTINFO(CKM_XOR_BASE_AND_DATA),
458 CONSTINFO(CKM_EXTRACT_KEY_FROM_KEY),
459 CONSTINFO(CKM_SSL3_PRE_MASTER_KEY_GEN),
460 CONSTINFO(CKM_SSL3_MASTER_KEY_DERIVE),
461 CONSTINFO(CKM_SSL3_KEY_AND_MAC_DERIVE),
462 CONSTINFO(CKM_SSL3_MD5_MAC),
463 CONSTINFO(CKM_SSL3_SHA1_MAC),
464 CONSTINFO(CKM_MD5_KEY_DERIVATION),
465 CONSTINFO(CKM_MD2_KEY_DERIVATION),
466 CONSTINFO(CKM_SHA1_KEY_DERIVATION),
467 CONSTINFO(CKM_PBE_MD2_DES_CBC),
468 CONSTINFO(CKM_PBE_MD5_DES_CBC),
469 CONSTINFO(CKM_PBE_MD5_CAST_CBC),
470 CONSTINFO(CKM_PBE_MD5_CAST3_CBC),
471 CONSTINFO(CKM_PBE_MD5_CAST5_CBC),
472 CONSTINFO(CKM_PBE_MD5_CAST128_CBC),
473 CONSTINFO(CKM_PBE_SHA1_CAST5_CBC),
474 CONSTINFO(CKM_PBE_SHA1_CAST128_CBC),
475 CONSTINFO(CKM_PBE_SHA1_RC4_128),
476 CONSTINFO(CKM_PBE_SHA1_RC4_40),
477 CONSTINFO(CKM_PBE_SHA1_DES3_EDE_CBC),
478 CONSTINFO(CKM_PBE_SHA1_DES2_EDE_CBC),
479 CONSTINFO(CKM_PBE_SHA1_RC2_128_CBC),
480 CONSTINFO(CKM_PBE_SHA1_RC2_40_CBC),
481 CONSTINFO(CKM_PBA_SHA1_WITH_SHA1_HMAC),
482 CONSTINFO(CKM_KEY_WRAP_LYNKS),
483 CONSTINFO(CKM_KEY_WRAP_SET_OAEP),
484 CONSTINFO(CKM_SKIPJACK_KEY_GEN),
485 CONSTINFO(CKM_SKIPJACK_ECB64),
486 CONSTINFO(CKM_SKIPJACK_CBC64),
487 CONSTINFO(CKM_SKIPJACK_OFB64),
488 CONSTINFO(CKM_SKIPJACK_CFB64),
489 CONSTINFO(CKM_SKIPJACK_CFB32),
490 CONSTINFO(CKM_SKIPJACK_CFB16),
491 CONSTINFO(CKM_SKIPJACK_CFB8),
492 CONSTINFO(CKM_SKIPJACK_WRAP),
493 CONSTINFO(CKM_SKIPJACK_PRIVATE_WRAP),
494 CONSTINFO(CKM_SKIPJACK_RELAYX),
495 CONSTINFO(CKM_KEA_KEY_PAIR_GEN),
496 CONSTINFO(CKM_KEA_KEY_DERIVE),
497 CONSTINFO(CKM_FORTEZZA_TIMESTAMP),
498 CONSTINFO(CKM_BATON_KEY_GEN),
499 CONSTINFO(CKM_BATON_ECB128),
500 CONSTINFO(CKM_BATON_ECB96),
501 CONSTINFO(CKM_BATON_CBC128),
502 CONSTINFO(CKM_BATON_COUNTER),
503 CONSTINFO(CKM_BATON_SHUFFLE),
504 CONSTINFO(CKM_BATON_WRAP),
505 CONSTINFO(CKM_ECDSA_KEY_PAIR_GEN),
506 CONSTINFO(CKM_ECDSA),
507 CONSTINFO(CKM_ECDSA_SHA1),
508 CONSTINFO(CKM_ECDSA_SHA224),
509 CONSTINFO(CKM_ECDSA_SHA256),
510 CONSTINFO(CKM_ECDSA_SHA384),
511 CONSTINFO(CKM_ECDSA_SHA512),
512 CONSTINFO(CKM_SHA224_RSA_PKCS),
513 CONSTINFO(CKM_SHA256_RSA_PKCS),
514 CONSTINFO(CKM_SHA384_RSA_PKCS),
515 CONSTINFO(CKM_SHA512_RSA_PKCS),
516 CONSTINFO(CKM_SHA224_RSA_PKCS_PSS),
517 CONSTINFO(CKM_SHA256_RSA_PKCS_PSS),
518 CONSTINFO(CKM_SHA384_RSA_PKCS_PSS),
519 CONSTINFO(CKM_SHA512_RSA_PKCS_PSS),
520 CONSTINFO(CKM_SHA224_KEY_DERIVATION),
521 CONSTINFO(CKM_SHA256_KEY_DERIVATION),
522 CONSTINFO(CKM_SHA384_KEY_DERIVATION),
523 CONSTINFO(CKM_SHA512_KEY_DERIVATION),
524 CONSTINFO(CKM_JUNIPER_KEY_GEN),
525 CONSTINFO(CKM_JUNIPER_ECB128),
526 CONSTINFO(CKM_JUNIPER_CBC128),
527 CONSTINFO(CKM_JUNIPER_COUNTER),
528 CONSTINFO(CKM_JUNIPER_SHUFFLE),
529 CONSTINFO(CKM_JUNIPER_WRAP),
530 CONSTINFO(CKM_FASTHASH),
531 CONSTINFO(CKM_VENDOR_DEFINED),
532
533 };
534
535
536 static unsigned int PkcsMechanismSize =
537 (sizeof(PkcsMechanismInfo) / sizeof(PkcsMechanismInfo[0]));
538
539
540
541 static ConstInfo PkcsObjectInfo[] = {
542
543 CONSTINFO(CKO_DATA),
544 CONSTINFO(CKO_CERTIFICATE),
545 CONSTINFO(CKO_PUBLIC_KEY),
546 CONSTINFO(CKO_PRIVATE_KEY),
547 CONSTINFO(CKO_SECRET_KEY),
548 CONSTINFO(CKO_VENDOR_DEFINED),
549
550 };
551
552 static unsigned int PkcsObjectSize =
553 (sizeof(PkcsObjectInfo) / sizeof(PkcsObjectInfo[0]));
554
555
556
557
558
559 static ConstInfo PkcsKeyInfo[] = {
560
561 CONSTINFO(CKK_RSA),
562 CONSTINFO(CKK_DSA),
563 CONSTINFO(CKK_DH),
564 CONSTINFO(CKK_ECDSA),
565 CONSTINFO(CKK_KEA),
566 CONSTINFO(CKK_GENERIC_SECRET),
567 CONSTINFO(CKK_RC2),
568 CONSTINFO(CKK_RC4),
569 CONSTINFO(CKK_DES),
570 CONSTINFO(CKK_DES2),
571 CONSTINFO(CKK_DES3),
572 CONSTINFO(CKK_CAST),
573 CONSTINFO(CKK_CAST3),
574 CONSTINFO((CKK_CAST5 | CKK_CAST128)),
575 CONSTINFO(CKK_RC5),
576 CONSTINFO(CKK_IDEA),
577 CONSTINFO(CKK_SKIPJACK),
578 CONSTINFO(CKK_BATON),
579 CONSTINFO(CKK_JUNIPER),
580 CONSTINFO(CKK_CDMF),
581 CONSTINFO(CKK_VENDOR_DEFINED),
582
583 };
584
585 static unsigned int PkcsKeySize =
586 (sizeof(PkcsKeyInfo) / sizeof(PkcsKeyInfo[0]));
587
588
589
590
591
592 static ConstInfo PkcsAttributeInfo[] = {
593 CONSTINFO(CKA_CLASS),
594 CONSTINFO(CKA_TOKEN),
595 CONSTINFO(CKA_PRIVATE),
596 CONSTINFO(CKA_LABEL),
597 CONSTINFO(CKA_APPLICATION),
598 CONSTINFO(CKA_VALUE),
599 CONSTINFO(CKA_CERTIFICATE_TYPE),
600 CONSTINFO(CKA_ISSUER),
601 CONSTINFO(CKA_SERIAL_NUMBER),
602 CONSTINFO(CKA_KEY_TYPE),
603 CONSTINFO(CKA_SUBJECT),
604 CONSTINFO(CKA_ID),
605 CONSTINFO(CKA_SENSITIVE),
606 CONSTINFO(CKA_ENCRYPT),
607 CONSTINFO(CKA_DECRYPT),
608 CONSTINFO(CKA_WRAP),
609 CONSTINFO(CKA_UNWRAP),
610 CONSTINFO(CKA_SIGN),
611 CONSTINFO(CKA_SIGN_RECOVER),
612 CONSTINFO(CKA_VERIFY),
613 CONSTINFO(CKA_VERIFY_RECOVER),
614 CONSTINFO(CKA_DERIVE),
615 CONSTINFO(CKA_START_DATE),
616 CONSTINFO(CKA_END_DATE),
617 CONSTINFO(CKA_MODULUS),
618 CONSTINFO(CKA_MODULUS_BITS),
619 CONSTINFO(CKA_PUBLIC_EXPONENT),
620 CONSTINFO(CKA_PRIVATE_EXPONENT),
621 CONSTINFO(CKA_PRIME_1),
622 CONSTINFO(CKA_PRIME_2),
623 CONSTINFO(CKA_EXPONENT_1),
624 CONSTINFO(CKA_EXPONENT_2),
625 CONSTINFO(CKA_COEFFICIENT),
626 CONSTINFO(CKA_PRIME),
627 CONSTINFO(CKA_SUBPRIME),
628 CONSTINFO(CKA_BASE),
629 CONSTINFO(CKA_VALUE_BITS),
630 CONSTINFO(CKA_VALUE_LEN),
631 CONSTINFO(CKA_EXTRACTABLE),
632 CONSTINFO(CKA_LOCAL),
633 CONSTINFO(CKA_NEVER_EXTRACTABLE),
634 CONSTINFO(CKA_ALWAYS_SENSITIVE),
635 CONSTINFO(CKA_MODIFIABLE),
636 CONSTINFO(CKA_ECDSA_PARAMS),
637 CONSTINFO(CKA_EC_POINT),
638 CONSTINFO(CKA_VENDOR_DEFINED),
639 CONSTINFO(CKA_IBM_OPAQUE),
640 CONSTINFO(CKA_IBM_RESTRICTABLE),
641 CONSTINFO(CKA_IBM_NEVER_MODIFIABLE),
642 CONSTINFO(CKA_IBM_RETAINKEY),
643 CONSTINFO(CKA_IBM_ATTRBOUND),
644 CONSTINFO(CKA_IBM_KEYTYPE),
645 CONSTINFO(CKA_IBM_CV),
646 CONSTINFO(CKA_IBM_MACKEY),
647 CONSTINFO(CKA_IBM_USE_AS_DATA),
648 CONSTINFO(CKA_IBM_STRUCT_PARAMS),
649 CONSTINFO(CKA_IBM_STD_COMPLIANCE1),
650 CONSTINFO(CKA_NSS_MOZILLA_CA_POLICY),
651 };
652
653
654 static unsigned int PkcsAttributeSize =
655 (sizeof(PkcsAttributeInfo) / sizeof(PkcsAttributeInfo[0]));
656
657 #if 0
658 static ConstInfo PkcsSessionStateInfo[] = {
659
660 CONSTINFO(CKS_RO_PUBLIC_SESSION),
661 CONSTINFO(CKS_RO_USER_FUNCTIONS),
662 CONSTINFO(CKS_RW_PUBLIC_SESSION),
663 CONSTINFO(CKS_RW_USER_FUNCTIONS),
664 CONSTINFO(CKS_RW_SO_FUNCTIONS),
665
666
667 };
668 #endif
669
670
671 static ConstInfo PkcsResponseSeverityInfo[] = {
672 {SEV_EXPECTED, "expected"},
673 {SEV_ALLOWED, "allowed"},
674 {SEV_ERROR, "an error"},
675 {SEV_FATAL, "fatal"},
676 };
677
678 static unsigned int PkcsResponseSeveritySize =
679 (sizeof(PkcsResponseSeverityInfo) / sizeof(PkcsResponseSeverityInfo[0]));
680
681
ConstName(pConstInfo pInfoArray,unsigned int InfoArraySize,unsigned int ConstValue)682 const unsigned char *ConstName(pConstInfo pInfoArray,
683 unsigned int InfoArraySize,
684 unsigned int ConstValue)
685 {
686
687 unsigned int i;
688 unsigned const char *retval = NULL;
689
690
691 for (i = 0; i < InfoArraySize; i++) {
692 if (pInfoArray[i].Code == ConstValue) {
693 retval = (unsigned char *)&(pInfoArray[i].Name[0]);
694 break;
695 }
696 /* end if */
697 } /* end for i */
698
699 if (retval == NULL) {
700 if (ConstValue == 0) {
701 retval = (const unsigned char *) "NULL";
702 } else {
703 retval = (const unsigned char *) "\"<*>CONSTANT NOT FOUND<*>\"";
704 }
705 }
706
707 return retval;
708 }
709
SignalConst(unsigned int Val)710 const unsigned char *SignalConst(unsigned int Val)
711 {
712 return ConstName(SignalInfo, SignalInfoSize, Val);
713 }
714
SysConst(unsigned int Val)715 const unsigned char *SysConst(unsigned int Val)
716 {
717 return ConstName(SysErrorInfo, SysErrorSize, Val);
718 }
719
720
721
PkcsReturn(unsigned int Val)722 const unsigned char *PkcsReturn(unsigned int Val)
723 {
724 return ConstName(PkcsReturnInfo, PkcsReturnSize, Val);
725 }
726
PkcsFlags(unsigned int Val)727 const unsigned char *PkcsFlags(unsigned int Val)
728 {
729 return ConstName(PkcsFlagsInfo, PkcsFlagsSize, Val);
730 }
731
PkcsMechanism(unsigned int Val)732 const unsigned char *PkcsMechanism(unsigned int Val)
733 {
734 return ConstName(PkcsMechanismInfo, PkcsMechanismSize, Val);
735 }
736
PkcsObject(unsigned int Val)737 const unsigned char *PkcsObject(unsigned int Val)
738 {
739 return ConstName(PkcsObjectInfo, PkcsObjectSize, Val);
740 }
741
PkcsKey(unsigned int Val)742 const unsigned char *PkcsKey(unsigned int Val)
743 {
744 return ConstName(PkcsKeyInfo, PkcsKeySize, Val);
745 }
746
PkcsAttribute(unsigned int Val)747 const unsigned char *PkcsAttribute(unsigned int Val)
748 {
749 return ConstName(PkcsAttributeInfo, PkcsAttributeSize, Val);
750 }
751
ResponseSeverity(unsigned int Val)752 const unsigned char *ResponseSeverity(unsigned int Val)
753 {
754 return ConstName(PkcsResponseSeverityInfo, PkcsResponseSeveritySize, Val);
755 }
756