1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/tests/pkcs11/netscape/trivial/trivial.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1280 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/* 1.9 + * This is a very trivial program I wrote for testing out a 1.10 + * couple data-only Cryptoki modules for NSS. It's not a "real" 1.11 + * test program that prints out nice "PASS" or "FAIL" messages; 1.12 + * it just makes calls and dumps data. 1.13 + */ 1.14 + 1.15 +#include "config.h" 1.16 + 1.17 +#ifdef HAVE_NSPR_H 1.18 +#include "nspr.h" 1.19 +#else 1.20 +#error "NSPR is required." 1.21 +#endif 1.22 + 1.23 +#ifdef WITH_NSS 1.24 +#define FGMR 1 1.25 +#include "ck.h" 1.26 +#else 1.27 +#include "pkcs11t.h" 1.28 +#include "pkcs11.h" 1.29 +#endif 1.30 + 1.31 +/* The RSA versions are sloppier with namespaces */ 1.32 +#ifndef CK_TRUE 1.33 +#define CK_TRUE TRUE 1.34 +#endif 1.35 + 1.36 +#ifndef CK_FALSE 1.37 +#define CK_FALSE FALSE 1.38 +#endif 1.39 + 1.40 +int 1.41 +rmain 1.42 +( 1.43 + int argc, 1.44 + char *argv[] 1.45 +); 1.46 + 1.47 +int 1.48 +main 1.49 +( 1.50 + int argc, 1.51 + char *argv[] 1.52 +) 1.53 +{ 1.54 + int rv = 0; 1.55 + 1.56 + PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 14); 1.57 + rv = rmain(argc, argv); 1.58 + PR_Cleanup(); 1.59 + 1.60 + return rv; 1.61 +} 1.62 + 1.63 +static CK_ATTRIBUTE_TYPE all_known_attribute_types[] = { 1.64 + CKA_CLASS, 1.65 + CKA_TOKEN, 1.66 + CKA_PRIVATE, 1.67 + CKA_LABEL, 1.68 + CKA_APPLICATION, 1.69 + CKA_VALUE, 1.70 + CKA_CERTIFICATE_TYPE, 1.71 + CKA_ISSUER, 1.72 + CKA_SERIAL_NUMBER, 1.73 + CKA_KEY_TYPE, 1.74 + CKA_SUBJECT, 1.75 + CKA_ID, 1.76 + CKA_SENSITIVE, 1.77 + CKA_ENCRYPT, 1.78 + CKA_DECRYPT, 1.79 + CKA_WRAP, 1.80 + CKA_UNWRAP, 1.81 + CKA_SIGN, 1.82 + CKA_SIGN_RECOVER, 1.83 + CKA_VERIFY, 1.84 + CKA_VERIFY_RECOVER, 1.85 + CKA_DERIVE, 1.86 + CKA_START_DATE, 1.87 + CKA_END_DATE, 1.88 + CKA_MODULUS, 1.89 + CKA_MODULUS_BITS, 1.90 + CKA_PUBLIC_EXPONENT, 1.91 + CKA_PRIVATE_EXPONENT, 1.92 + CKA_PRIME_1, 1.93 + CKA_PRIME_2, 1.94 + CKA_EXPONENT_1, 1.95 + CKA_EXPONENT_2, 1.96 + CKA_COEFFICIENT, 1.97 + CKA_PRIME, 1.98 + CKA_SUBPRIME, 1.99 + CKA_BASE, 1.100 + CKA_VALUE_BITS, 1.101 + CKA_VALUE_LEN, 1.102 + CKA_EXTRACTABLE, 1.103 + CKA_LOCAL, 1.104 + CKA_NEVER_EXTRACTABLE, 1.105 + CKA_ALWAYS_SENSITIVE, 1.106 + CKA_MODIFIABLE, 1.107 +#ifdef CKA_NETSCAPE 1.108 + CKA_NETSCAPE_URL, 1.109 + CKA_NETSCAPE_EMAIL, 1.110 + CKA_NETSCAPE_SMIME_INFO, 1.111 + CKA_NETSCAPE_SMIME_TIMESTAMP, 1.112 + CKA_NETSCAPE_PKCS8_SALT, 1.113 + CKA_NETSCAPE_PASSWORD_CHECK, 1.114 + CKA_NETSCAPE_EXPIRES, 1.115 +#endif /* CKA_NETSCAPE */ 1.116 +#ifdef CKA_TRUST 1.117 + CKA_TRUST_DIGITAL_SIGNATURE, 1.118 + CKA_TRUST_NON_REPUDIATION, 1.119 + CKA_TRUST_KEY_ENCIPHERMENT, 1.120 + CKA_TRUST_DATA_ENCIPHERMENT, 1.121 + CKA_TRUST_KEY_AGREEMENT, 1.122 + CKA_TRUST_KEY_CERT_SIGN, 1.123 + CKA_TRUST_CRL_SIGN, 1.124 + CKA_TRUST_SERVER_AUTH, 1.125 + CKA_TRUST_CLIENT_AUTH, 1.126 + CKA_TRUST_CODE_SIGNING, 1.127 + CKA_TRUST_EMAIL_PROTECTION, 1.128 + CKA_TRUST_IPSEC_END_SYSTEM, 1.129 + CKA_TRUST_IPSEC_TUNNEL, 1.130 + CKA_TRUST_IPSEC_USER, 1.131 + CKA_TRUST_TIME_STAMPING, 1.132 +#endif /* CKA_TRUST */ 1.133 +}; 1.134 + 1.135 +static number_of_all_known_attribute_types = 1.136 + (sizeof(all_known_attribute_types)/sizeof(all_known_attribute_types[0])); 1.137 + 1.138 +int 1.139 +usage 1.140 +( 1.141 + char *argv0 1.142 +) 1.143 +{ 1.144 + PR_fprintf(PR_STDERR, "Usage: %s [-i {string|--}] <library>.so\n", argv0); 1.145 + return 1; 1.146 +} 1.147 + 1.148 +int 1.149 +rmain 1.150 +( 1.151 + int argc, 1.152 + char *argv[] 1.153 +) 1.154 +{ 1.155 + char *argv0 = argv[0]; 1.156 + PRLibrary *lib; 1.157 + CK_C_GetFunctionList gfl; 1.158 + CK_FUNCTION_LIST_PTR epv = (CK_FUNCTION_LIST_PTR)NULL; 1.159 + CK_RV ck_rv; 1.160 + CK_INFO info; 1.161 + CK_ULONG nSlots; 1.162 + CK_SLOT_ID *pSlots; 1.163 + CK_ULONG i; 1.164 + CK_C_INITIALIZE_ARGS ia, *iap; 1.165 + 1.166 + (void)memset(&ia, 0, sizeof(CK_C_INITIALIZE_ARGS)); 1.167 + iap = (CK_C_INITIALIZE_ARGS *)NULL; 1.168 + while( argv++, --argc ) { 1.169 + if( '-' == argv[0][0] ) { 1.170 + switch( argv[0][1] ) { 1.171 + case 'i': 1.172 + iap = &ia; 1.173 + if( ((char *)NULL != argv[1]) && ('-' != argv[1][0]) ) { 1.174 +#ifdef WITH_NSS 1.175 + ia.pConfig = argv[1]; 1.176 + ia.ulConfigLen = strlen(argv[1]); 1.177 + argv++, --argc; 1.178 +#else 1.179 + return usage(argv0); 1.180 +#endif /* WITH_NSS */ 1.181 + } 1.182 + break; 1.183 + case '-': 1.184 + argv++, --argc; 1.185 + goto endargs; 1.186 + default: 1.187 + return usage(argv0); 1.188 + } 1.189 + } else { 1.190 + break; 1.191 + } 1.192 + } 1.193 + endargs:; 1.194 + 1.195 + if( 1 != argc ) { 1.196 + return usage(argv0); 1.197 + } 1.198 + 1.199 + lib = PR_LoadLibrary(argv[0]); 1.200 + if( (PRLibrary *)NULL == lib ) { 1.201 + PR_fprintf(PR_STDERR, "Can't load %s: %ld, %ld\n", argv[1], PR_GetError(), PR_GetOSError()); 1.202 + return 1; 1.203 + } 1.204 + 1.205 + gfl = (CK_C_GetFunctionList)PR_FindSymbol(lib, "C_GetFunctionList"); 1.206 + if( (CK_C_GetFunctionList)NULL == gfl ) { 1.207 + PR_fprintf(PR_STDERR, "Can't find C_GetFunctionList in %s: %ld, %ld\n", argv[1], 1.208 + PR_GetError(), PR_GetOSError()); 1.209 + return 1; 1.210 + } 1.211 + 1.212 + ck_rv = (*gfl)(&epv); 1.213 + if( CKR_OK != ck_rv ) { 1.214 + PR_fprintf(PR_STDERR, "CK_GetFunctionList returned 0x%08x\n", ck_rv); 1.215 + return 1; 1.216 + } 1.217 + 1.218 + PR_fprintf(PR_STDOUT, "Module %s loaded, epv = 0x%08x.\n\n", argv[1], (CK_ULONG)epv); 1.219 + 1.220 + /* C_Initialize */ 1.221 + ck_rv = epv->C_Initialize(iap); 1.222 + if( CKR_OK != ck_rv ) { 1.223 + PR_fprintf(PR_STDERR, "C_Initialize returned 0x%08x\n", ck_rv); 1.224 + return 1; 1.225 + } 1.226 + 1.227 + /* C_GetInfo */ 1.228 + (void)memset(&info, 0, sizeof(CK_INFO)); 1.229 + ck_rv = epv->C_GetInfo(&info); 1.230 + if( CKR_OK != ck_rv ) { 1.231 + PR_fprintf(PR_STDERR, "C_GetInfo returned 0x%08x\n", ck_rv); 1.232 + return 1; 1.233 + } 1.234 + 1.235 + PR_fprintf(PR_STDOUT, "Module Info:\n"); 1.236 + PR_fprintf(PR_STDOUT, " cryptokiVersion = %lu.%02lu\n", 1.237 + (PRUint32)info.cryptokiVersion.major, (PRUint32)info.cryptokiVersion.minor); 1.238 + PR_fprintf(PR_STDOUT, " manufacturerID = \"%.32s\"\n", info.manufacturerID); 1.239 + PR_fprintf(PR_STDOUT, " flags = 0x%08lx\n", info.flags); 1.240 + PR_fprintf(PR_STDOUT, " libraryDescription = \"%.32s\"\n", info.libraryDescription); 1.241 + PR_fprintf(PR_STDOUT, " libraryVersion = %lu.%02lu\n", 1.242 + (PRUint32)info.libraryVersion.major, (PRUint32)info.libraryVersion.minor); 1.243 + PR_fprintf(PR_STDOUT, "\n"); 1.244 + 1.245 + /* C_GetSlotList */ 1.246 + nSlots = 0; 1.247 + ck_rv = epv->C_GetSlotList(CK_FALSE, (CK_SLOT_ID_PTR)CK_NULL_PTR, &nSlots); 1.248 + switch( ck_rv ) { 1.249 + case CKR_BUFFER_TOO_SMALL: 1.250 + case CKR_OK: 1.251 + break; 1.252 + default: 1.253 + PR_fprintf(PR_STDERR, "C_GetSlotList(FALSE, NULL, ) returned 0x%08x\n", ck_rv); 1.254 + return 1; 1.255 + } 1.256 + 1.257 + PR_fprintf(PR_STDOUT, "There are %lu slots.\n", nSlots); 1.258 + 1.259 + pSlots = (CK_SLOT_ID_PTR)PR_Calloc(nSlots, sizeof(CK_SLOT_ID)); 1.260 + if( (CK_SLOT_ID_PTR)NULL == pSlots ) { 1.261 + PR_fprintf(PR_STDERR, "[memory allocation of %lu bytes failed]\n", nSlots * sizeof(CK_SLOT_ID)); 1.262 + return 1; 1.263 + } 1.264 + 1.265 + ck_rv = epv->C_GetSlotList(CK_FALSE, pSlots, &nSlots); 1.266 + if( CKR_OK != ck_rv ) { 1.267 + PR_fprintf(PR_STDERR, "C_GetSlotList(FALSE, , ) returned 0x%08x\n", ck_rv); 1.268 + return 1; 1.269 + } 1.270 + 1.271 + for( i = 0; i < nSlots; i++ ) { 1.272 + PR_fprintf(PR_STDOUT, " [%lu]: CK_SLOT_ID = %lu\n", (i+1), pSlots[i]); 1.273 + } 1.274 + 1.275 + PR_fprintf(PR_STDOUT, "\n"); 1.276 + 1.277 + /* C_GetSlotInfo */ 1.278 + for( i = 0; i < nSlots; i++ ) { 1.279 + CK_SLOT_INFO sinfo; 1.280 + 1.281 + PR_fprintf(PR_STDOUT, "[%lu]: CK_SLOT_ID = %lu\n", (i+1), pSlots[i]); 1.282 + 1.283 + (void)memset(&sinfo, 0, sizeof(CK_SLOT_INFO)); 1.284 + ck_rv = epv->C_GetSlotInfo(pSlots[i], &sinfo); 1.285 + if( CKR_OK != ck_rv ) { 1.286 + PR_fprintf(PR_STDERR, "C_GetSlotInfo(%lu, ) returned 0x%08x\n", pSlots[i], ck_rv); 1.287 + return 1; 1.288 + } 1.289 + 1.290 + PR_fprintf(PR_STDOUT, " Slot Info:\n"); 1.291 + PR_fprintf(PR_STDOUT, " slotDescription = \"%.64s\"\n", sinfo.slotDescription); 1.292 + PR_fprintf(PR_STDOUT, " manufacturerID = \"%.32s\"\n", sinfo.manufacturerID); 1.293 + PR_fprintf(PR_STDOUT, " flags = 0x%08lx\n", sinfo.flags); 1.294 + PR_fprintf(PR_STDOUT, " -> TOKEN PRESENT = %s\n", 1.295 + sinfo.flags & CKF_TOKEN_PRESENT ? "TRUE" : "FALSE"); 1.296 + PR_fprintf(PR_STDOUT, " -> REMOVABLE DEVICE = %s\n", 1.297 + sinfo.flags & CKF_REMOVABLE_DEVICE ? "TRUE" : "FALSE"); 1.298 + PR_fprintf(PR_STDOUT, " -> HW SLOT = %s\n", 1.299 + sinfo.flags & CKF_HW_SLOT ? "TRUE" : "FALSE"); 1.300 + PR_fprintf(PR_STDOUT, " hardwareVersion = %lu.%02lu\n", 1.301 + (PRUint32)sinfo.hardwareVersion.major, (PRUint32)sinfo.hardwareVersion.minor); 1.302 + PR_fprintf(PR_STDOUT, " firmwareVersion = %lu.%02lu\n", 1.303 + (PRUint32)sinfo.firmwareVersion.major, (PRUint32)sinfo.firmwareVersion.minor); 1.304 + 1.305 + if( sinfo.flags & CKF_TOKEN_PRESENT ) { 1.306 + CK_TOKEN_INFO tinfo; 1.307 + CK_MECHANISM_TYPE *pMechanismList; 1.308 + CK_ULONG nMechanisms = 0; 1.309 + CK_ULONG j; 1.310 + 1.311 + (void)memset(&tinfo, 0, sizeof(CK_TOKEN_INFO)); 1.312 + ck_rv = epv->C_GetTokenInfo(pSlots[i], &tinfo); 1.313 + if( CKR_OK != ck_rv ) { 1.314 + PR_fprintf(PR_STDERR, "C_GetTokenInfo(%lu, ) returned 0x%08x\n", pSlots[i], ck_rv); 1.315 + return 1; 1.316 + } 1.317 + 1.318 + PR_fprintf(PR_STDOUT, " Token Info:\n"); 1.319 + PR_fprintf(PR_STDOUT, " label = \"%.32s\"\n", tinfo.label); 1.320 + PR_fprintf(PR_STDOUT, " manufacturerID = \"%.32s\"\n", tinfo.manufacturerID); 1.321 + PR_fprintf(PR_STDOUT, " model = \"%.16s\"\n", tinfo.model); 1.322 + PR_fprintf(PR_STDOUT, " serialNumber = \"%.16s\"\n", tinfo.serialNumber); 1.323 + PR_fprintf(PR_STDOUT, " flags = 0x%08lx\n", tinfo.flags); 1.324 + PR_fprintf(PR_STDOUT, " -> RNG = %s\n", 1.325 + tinfo.flags & CKF_RNG ? "TRUE" : "FALSE"); 1.326 + PR_fprintf(PR_STDOUT, " -> WRITE PROTECTED = %s\n", 1.327 + tinfo.flags & CKF_WRITE_PROTECTED ? "TRUE" : "FALSE"); 1.328 + PR_fprintf(PR_STDOUT, " -> LOGIN REQUIRED = %s\n", 1.329 + tinfo.flags & CKF_LOGIN_REQUIRED ? "TRUE" : "FALSE"); 1.330 + PR_fprintf(PR_STDOUT, " -> USER PIN INITIALIZED = %s\n", 1.331 + tinfo.flags & CKF_USER_PIN_INITIALIZED ? "TRUE" : "FALSE"); 1.332 + PR_fprintf(PR_STDOUT, " -> RESTORE KEY NOT NEEDED = %s\n", 1.333 + tinfo.flags & CKF_RESTORE_KEY_NOT_NEEDED ? "TRUE" : "FALSE"); 1.334 + PR_fprintf(PR_STDOUT, " -> CLOCK ON TOKEN = %s\n", 1.335 + tinfo.flags & CKF_CLOCK_ON_TOKEN ? "TRUE" : "FALSE"); 1.336 +#ifdef CKF_SUPPORTS_PARALLEL 1.337 + PR_fprintf(PR_STDOUT, " -> SUPPORTS PARALLEL = %s\n", 1.338 + tinfo.flags & CKF_SUPPORTS_PARALLEL ? "TRUE" : "FALSE"); 1.339 +#endif /* CKF_SUPPORTS_PARALLEL */ 1.340 + PR_fprintf(PR_STDOUT, " -> PROTECTED AUTHENTICATION PATH = %s\n", 1.341 + tinfo.flags & CKF_PROTECTED_AUTHENTICATION_PATH ? "TRUE" : "FALSE"); 1.342 + PR_fprintf(PR_STDOUT, " -> DUAL_CRYPTO_OPERATIONS = %s\n", 1.343 + tinfo.flags & CKF_DUAL_CRYPTO_OPERATIONS ? "TRUE" : "FALSE"); 1.344 + PR_fprintf(PR_STDOUT, " ulMaxSessionCount = %lu\n", tinfo.ulMaxSessionCount); 1.345 + PR_fprintf(PR_STDOUT, " ulSessionCount = %lu\n", tinfo.ulSessionCount); 1.346 + PR_fprintf(PR_STDOUT, " ulMaxRwSessionCount = %lu\n", tinfo.ulMaxRwSessionCount); 1.347 + PR_fprintf(PR_STDOUT, " ulRwSessionCount = %lu\n", tinfo.ulRwSessionCount); 1.348 + PR_fprintf(PR_STDOUT, " ulMaxPinLen = %lu\n", tinfo.ulMaxPinLen); 1.349 + PR_fprintf(PR_STDOUT, " ulMinPinLen = %lu\n", tinfo.ulMinPinLen); 1.350 + PR_fprintf(PR_STDOUT, " ulTotalPublicMemory = %lu\n", tinfo.ulTotalPublicMemory); 1.351 + PR_fprintf(PR_STDOUT, " ulFreePublicMemory = %lu\n", tinfo.ulFreePublicMemory); 1.352 + PR_fprintf(PR_STDOUT, " ulTotalPrivateMemory = %lu\n", tinfo.ulTotalPrivateMemory); 1.353 + PR_fprintf(PR_STDOUT, " ulFreePrivateMemory = %lu\n", tinfo.ulFreePrivateMemory); 1.354 + PR_fprintf(PR_STDOUT, " hardwareVersion = %lu.%02lu\n", 1.355 + (PRUint32)tinfo.hardwareVersion.major, (PRUint32)tinfo.hardwareVersion.minor); 1.356 + PR_fprintf(PR_STDOUT, " firmwareVersion = %lu.%02lu\n", 1.357 + (PRUint32)tinfo.firmwareVersion.major, (PRUint32)tinfo.firmwareVersion.minor); 1.358 + PR_fprintf(PR_STDOUT, " utcTime = \"%.16s\"\n", tinfo.utcTime); 1.359 + 1.360 + 1.361 + ck_rv = epv->C_GetMechanismList(pSlots[i], (CK_MECHANISM_TYPE_PTR)CK_NULL_PTR, &nMechanisms); 1.362 + switch( ck_rv ) { 1.363 + case CKR_BUFFER_TOO_SMALL: 1.364 + case CKR_OK: 1.365 + break; 1.366 + default: 1.367 + PR_fprintf(PR_STDERR, "C_GetMechanismList(%lu, NULL, ) returned 0x%08x\n", pSlots[i], ck_rv); 1.368 + return 1; 1.369 + } 1.370 + 1.371 + PR_fprintf(PR_STDOUT, " %lu mechanisms:\n", nMechanisms); 1.372 + 1.373 + pMechanismList = (CK_MECHANISM_TYPE_PTR)PR_Calloc(nMechanisms, sizeof(CK_MECHANISM_TYPE)); 1.374 + if( (CK_MECHANISM_TYPE_PTR)NULL == pMechanismList ) { 1.375 + PR_fprintf(PR_STDERR, "[memory allocation of %lu bytes failed]\n", 1.376 + nMechanisms * sizeof(CK_MECHANISM_TYPE)); 1.377 + return 1; 1.378 + } 1.379 + 1.380 + ck_rv = epv->C_GetMechanismList(pSlots[i], pMechanismList, &nMechanisms); 1.381 + if( CKR_OK != ck_rv ) { 1.382 + PR_fprintf(PR_STDERR, "C_GetMechanismList(%lu, , ) returned 0x%08x\n", pSlots[i], ck_rv); 1.383 + return 1; 1.384 + } 1.385 + 1.386 + for( j = 0; j < nMechanisms; j++ ) { 1.387 + PR_fprintf(PR_STDOUT, " {%lu}: CK_MECHANISM_TYPE = %lu\n", (j+1), pMechanismList[j]); 1.388 + } 1.389 + 1.390 + PR_fprintf(PR_STDOUT, "\n"); 1.391 + 1.392 + for( j = 0; j < nMechanisms; j++ ) { 1.393 + CK_MECHANISM_INFO minfo; 1.394 + 1.395 + (void)memset(&minfo, 0, sizeof(CK_MECHANISM_INFO)); 1.396 + ck_rv = epv->C_GetMechanismInfo(pSlots[i], pMechanismList[j], &minfo); 1.397 + if( CKR_OK != ck_rv ) { 1.398 + PR_fprintf(PR_STDERR, "C_GetMechanismInfo(%lu, %lu, ) returned 0x%08x\n", pSlots[i], 1.399 + pMechanismList[j]); 1.400 + return 1; 1.401 + } 1.402 + 1.403 + PR_fprintf(PR_STDOUT, " [%lu]: CK_MECHANISM_TYPE = %lu\n", (j+1), pMechanismList[j]); 1.404 + PR_fprintf(PR_STDOUT, " ulMinKeySize = %lu\n", minfo.ulMinKeySize); 1.405 + PR_fprintf(PR_STDOUT, " ulMaxKeySize = %lu\n", minfo.ulMaxKeySize); 1.406 + PR_fprintf(PR_STDOUT, " flags = 0x%08x\n", minfo.flags); 1.407 + PR_fprintf(PR_STDOUT, " -> HW = %s\n", minfo.flags & CKF_HW ? "TRUE" : "FALSE"); 1.408 + PR_fprintf(PR_STDOUT, " -> ENCRYPT = %s\n", minfo.flags & CKF_ENCRYPT ? "TRUE" : "FALSE"); 1.409 + PR_fprintf(PR_STDOUT, " -> DECRYPT = %s\n", minfo.flags & CKF_DECRYPT ? "TRUE" : "FALSE"); 1.410 + PR_fprintf(PR_STDOUT, " -> DIGEST = %s\n", minfo.flags & CKF_DIGEST ? "TRUE" : "FALSE"); 1.411 + PR_fprintf(PR_STDOUT, " -> SIGN = %s\n", minfo.flags & CKF_SIGN ? "TRUE" : "FALSE"); 1.412 + PR_fprintf(PR_STDOUT, " -> SIGN_RECOVER = %s\n", minfo.flags & CKF_SIGN_RECOVER ? "TRUE" : "FALSE"); 1.413 + PR_fprintf(PR_STDOUT, " -> VERIFY = %s\n", minfo.flags & CKF_VERIFY ? "TRUE" : "FALSE"); 1.414 + PR_fprintf(PR_STDOUT, " -> VERIFY_RECOVER = %s\n", minfo.flags & CKF_VERIFY_RECOVER ? "TRUE" : "FALSE"); 1.415 + PR_fprintf(PR_STDOUT, " -> GENERATE = %s\n", minfo.flags & CKF_GENERATE ? "TRUE" : "FALSE"); 1.416 + PR_fprintf(PR_STDOUT, " -> GENERATE_KEY_PAIR = %s\n", minfo.flags & CKF_GENERATE_KEY_PAIR ? "TRUE" : "FALSE"); 1.417 + PR_fprintf(PR_STDOUT, " -> WRAP = %s\n", minfo.flags & CKF_WRAP ? "TRUE" : "FALSE"); 1.418 + PR_fprintf(PR_STDOUT, " -> UNWRAP = %s\n", minfo.flags & CKF_UNWRAP ? "TRUE" : "FALSE"); 1.419 + PR_fprintf(PR_STDOUT, " -> DERIVE = %s\n", minfo.flags & CKF_DERIVE ? "TRUE" : "FALSE"); 1.420 + PR_fprintf(PR_STDOUT, " -> EXTENSION = %s\n", minfo.flags & CKF_EXTENSION ? "TRUE" : "FALSE"); 1.421 + 1.422 + PR_fprintf(PR_STDOUT, "\n"); 1.423 + } 1.424 + 1.425 + if( tinfo.flags & CKF_LOGIN_REQUIRED ) { 1.426 + PR_fprintf(PR_STDERR, "*** LOGIN REQUIRED but not yet implemented ***\n"); 1.427 + /* all the stuff about logging in as SO and setting the user pin if needed, etc. */ 1.428 + return 2; 1.429 + } 1.430 + 1.431 + /* session to find objects */ 1.432 + { 1.433 + CK_SESSION_HANDLE h = (CK_SESSION_HANDLE)0; 1.434 + CK_SESSION_INFO sinfo; 1.435 + CK_ATTRIBUTE_PTR pTemplate; 1.436 + CK_ULONG tnObjects = 0; 1.437 + 1.438 + ck_rv = epv->C_OpenSession(pSlots[i], CKF_SERIAL_SESSION, (CK_VOID_PTR)CK_NULL_PTR, (CK_NOTIFY)CK_NULL_PTR, &h); 1.439 + if( CKR_OK != ck_rv ) { 1.440 + PR_fprintf(PR_STDERR, "C_OpenSession(%lu, CKF_SERIAL_SESSION, , ) returned 0x%08x\n", pSlots[i], ck_rv); 1.441 + return 1; 1.442 + } 1.443 + 1.444 + PR_fprintf(PR_STDOUT, " Opened a session: handle = 0x%08x\n", h); 1.445 + 1.446 + (void)memset(&sinfo, 0, sizeof(CK_SESSION_INFO)); 1.447 + ck_rv = epv->C_GetSessionInfo(h, &sinfo); 1.448 + if( CKR_OK != ck_rv ) { 1.449 + PR_fprintf(PR_STDOUT, "C_GetSessionInfo(%lu, ) returned 0x%08x\n", h, ck_rv); 1.450 + return 1; 1.451 + } 1.452 + 1.453 + PR_fprintf(PR_STDOUT, " SESSION INFO:\n"); 1.454 + PR_fprintf(PR_STDOUT, " slotID = %lu\n", sinfo.slotID); 1.455 + PR_fprintf(PR_STDOUT, " state = %lu\n", sinfo.state); 1.456 + PR_fprintf(PR_STDOUT, " flags = 0x%08x\n", sinfo.flags); 1.457 +#ifdef CKF_EXCLUSIVE_SESSION 1.458 + PR_fprintf(PR_STDOUT, " -> EXCLUSIVE SESSION = %s\n", sinfo.flags & CKF_EXCLUSIVE_SESSION ? "TRUE" : "FALSE"); 1.459 +#endif /* CKF_EXCLUSIVE_SESSION */ 1.460 + PR_fprintf(PR_STDOUT, " -> RW SESSION = %s\n", sinfo.flags & CKF_RW_SESSION ? "TRUE" : "FALSE"); 1.461 + PR_fprintf(PR_STDOUT, " -> SERIAL SESSION = %s\n", sinfo.flags & CKF_SERIAL_SESSION ? "TRUE" : "FALSE"); 1.462 +#ifdef CKF_INSERTION_CALLBACK 1.463 + PR_fprintf(PR_STDOUT, " -> INSERTION CALLBACK = %s\n", sinfo.flags & CKF_INSERTION_CALLBACK ? "TRUE" : "FALSE"); 1.464 +#endif /* CKF_INSERTION_CALLBACK */ 1.465 + PR_fprintf(PR_STDOUT, " ulDeviceError = %lu\n", sinfo.ulDeviceError); 1.466 + PR_fprintf(PR_STDOUT, "\n"); 1.467 + 1.468 + ck_rv = epv->C_FindObjectsInit(h, (CK_ATTRIBUTE_PTR)CK_NULL_PTR, 0); 1.469 + if( CKR_OK != ck_rv ) { 1.470 + PR_fprintf(PR_STDOUT, "C_FindObjectsInit(%lu, NULL_PTR, 0) returned 0x%08x\n", h, ck_rv); 1.471 + return 1; 1.472 + } 1.473 + 1.474 + pTemplate = (CK_ATTRIBUTE_PTR)PR_Calloc(number_of_all_known_attribute_types, sizeof(CK_ATTRIBUTE)); 1.475 + if( (CK_ATTRIBUTE_PTR)NULL == pTemplate ) { 1.476 + PR_fprintf(PR_STDERR, "[memory allocation of %lu bytes failed]\n", 1.477 + number_of_all_known_attribute_types * sizeof(CK_ATTRIBUTE)); 1.478 + return 1; 1.479 + } 1.480 + 1.481 + PR_fprintf(PR_STDOUT, " All objects:\n"); 1.482 + 1.483 + while(1) { 1.484 + CK_OBJECT_HANDLE o = (CK_OBJECT_HANDLE)0; 1.485 + CK_ULONG nObjects = 0; 1.486 + CK_ULONG k; 1.487 + CK_ULONG nAttributes = 0; 1.488 + CK_ATTRIBUTE_PTR pT2; 1.489 + CK_ULONG l; 1.490 + 1.491 + ck_rv = epv->C_FindObjects(h, &o, 1, &nObjects); 1.492 + if( CKR_OK != ck_rv ) { 1.493 + PR_fprintf(PR_STDERR, "C_FindObjects(%lu, , 1, ) returned 0x%08x\n", h, ck_rv); 1.494 + return 1; 1.495 + } 1.496 + 1.497 + if( 0 == nObjects ) { 1.498 + PR_fprintf(PR_STDOUT, "\n"); 1.499 + break; 1.500 + } 1.501 + 1.502 + tnObjects++; 1.503 + 1.504 + PR_fprintf(PR_STDOUT, " OBJECT HANDLE %lu:\n", o); 1.505 + 1.506 + for( k = 0; k < number_of_all_known_attribute_types; k++ ) { 1.507 + pTemplate[k].type = all_known_attribute_types[k]; 1.508 + pTemplate[k].pValue = (CK_VOID_PTR)CK_NULL_PTR; 1.509 + pTemplate[k].ulValueLen = 0; 1.510 + } 1.511 + 1.512 + ck_rv = epv->C_GetAttributeValue(h, o, pTemplate, number_of_all_known_attribute_types); 1.513 + switch( ck_rv ) { 1.514 + case CKR_OK: 1.515 + case CKR_ATTRIBUTE_SENSITIVE: 1.516 + case CKR_ATTRIBUTE_TYPE_INVALID: 1.517 + case CKR_BUFFER_TOO_SMALL: 1.518 + break; 1.519 + default: 1.520 + PR_fprintf(PR_STDERR, "C_GetAtributeValue(%lu, %lu, {all attribute types}, %lu) returned 0x%08x\n", 1.521 + h, o, number_of_all_known_attribute_types, ck_rv); 1.522 + return 1; 1.523 + } 1.524 + 1.525 + for( k = 0; k < number_of_all_known_attribute_types; k++ ) { 1.526 + if( -1 != (CK_LONG)pTemplate[k].ulValueLen ) { 1.527 + nAttributes++; 1.528 + } 1.529 + } 1.530 + 1.531 + if( 1 ) { 1.532 + PR_fprintf(PR_STDOUT, " %lu attributes:\n", nAttributes); 1.533 + for( k = 0; k < number_of_all_known_attribute_types; k++ ) { 1.534 + if( -1 != (CK_LONG)pTemplate[k].ulValueLen ) { 1.535 + PR_fprintf(PR_STDOUT, " 0x%08x (len = %lu)\n", pTemplate[k].type, 1.536 + pTemplate[k].ulValueLen); 1.537 + } 1.538 + } 1.539 + PR_fprintf(PR_STDOUT, "\n"); 1.540 + } 1.541 + 1.542 + pT2 = (CK_ATTRIBUTE_PTR)PR_Calloc(nAttributes, sizeof(CK_ATTRIBUTE)); 1.543 + if( (CK_ATTRIBUTE_PTR)NULL == pT2 ) { 1.544 + PR_fprintf(PR_STDERR, "[memory allocation of %lu bytes failed]\n", 1.545 + nAttributes * sizeof(CK_ATTRIBUTE)); 1.546 + return 1; 1.547 + } 1.548 + 1.549 + for( l = 0, k = 0; k < number_of_all_known_attribute_types; k++ ) { 1.550 + if( -1 != (CK_LONG)pTemplate[k].ulValueLen ) { 1.551 + pT2[l].type = pTemplate[k].type; 1.552 + pT2[l].ulValueLen = pTemplate[k].ulValueLen; 1.553 + pT2[l].pValue = (CK_VOID_PTR)PR_Malloc(pT2[l].ulValueLen); 1.554 + if( (CK_VOID_PTR)NULL == pT2[l].pValue ) { 1.555 + PR_fprintf(PR_STDERR, "[memory allocation of %lu bytes failed]\n", pT2[l].ulValueLen); 1.556 + return 1; 1.557 + } 1.558 + l++; 1.559 + } 1.560 + } 1.561 + 1.562 + PR_ASSERT( l == nAttributes ); 1.563 + 1.564 + ck_rv = epv->C_GetAttributeValue(h, o, pT2, nAttributes); 1.565 + switch( ck_rv ) { 1.566 + case CKR_OK: 1.567 + case CKR_ATTRIBUTE_SENSITIVE: 1.568 + case CKR_ATTRIBUTE_TYPE_INVALID: 1.569 + case CKR_BUFFER_TOO_SMALL: 1.570 + break; 1.571 + default: 1.572 + PR_fprintf(PR_STDERR, "C_GetAtributeValue(%lu, %lu, {existent attribute types}, %lu) returned 0x%08x\n", 1.573 + h, o, nAttributes, ck_rv); 1.574 + return 1; 1.575 + } 1.576 + 1.577 + for( l = 0; l < nAttributes; l++ ) { 1.578 + PR_fprintf(PR_STDOUT, " type = 0x%08x, len = %ld", pT2[l].type, (CK_LONG)pT2[l].ulValueLen); 1.579 + if( -1 == (CK_LONG)pT2[l].ulValueLen ) { 1.580 + ; 1.581 + } else { 1.582 + CK_ULONG m; 1.583 + 1.584 + if( pT2[l].ulValueLen <= 8 ) { 1.585 + PR_fprintf(PR_STDOUT, ", value = "); 1.586 + } else { 1.587 + PR_fprintf(PR_STDOUT, ", value = \n "); 1.588 + } 1.589 + 1.590 + for( m = 0; (m < pT2[l].ulValueLen) && (m < 20); m++ ) { 1.591 + PR_fprintf(PR_STDOUT, "%02x", (CK_ULONG)(0xff & ((CK_CHAR_PTR)pT2[l].pValue)[m])); 1.592 + } 1.593 + 1.594 + PR_fprintf(PR_STDOUT, " "); 1.595 + 1.596 + for( m = 0; (m < pT2[l].ulValueLen) && (m < 20); m++ ) { 1.597 + CK_CHAR c = ((CK_CHAR_PTR)pT2[l].pValue)[m]; 1.598 + if( (c < 0x20) || (c >= 0x7f) ) { 1.599 + c = '.'; 1.600 + } 1.601 + PR_fprintf(PR_STDOUT, "%c", c); 1.602 + } 1.603 + } 1.604 + 1.605 + PR_fprintf(PR_STDOUT, "\n"); 1.606 + } 1.607 + 1.608 + PR_fprintf(PR_STDOUT, "\n"); 1.609 + 1.610 + for( l = 0; l < nAttributes; l++ ) { 1.611 + PR_Free(pT2[l].pValue); 1.612 + } 1.613 + PR_Free(pT2); 1.614 + } /* while(1) */ 1.615 + 1.616 + ck_rv = epv->C_FindObjectsFinal(h); 1.617 + if( CKR_OK != ck_rv ) { 1.618 + PR_fprintf(PR_STDERR, "C_FindObjectsFinal(%lu) returned 0x%08x\n", h, ck_rv); 1.619 + return 1; 1.620 + } 1.621 + 1.622 + PR_fprintf(PR_STDOUT, " (%lu objects total)\n", tnObjects); 1.623 + 1.624 + ck_rv = epv->C_CloseSession(h); 1.625 + if( CKR_OK != ck_rv ) { 1.626 + PR_fprintf(PR_STDERR, "C_CloseSession(%lu) returned 0x%08x\n", h, ck_rv); 1.627 + return 1; 1.628 + } 1.629 + } /* session to find objects */ 1.630 + 1.631 + /* session to create, find, and delete a couple session objects */ 1.632 + { 1.633 + CK_SESSION_HANDLE h = (CK_SESSION_HANDLE)0; 1.634 + CK_ATTRIBUTE one[7], two[7], three[7], delta[1], mask[1]; 1.635 + CK_OBJECT_CLASS cko_data = CKO_DATA; 1.636 + CK_BBOOL false = CK_FALSE, true = CK_TRUE; 1.637 + char *key = "TEST PROGRAM"; 1.638 + CK_ULONG key_len = strlen(key); 1.639 + CK_OBJECT_HANDLE hOneIn = (CK_OBJECT_HANDLE)0, hTwoIn = (CK_OBJECT_HANDLE)0, 1.640 + hThreeIn = (CK_OBJECT_HANDLE)0, hDeltaIn = (CK_OBJECT_HANDLE)0; 1.641 + CK_OBJECT_HANDLE found[10]; 1.642 + CK_ULONG nFound; 1.643 + 1.644 + ck_rv = epv->C_OpenSession(pSlots[i], CKF_SERIAL_SESSION, (CK_VOID_PTR)CK_NULL_PTR, (CK_NOTIFY)CK_NULL_PTR, &h); 1.645 + if( CKR_OK != ck_rv ) { 1.646 + PR_fprintf(PR_STDERR, "C_OpenSession(%lu, CKF_SERIAL_SESSION, , ) returned 0x%08x\n", pSlots[i], ck_rv); 1.647 + return 1; 1.648 + } 1.649 + 1.650 + PR_fprintf(PR_STDOUT, " Opened a session: handle = 0x%08x\n", h); 1.651 + 1.652 + one[0].type = CKA_CLASS; 1.653 + one[0].pValue = &cko_data; 1.654 + one[0].ulValueLen = sizeof(CK_OBJECT_CLASS); 1.655 + one[1].type = CKA_TOKEN; 1.656 + one[1].pValue = &false; 1.657 + one[1].ulValueLen = sizeof(CK_BBOOL); 1.658 + one[2].type = CKA_PRIVATE; 1.659 + one[2].pValue = &false; 1.660 + one[2].ulValueLen = sizeof(CK_BBOOL); 1.661 + one[3].type = CKA_MODIFIABLE; 1.662 + one[3].pValue = &true; 1.663 + one[3].ulValueLen = sizeof(CK_BBOOL); 1.664 + one[4].type = CKA_LABEL; 1.665 + one[4].pValue = "Test data object one"; 1.666 + one[4].ulValueLen = strlen(one[4].pValue); 1.667 + one[5].type = CKA_APPLICATION; 1.668 + one[5].pValue = key; 1.669 + one[5].ulValueLen = key_len; 1.670 + one[6].type = CKA_VALUE; 1.671 + one[6].pValue = "Object one"; 1.672 + one[6].ulValueLen = strlen(one[6].pValue); 1.673 + 1.674 + two[0].type = CKA_CLASS; 1.675 + two[0].pValue = &cko_data; 1.676 + two[0].ulValueLen = sizeof(CK_OBJECT_CLASS); 1.677 + two[1].type = CKA_TOKEN; 1.678 + two[1].pValue = &false; 1.679 + two[1].ulValueLen = sizeof(CK_BBOOL); 1.680 + two[2].type = CKA_PRIVATE; 1.681 + two[2].pValue = &false; 1.682 + two[2].ulValueLen = sizeof(CK_BBOOL); 1.683 + two[3].type = CKA_MODIFIABLE; 1.684 + two[3].pValue = &true; 1.685 + two[3].ulValueLen = sizeof(CK_BBOOL); 1.686 + two[4].type = CKA_LABEL; 1.687 + two[4].pValue = "Test data object two"; 1.688 + two[4].ulValueLen = strlen(two[4].pValue); 1.689 + two[5].type = CKA_APPLICATION; 1.690 + two[5].pValue = key; 1.691 + two[5].ulValueLen = key_len; 1.692 + two[6].type = CKA_VALUE; 1.693 + two[6].pValue = "Object two"; 1.694 + two[6].ulValueLen = strlen(two[6].pValue); 1.695 + 1.696 + three[0].type = CKA_CLASS; 1.697 + three[0].pValue = &cko_data; 1.698 + three[0].ulValueLen = sizeof(CK_OBJECT_CLASS); 1.699 + three[1].type = CKA_TOKEN; 1.700 + three[1].pValue = &false; 1.701 + three[1].ulValueLen = sizeof(CK_BBOOL); 1.702 + three[2].type = CKA_PRIVATE; 1.703 + three[2].pValue = &false; 1.704 + three[2].ulValueLen = sizeof(CK_BBOOL); 1.705 + three[3].type = CKA_MODIFIABLE; 1.706 + three[3].pValue = &true; 1.707 + three[3].ulValueLen = sizeof(CK_BBOOL); 1.708 + three[4].type = CKA_LABEL; 1.709 + three[4].pValue = "Test data object three"; 1.710 + three[4].ulValueLen = strlen(three[4].pValue); 1.711 + three[5].type = CKA_APPLICATION; 1.712 + three[5].pValue = key; 1.713 + three[5].ulValueLen = key_len; 1.714 + three[6].type = CKA_VALUE; 1.715 + three[6].pValue = "Object three"; 1.716 + three[6].ulValueLen = strlen(three[6].pValue); 1.717 + 1.718 + ck_rv = epv->C_CreateObject(h, one, 7, &hOneIn); 1.719 + if( CKR_OK != ck_rv ) { 1.720 + PR_fprintf(PR_STDERR, "C_CreateObject(%lu, one, 7, ) returned 0x%08x\n", h, ck_rv); 1.721 + return 1; 1.722 + } 1.723 + 1.724 + PR_fprintf(PR_STDOUT, " Created object one: handle = %lu\n", hOneIn); 1.725 + 1.726 + ck_rv = epv->C_CreateObject(h, two, 7, &hTwoIn); 1.727 + if( CKR_OK != ck_rv ) { 1.728 + PR_fprintf(PR_STDERR, "C_CreateObject(%lu, two, 7, ) returned 0x%08x\n", h, ck_rv); 1.729 + return 1; 1.730 + } 1.731 + 1.732 + PR_fprintf(PR_STDOUT, " Created object two: handle = %lu\n", hTwoIn); 1.733 + 1.734 + ck_rv = epv->C_CreateObject(h, three, 7, &hThreeIn); 1.735 + if( CKR_OK != ck_rv ) { 1.736 + PR_fprintf(PR_STDERR, "C_CreateObject(%lu, three, 7, ) returned 0x%08x\n", h, ck_rv); 1.737 + return 1; 1.738 + } 1.739 + 1.740 + PR_fprintf(PR_STDOUT, " Created object three: handle = %lu\n", hThreeIn); 1.741 + 1.742 + delta[0].type = CKA_VALUE; 1.743 + delta[0].pValue = "Copied object"; 1.744 + delta[0].ulValueLen = strlen(delta[0].pValue); 1.745 + 1.746 + ck_rv = epv->C_CopyObject(h, hThreeIn, delta, 1, &hDeltaIn); 1.747 + if( CKR_OK != ck_rv ) { 1.748 + PR_fprintf(PR_STDERR, "C_CopyObject(%lu, %lu, delta, 1, ) returned 0x%08x\n", 1.749 + h, hThreeIn, ck_rv); 1.750 + return 1; 1.751 + } 1.752 + 1.753 + PR_fprintf(PR_STDOUT, " Copied object three: new handle = %lu\n", hDeltaIn); 1.754 + 1.755 + mask[0].type = CKA_APPLICATION; 1.756 + mask[0].pValue = key; 1.757 + mask[0].ulValueLen = key_len; 1.758 + 1.759 + ck_rv = epv->C_FindObjectsInit(h, mask, 1); 1.760 + if( CKR_OK != ck_rv ) { 1.761 + PR_fprintf(PR_STDERR, "C_FindObjectsInit(%lu, mask, 1) returned 0x%08x\n", 1.762 + h, ck_rv); 1.763 + return 1; 1.764 + } 1.765 + 1.766 + (void)memset(&found, 0, sizeof(found)); 1.767 + nFound = 0; 1.768 + ck_rv = epv->C_FindObjects(h, found, 10, &nFound); 1.769 + if( CKR_OK != ck_rv ) { 1.770 + PR_fprintf(PR_STDERR, "C_FindObjects(%lu,, 10, ) returned 0x%08x\n", 1.771 + h, ck_rv); 1.772 + return 1; 1.773 + } 1.774 + 1.775 + if( 4 != nFound ) { 1.776 + PR_fprintf(PR_STDERR, "Found %lu objects, not 4.\n", nFound); 1.777 + return 1; 1.778 + } 1.779 + 1.780 + PR_fprintf(PR_STDOUT, " Found 4 objects: %lu, %lu, %lu, %lu\n", 1.781 + found[0], found[1], found[2], found[3]); 1.782 + 1.783 + ck_rv = epv->C_FindObjectsFinal(h); 1.784 + if( CKR_OK != ck_rv ) { 1.785 + PR_fprintf(PR_STDERR, "C_FindObjectsFinal(%lu) returned 0x%08x\n", h, ck_rv); 1.786 + return 1; 1.787 + } 1.788 + 1.789 + ck_rv = epv->C_DestroyObject(h, hThreeIn); 1.790 + if( CKR_OK != ck_rv ) { 1.791 + PR_fprintf(PR_STDERR, "C_DestroyObject(%lu, %lu) returned 0x%08x\n", h, hThreeIn, ck_rv); 1.792 + return 1; 1.793 + } 1.794 + 1.795 + PR_fprintf(PR_STDOUT, " Destroyed object three (handle = %lu)\n", hThreeIn); 1.796 + 1.797 + delta[0].type = CKA_APPLICATION; 1.798 + delta[0].pValue = "Changed application"; 1.799 + delta[0].ulValueLen = strlen(delta[0].pValue); 1.800 + 1.801 + ck_rv = epv->C_SetAttributeValue(h, hTwoIn, delta, 1); 1.802 + if( CKR_OK != ck_rv ) { 1.803 + PR_fprintf(PR_STDERR, "C_SetAttributeValue(%lu, %lu, delta, 1) returned 0x%08x\n", 1.804 + h, hTwoIn, ck_rv); 1.805 + return 1; 1.806 + } 1.807 + 1.808 + PR_fprintf(PR_STDOUT, " Changed object two (handle = %lu).\n", hTwoIn); 1.809 + 1.810 + /* Can another session find these session objects? */ 1.811 + { 1.812 + CK_SESSION_HANDLE h2 = (CK_SESSION_HANDLE)0; 1.813 + 1.814 + ck_rv = epv->C_OpenSession(pSlots[i], CKF_SERIAL_SESSION, (CK_VOID_PTR)CK_NULL_PTR, (CK_NOTIFY)CK_NULL_PTR, &h2); 1.815 + if( CKR_OK != ck_rv ) { 1.816 + PR_fprintf(PR_STDERR, "C_OpenSession(%lu, CKF_SERIAL_SESSION, , ) returned 0x%08x\n", pSlots[i], ck_rv); 1.817 + return 1; 1.818 + } 1.819 + 1.820 + PR_fprintf(PR_STDOUT, " Opened a second session: handle = 0x%08x\n", h2); 1.821 + 1.822 + /* mask is still the same */ 1.823 + 1.824 + ck_rv = epv->C_FindObjectsInit(h2, mask, 1); 1.825 + if( CKR_OK != ck_rv ) { 1.826 + PR_fprintf(PR_STDERR, "C_FindObjectsInit(%lu, mask, 1) returned 0x%08x\n", 1.827 + h2, ck_rv); 1.828 + return 1; 1.829 + } 1.830 + 1.831 + (void)memset(&found, 0, sizeof(found)); 1.832 + nFound = 0; 1.833 + ck_rv = epv->C_FindObjects(h2, found, 10, &nFound); 1.834 + if( CKR_OK != ck_rv ) { 1.835 + PR_fprintf(PR_STDERR, "C_FindObjects(%lu,, 10, ) returned 0x%08x\n", 1.836 + h2, ck_rv); 1.837 + return 1; 1.838 + } 1.839 + 1.840 + if( 2 != nFound ) { 1.841 + PR_fprintf(PR_STDERR, "Found %lu objects, not 2.\n", nFound); 1.842 + return 1; 1.843 + } 1.844 + 1.845 + PR_fprintf(PR_STDOUT, " Found 2 objects: %lu, %lu\n", 1.846 + found[0], found[1]); 1.847 + 1.848 + ck_rv = epv->C_FindObjectsFinal(h2); 1.849 + if( CKR_OK != ck_rv ) { 1.850 + PR_fprintf(PR_STDERR, "C_FindObjectsFinal(%lu) returned 0x%08x\n", h2, ck_rv); 1.851 + return 1; 1.852 + } 1.853 + 1.854 + /* Leave the session hanging open, we'll CloseAllSessions later */ 1.855 + } /* Can another session find these session objects? */ 1.856 + 1.857 + ck_rv = epv->C_CloseAllSessions(pSlots[i]); 1.858 + if( CKR_OK != ck_rv ) { 1.859 + PR_fprintf(PR_STDERR, "C_CloseAllSessions(%lu) returned 0x%08x\n", pSlots[i], ck_rv); 1.860 + return 1; 1.861 + } 1.862 + } /* session to create, find, and delete a couple session objects */ 1.863 + 1.864 + /* Might be interesting to do a find here to verify that all session objects are gone. */ 1.865 + 1.866 + if( tinfo.flags & CKF_WRITE_PROTECTED ) { 1.867 + PR_fprintf(PR_STDOUT, "Token is write protected, skipping token-object tests.\n"); 1.868 + } else { 1.869 + CK_SESSION_HANDLE h = (CK_SESSION_HANDLE)0; 1.870 + CK_ATTRIBUTE tobj[7], tsobj[7], stobj[7], delta[1], mask[2]; 1.871 + CK_OBJECT_CLASS cko_data = CKO_DATA; 1.872 + CK_BBOOL false = CK_FALSE, true = CK_TRUE; 1.873 + char *key = "TEST PROGRAM"; 1.874 + CK_ULONG key_len = strlen(key); 1.875 + CK_OBJECT_HANDLE hTIn = (CK_OBJECT_HANDLE)0, hTSIn = (CK_OBJECT_HANDLE)0, 1.876 + hSTIn = (CK_OBJECT_HANDLE)0, hDeltaIn = (CK_OBJECT_HANDLE)0; 1.877 + CK_OBJECT_HANDLE found[10]; 1.878 + CK_ULONG nFound; 1.879 + 1.880 + ck_rv = epv->C_OpenSession(pSlots[i], CKF_SERIAL_SESSION, (CK_VOID_PTR)CK_NULL_PTR, (CK_NOTIFY)CK_NULL_PTR, &h); 1.881 + if( CKR_OK != ck_rv ) { 1.882 + PR_fprintf(PR_STDERR, "C_OpenSession(%lu, CKF_SERIAL_SESSION, , ) returned 0x%08x\n", pSlots[i], ck_rv); 1.883 + return 1; 1.884 + } 1.885 + 1.886 + PR_fprintf(PR_STDOUT, " Opened a session: handle = 0x%08x\n", h); 1.887 + 1.888 + tobj[0].type = CKA_CLASS; 1.889 + tobj[0].pValue = &cko_data; 1.890 + tobj[0].ulValueLen = sizeof(CK_OBJECT_CLASS); 1.891 + tobj[1].type = CKA_TOKEN; 1.892 + tobj[1].pValue = &true; 1.893 + tobj[1].ulValueLen = sizeof(CK_BBOOL); 1.894 + tobj[2].type = CKA_PRIVATE; 1.895 + tobj[2].pValue = &false; 1.896 + tobj[2].ulValueLen = sizeof(CK_BBOOL); 1.897 + tobj[3].type = CKA_MODIFIABLE; 1.898 + tobj[3].pValue = &true; 1.899 + tobj[3].ulValueLen = sizeof(CK_BBOOL); 1.900 + tobj[4].type = CKA_LABEL; 1.901 + tobj[4].pValue = "Test data object token"; 1.902 + tobj[4].ulValueLen = strlen(tobj[4].pValue); 1.903 + tobj[5].type = CKA_APPLICATION; 1.904 + tobj[5].pValue = key; 1.905 + tobj[5].ulValueLen = key_len; 1.906 + tobj[6].type = CKA_VALUE; 1.907 + tobj[6].pValue = "Object token"; 1.908 + tobj[6].ulValueLen = strlen(tobj[6].pValue); 1.909 + 1.910 + tsobj[0].type = CKA_CLASS; 1.911 + tsobj[0].pValue = &cko_data; 1.912 + tsobj[0].ulValueLen = sizeof(CK_OBJECT_CLASS); 1.913 + tsobj[1].type = CKA_TOKEN; 1.914 + tsobj[1].pValue = &true; 1.915 + tsobj[1].ulValueLen = sizeof(CK_BBOOL); 1.916 + tsobj[2].type = CKA_PRIVATE; 1.917 + tsobj[2].pValue = &false; 1.918 + tsobj[2].ulValueLen = sizeof(CK_BBOOL); 1.919 + tsobj[3].type = CKA_MODIFIABLE; 1.920 + tsobj[3].pValue = &true; 1.921 + tsobj[3].ulValueLen = sizeof(CK_BBOOL); 1.922 + tsobj[4].type = CKA_LABEL; 1.923 + tsobj[4].pValue = "Test data object token->session"; 1.924 + tsobj[4].ulValueLen = strlen(tsobj[4].pValue); 1.925 + tsobj[5].type = CKA_APPLICATION; 1.926 + tsobj[5].pValue = key; 1.927 + tsobj[5].ulValueLen = key_len; 1.928 + tsobj[6].type = CKA_VALUE; 1.929 + tsobj[6].pValue = "Object token->session"; 1.930 + tsobj[6].ulValueLen = strlen(tsobj[6].pValue); 1.931 + 1.932 + stobj[0].type = CKA_CLASS; 1.933 + stobj[0].pValue = &cko_data; 1.934 + stobj[0].ulValueLen = sizeof(CK_OBJECT_CLASS); 1.935 + stobj[1].type = CKA_TOKEN; 1.936 + stobj[1].pValue = &false; 1.937 + stobj[1].ulValueLen = sizeof(CK_BBOOL); 1.938 + stobj[2].type = CKA_PRIVATE; 1.939 + stobj[2].pValue = &false; 1.940 + stobj[2].ulValueLen = sizeof(CK_BBOOL); 1.941 + stobj[3].type = CKA_MODIFIABLE; 1.942 + stobj[3].pValue = &true; 1.943 + stobj[3].ulValueLen = sizeof(CK_BBOOL); 1.944 + stobj[4].type = CKA_LABEL; 1.945 + stobj[4].pValue = "Test data object session->token"; 1.946 + stobj[4].ulValueLen = strlen(stobj[4].pValue); 1.947 + stobj[5].type = CKA_APPLICATION; 1.948 + stobj[5].pValue = key; 1.949 + stobj[5].ulValueLen = key_len; 1.950 + stobj[6].type = CKA_VALUE; 1.951 + stobj[6].pValue = "Object session->token"; 1.952 + stobj[6].ulValueLen = strlen(stobj[6].pValue); 1.953 + 1.954 + ck_rv = epv->C_CreateObject(h, tobj, 7, &hTIn); 1.955 + if( CKR_OK != ck_rv ) { 1.956 + PR_fprintf(PR_STDERR, "C_CreateObject(%lu, tobj, 7, ) returned 0x%08x\n", h, ck_rv); 1.957 + return 1; 1.958 + } 1.959 + 1.960 + PR_fprintf(PR_STDOUT, " Created object token: handle = %lu\n", hTIn); 1.961 + 1.962 + ck_rv = epv->C_CreateObject(h, tsobj, 7, &hTSIn); 1.963 + if( CKR_OK != ck_rv ) { 1.964 + PR_fprintf(PR_STDERR, "C_CreateObject(%lu, tobj, 7, ) returned 0x%08x\n", h, ck_rv); 1.965 + return 1; 1.966 + } 1.967 + 1.968 + PR_fprintf(PR_STDOUT, " Created object token->session: handle = %lu\n", hTSIn); 1.969 + ck_rv = epv->C_CreateObject(h, stobj, 7, &hSTIn); 1.970 + if( CKR_OK != ck_rv ) { 1.971 + PR_fprintf(PR_STDERR, "C_CreateObject(%lu, tobj, 7, ) returned 0x%08x\n", h, ck_rv); 1.972 + return 1; 1.973 + } 1.974 + 1.975 + PR_fprintf(PR_STDOUT, " Created object session->token: handle = %lu\n", hSTIn); 1.976 + 1.977 + /* I've created two token objects and one session object; find the two */ 1.978 + 1.979 + mask[0].type = CKA_APPLICATION; 1.980 + mask[0].pValue = key; 1.981 + mask[0].ulValueLen = key_len; 1.982 + mask[1].type = CKA_TOKEN; 1.983 + mask[1].pValue = &true; 1.984 + mask[1].ulValueLen = sizeof(CK_BBOOL); 1.985 + 1.986 + ck_rv = epv->C_FindObjectsInit(h, mask, 2); 1.987 + if( CKR_OK != ck_rv ) { 1.988 + PR_fprintf(PR_STDERR, "C_FindObjectsInit(%lu, mask, 2) returned 0x%08x\n", 1.989 + h, ck_rv); 1.990 + return 1; 1.991 + } 1.992 + 1.993 + (void)memset(&found, 0, sizeof(found)); 1.994 + nFound = 0; 1.995 + ck_rv = epv->C_FindObjects(h, found, 10, &nFound); 1.996 + if( CKR_OK != ck_rv ) { 1.997 + PR_fprintf(PR_STDERR, "C_FindObjects(%lu,, 10, ) returned 0x%08x\n", 1.998 + h, ck_rv); 1.999 + return 1; 1.1000 + } 1.1001 + 1.1002 + if( 2 != nFound ) { 1.1003 + PR_fprintf(PR_STDERR, "Found %lu objects, not 2.\n", nFound); 1.1004 + return 1; 1.1005 + } 1.1006 + 1.1007 + PR_fprintf(PR_STDOUT, " Found 2 objects: %lu, %lu\n", 1.1008 + found[0], found[1]); 1.1009 + 1.1010 + ck_rv = epv->C_FindObjectsFinal(h); 1.1011 + if( CKR_OK != ck_rv ) { 1.1012 + PR_fprintf(PR_STDERR, "C_FindObjectsFinal(%lu) returned 0x%08x\n", h, ck_rv); 1.1013 + return 1; 1.1014 + } 1.1015 + 1.1016 + /* Convert a token to session object */ 1.1017 + 1.1018 + delta[0].type = CKA_TOKEN; 1.1019 + delta[0].pValue = &false; 1.1020 + delta[0].ulValueLen = sizeof(CK_BBOOL); 1.1021 + 1.1022 + ck_rv = epv->C_SetAttributeValue(h, hTSIn, delta, 1); 1.1023 + if( CKR_OK != ck_rv ) { 1.1024 + PR_fprintf(PR_STDERR, "C_SetAttributeValue(%lu, %lu, delta, 1) returned 0x%08x\n", 1.1025 + h, hTSIn, ck_rv); 1.1026 + return 1; 1.1027 + } 1.1028 + 1.1029 + PR_fprintf(PR_STDOUT, " Changed object from token to session (handle = %lu).\n", hTSIn); 1.1030 + 1.1031 + /* Now find again; there should be one */ 1.1032 + 1.1033 + mask[0].type = CKA_APPLICATION; 1.1034 + mask[0].pValue = key; 1.1035 + mask[0].ulValueLen = key_len; 1.1036 + mask[1].type = CKA_TOKEN; 1.1037 + mask[1].pValue = &true; 1.1038 + mask[1].ulValueLen = sizeof(CK_BBOOL); 1.1039 + 1.1040 + ck_rv = epv->C_FindObjectsInit(h, mask, 2); 1.1041 + if( CKR_OK != ck_rv ) { 1.1042 + PR_fprintf(PR_STDERR, "C_FindObjectsInit(%lu, mask, 2) returned 0x%08x\n", 1.1043 + h, ck_rv); 1.1044 + return 1; 1.1045 + } 1.1046 + 1.1047 + (void)memset(&found, 0, sizeof(found)); 1.1048 + nFound = 0; 1.1049 + ck_rv = epv->C_FindObjects(h, found, 10, &nFound); 1.1050 + if( CKR_OK != ck_rv ) { 1.1051 + PR_fprintf(PR_STDERR, "C_FindObjects(%lu,, 10, ) returned 0x%08x\n", 1.1052 + h, ck_rv); 1.1053 + return 1; 1.1054 + } 1.1055 + 1.1056 + if( 1 != nFound ) { 1.1057 + PR_fprintf(PR_STDERR, "Found %lu objects, not 1.\n", nFound); 1.1058 + return 1; 1.1059 + } 1.1060 + 1.1061 + PR_fprintf(PR_STDOUT, " Found 1 objects: %lu\n", 1.1062 + found[0]); 1.1063 + 1.1064 + ck_rv = epv->C_FindObjectsFinal(h); 1.1065 + if( CKR_OK != ck_rv ) { 1.1066 + PR_fprintf(PR_STDERR, "C_FindObjectsFinal(%lu) returned 0x%08x\n", h, ck_rv); 1.1067 + return 1; 1.1068 + } 1.1069 + 1.1070 + /* Convert a session to a token object */ 1.1071 + 1.1072 + delta[0].type = CKA_TOKEN; 1.1073 + delta[0].pValue = &true; 1.1074 + delta[0].ulValueLen = sizeof(CK_BBOOL); 1.1075 + 1.1076 + ck_rv = epv->C_SetAttributeValue(h, hSTIn, delta, 1); 1.1077 + if( CKR_OK != ck_rv ) { 1.1078 + PR_fprintf(PR_STDERR, "C_SetAttributeValue(%lu, %lu, delta, 1) returned 0x%08x\n", 1.1079 + h, hSTIn, ck_rv); 1.1080 + return 1; 1.1081 + } 1.1082 + 1.1083 + PR_fprintf(PR_STDOUT, " Changed object from session to token (handle = %lu).\n", hSTIn); 1.1084 + 1.1085 + /* Now find again; there should be two again */ 1.1086 + 1.1087 + mask[0].type = CKA_APPLICATION; 1.1088 + mask[0].pValue = key; 1.1089 + mask[0].ulValueLen = key_len; 1.1090 + mask[1].type = CKA_TOKEN; 1.1091 + mask[1].pValue = &true; 1.1092 + mask[1].ulValueLen = sizeof(CK_BBOOL); 1.1093 + 1.1094 + ck_rv = epv->C_FindObjectsInit(h, mask, 2); 1.1095 + if( CKR_OK != ck_rv ) { 1.1096 + PR_fprintf(PR_STDERR, "C_FindObjectsInit(%lu, mask, 2) returned 0x%08x\n", 1.1097 + h, ck_rv); 1.1098 + return 1; 1.1099 + } 1.1100 + 1.1101 + (void)memset(&found, 0, sizeof(found)); 1.1102 + nFound = 0; 1.1103 + ck_rv = epv->C_FindObjects(h, found, 10, &nFound); 1.1104 + if( CKR_OK != ck_rv ) { 1.1105 + PR_fprintf(PR_STDERR, "C_FindObjects(%lu,, 10, ) returned 0x%08x\n", 1.1106 + h, ck_rv); 1.1107 + return 1; 1.1108 + } 1.1109 + 1.1110 + if( 2 != nFound ) { 1.1111 + PR_fprintf(PR_STDERR, "Found %lu objects, not 2.\n", nFound); 1.1112 + return 1; 1.1113 + } 1.1114 + 1.1115 + PR_fprintf(PR_STDOUT, " Found 2 objects: %lu, %lu\n", 1.1116 + found[0], found[1]); 1.1117 + 1.1118 + ck_rv = epv->C_FindObjectsFinal(h); 1.1119 + if( CKR_OK != ck_rv ) { 1.1120 + PR_fprintf(PR_STDERR, "C_FindObjectsFinal(%lu) returned 0x%08x\n", h, ck_rv); 1.1121 + return 1; 1.1122 + } 1.1123 + 1.1124 + /* Delete the two (found) token objects to clean up */ 1.1125 + 1.1126 + ck_rv = epv->C_DestroyObject(h, found[0]); 1.1127 + if( CKR_OK != ck_rv ) { 1.1128 + PR_fprintf(PR_STDERR, "C_DestroyObject(%lu, %lu) returned 0x%08x\n", h, found[0], ck_rv); 1.1129 + return 1; 1.1130 + } 1.1131 + 1.1132 + PR_fprintf(PR_STDOUT, " Destroyed token object (handle = %lu)\n", found[0]); 1.1133 + 1.1134 + ck_rv = epv->C_DestroyObject(h, found[1]); 1.1135 + if( CKR_OK != ck_rv ) { 1.1136 + PR_fprintf(PR_STDERR, "C_DestroyObject(%lu, %lu) returned 0x%08x\n", h, found[1], ck_rv); 1.1137 + return 1; 1.1138 + } 1.1139 + 1.1140 + PR_fprintf(PR_STDOUT, " Destroyed token object (handle = %lu)\n", found[1]); 1.1141 + 1.1142 + /* Close the session and all objects should be gone */ 1.1143 + 1.1144 + ck_rv = epv->C_CloseSession(h); 1.1145 + if( CKR_OK != ck_rv ) { 1.1146 + PR_fprintf(PR_STDERR, "C_CloseSession(%lu) returned 0x%08x\n", h, ck_rv); 1.1147 + return 1; 1.1148 + } 1.1149 + } /* if( tinfo.flags & CKF_WRITE_PROTECTED ) */ 1.1150 + 1.1151 + if( tinfo.flags & CKF_WRITE_PROTECTED ) { 1.1152 + PR_fprintf(PR_STDOUT, "Token is write protected, skipping leaving a record.\n"); 1.1153 + } else { 1.1154 + CK_SESSION_HANDLE h = (CK_SESSION_HANDLE)0; 1.1155 + CK_ATTRIBUTE record[7], mask[2]; 1.1156 + CK_OBJECT_CLASS cko_data = CKO_DATA; 1.1157 + CK_BBOOL false = CK_FALSE, true = CK_TRUE; 1.1158 + char *key = "TEST RECORD"; 1.1159 + CK_ULONG key_len = strlen(key); 1.1160 + CK_OBJECT_HANDLE hin = (CK_OBJECT_HANDLE)0; 1.1161 + char timebuffer[256]; 1.1162 + 1.1163 + ck_rv = epv->C_OpenSession(pSlots[i], CKF_SERIAL_SESSION, (CK_VOID_PTR)CK_NULL_PTR, (CK_NOTIFY)CK_NULL_PTR, &h); 1.1164 + if( CKR_OK != ck_rv ) { 1.1165 + PR_fprintf(PR_STDERR, "C_OpenSession(%lu, CKF_SERIAL_SESSION, , ) returned 0x%08x\n", pSlots[i], ck_rv); 1.1166 + return 1; 1.1167 + } 1.1168 + 1.1169 + PR_fprintf(PR_STDOUT, " Opened a session: handle = 0x%08x\n", h); 1.1170 + 1.1171 + /* I can't believe how hard NSPR makes this operation */ 1.1172 + { 1.1173 + time_t now = 0; 1.1174 + struct tm *tm; 1.1175 + time(&now); 1.1176 + tm = localtime(&now); 1.1177 + strftime(timebuffer, sizeof(timebuffer), "%Y-%m-%d %T %Z", tm); 1.1178 + } 1.1179 + 1.1180 + record[0].type = CKA_CLASS; 1.1181 + record[0].pValue = &cko_data; 1.1182 + record[0].ulValueLen = sizeof(CK_OBJECT_CLASS); 1.1183 + record[1].type = CKA_TOKEN; 1.1184 + record[1].pValue = &true; 1.1185 + record[1].ulValueLen = sizeof(CK_BBOOL); 1.1186 + record[2].type = CKA_PRIVATE; 1.1187 + record[2].pValue = &false; 1.1188 + record[2].ulValueLen = sizeof(CK_BBOOL); 1.1189 + record[3].type = CKA_MODIFIABLE; 1.1190 + record[3].pValue = &true; 1.1191 + record[3].ulValueLen = sizeof(CK_BBOOL); 1.1192 + record[4].type = CKA_LABEL; 1.1193 + record[4].pValue = "Test record"; 1.1194 + record[4].ulValueLen = strlen(record[4].pValue); 1.1195 + record[5].type = CKA_APPLICATION; 1.1196 + record[5].pValue = key; 1.1197 + record[5].ulValueLen = key_len; 1.1198 + record[6].type = CKA_VALUE; 1.1199 + record[6].pValue = timebuffer; 1.1200 + record[6].ulValueLen = strlen(timebuffer)+1; 1.1201 + 1.1202 + PR_fprintf(PR_STDOUT, " Timestamping with \"%s\"\n", timebuffer); 1.1203 + 1.1204 + ck_rv = epv->C_CreateObject(h, record, 7, &hin); 1.1205 + if( CKR_OK != ck_rv ) { 1.1206 + PR_fprintf(PR_STDERR, "C_CreateObject(%lu, tobj, 7, ) returned 0x%08x\n", h, ck_rv); 1.1207 + return 1; 1.1208 + } 1.1209 + 1.1210 + PR_fprintf(PR_STDOUT, " Created record object: handle = %lu\n", hin); 1.1211 + 1.1212 + PR_fprintf(PR_STDOUT, " == All test timestamps ==\n"); 1.1213 + 1.1214 + mask[0].type = CKA_CLASS; 1.1215 + mask[0].pValue = &cko_data; 1.1216 + mask[0].ulValueLen = sizeof(CK_OBJECT_CLASS); 1.1217 + mask[1].type = CKA_APPLICATION; 1.1218 + mask[1].pValue = key; 1.1219 + mask[1].ulValueLen = key_len; 1.1220 + 1.1221 + ck_rv = epv->C_FindObjectsInit(h, mask, 2); 1.1222 + if( CKR_OK != ck_rv ) { 1.1223 + PR_fprintf(PR_STDERR, "C_FindObjectsInit(%lu, mask, 1) returned 0x%08x\n", 1.1224 + h, ck_rv); 1.1225 + return 1; 1.1226 + } 1.1227 + 1.1228 + while( 1 ) { 1.1229 + CK_OBJECT_HANDLE o = (CK_OBJECT_HANDLE)0; 1.1230 + CK_ULONG nObjects = 0; 1.1231 + CK_ATTRIBUTE value[1]; 1.1232 + char buffer[1024]; 1.1233 + 1.1234 + ck_rv = epv->C_FindObjects(h, &o, 1, &nObjects); 1.1235 + if( CKR_OK != ck_rv ) { 1.1236 + PR_fprintf(PR_STDERR, "C_FindObjects(%lu, , 1, ) returned 0x%08x\n", h, ck_rv); 1.1237 + return 1; 1.1238 + } 1.1239 + 1.1240 + if( 0 == nObjects ) { 1.1241 + PR_fprintf(PR_STDOUT, "\n"); 1.1242 + break; 1.1243 + } 1.1244 + 1.1245 + value[0].type = CKA_VALUE; 1.1246 + value[0].pValue = buffer; 1.1247 + value[0].ulValueLen = sizeof(buffer); 1.1248 + 1.1249 + ck_rv = epv->C_GetAttributeValue(h, o, value, 1); 1.1250 + switch( ck_rv ) { 1.1251 + case CKR_OK: 1.1252 + PR_fprintf(PR_STDOUT, " %s\n", value[0].pValue); 1.1253 + break; 1.1254 + case CKR_ATTRIBUTE_SENSITIVE: 1.1255 + PR_fprintf(PR_STDOUT, " [Sensitive???]\n"); 1.1256 + break; 1.1257 + case CKR_ATTRIBUTE_TYPE_INVALID: 1.1258 + PR_fprintf(PR_STDOUT, " [Invalid attribute???]\n"); 1.1259 + break; 1.1260 + case CKR_BUFFER_TOO_SMALL: 1.1261 + PR_fprintf(PR_STDOUT, " (result > 1k (%lu))\n", value[0].ulValueLen); 1.1262 + break; 1.1263 + default: 1.1264 + PR_fprintf(PR_STDERR, "C_GetAtributeValue(%lu, %lu, CKA_VALUE, 1) returned 0x%08x\n", 1.1265 + h, o); 1.1266 + return 1; 1.1267 + } 1.1268 + } /* while */ 1.1269 + 1.1270 + ck_rv = epv->C_FindObjectsFinal(h); 1.1271 + if( CKR_OK != ck_rv ) { 1.1272 + PR_fprintf(PR_STDERR, "C_FindObjectsFinal(%lu) returned 0x%08x\n", h, ck_rv); 1.1273 + return 1; 1.1274 + } 1.1275 + } /* "leaving a record" else clause */ 1.1276 + 1.1277 + } 1.1278 + 1.1279 + PR_fprintf(PR_STDOUT, "\n"); 1.1280 + } 1.1281 + 1.1282 + return 0; 1.1283 +}