michael@0: Load nsscapi.dll michael@0: C_Initialize NULL michael@0: C_GetSlotList false NULL slotCount michael@0: NewArray slotList CK_ULONG slotCount michael@0: C_GetSlotList false slotList slotCount michael@0: #change the following to the appropriate slot id michael@0: set slotID 1 michael@0: #set slotID slotList[0] michael@0: C_GetSlotInfo slotID slotInfo michael@0: C_GetTokenInfo slotID tokenInfo michael@0: C_OpenSession slotID CKF_SERIAL_SESSION session michael@0: # michael@0: #uncomment the following line and include the correct password michael@0: #C_Login session CKU_USER 0000 4 michael@0: # michael@0: # build the search template michael@0: # michael@0: NewTemplate search CKA_CLASS michael@0: SetTemplate search 0 CKO_CERTIFICATE michael@0: NewArray certID CK_ULONG 10 michael@0: C_FindObjectsInit session search 1 michael@0: C_FindObjects session certID sizeA(certID) count michael@0: C_FindObjectsFinal session michael@0: # michael@0: # now read the cert out michael@0: # michael@0: #NewTemplate derCert CKA_VALUE michael@0: #NewTemplate certName CKA_LABEL,CKA_VALUE michael@0: #C_GetAttributeValue session certID[0] certName sizeA(certName) michael@0: #BuildTemplate certName michael@0: #C_GetAttributeValue session certID[0] certName sizeA(certName) michael@0: #print certName[0] michael@0: Set countm1 count michael@0: Decrement countm1 1 michael@0: LoopRun pLabel1 i 0 countm1 1 michael@0: Set i 1 michael@0: run pLabel1 michael@0: NewTemplate id CKA_CLASS,CKA_ID michael@0: C_GetAttributeValue session certID[i] id sizeA(id) michael@0: BuildTemplate id michael@0: C_GetAttributeValue session certID[i] id sizeA(id) michael@0: SetTemplate id 0 CKO_PRIVATE_KEY michael@0: NewArray keyID CK_ULONG 10 michael@0: C_FindObjectsInit session id sizeA(id) michael@0: C_FindObjects session keyID sizeA(keyID) count michael@0: C_FindObjectsFinal session michael@0: michael@0: NewMechanism rsaParams CKM_RSA_PKCS michael@0: NewArray sign data 256 michael@0: NewArray sdata data 36 michael@0: C_SignInit session rsaParams keyID[0] michael@0: print sdata michael@0: C_Sign session sdata sizeof(sdata) sign sizeof(sign) michael@0: save signature sign michael@0: save hash sdata michael@0: NewTemplate privValue CKA_MODULUS,CKA_PUBLIC_EXPONENT michael@0: C_GetAttributeValue session keyID[0] privValue sizeA(privValue) michael@0: BuildTemplate privValue michael@0: C_GetAttributeValue session keyID[0] privValue sizeA(privValue) michael@0: print privValue[0] michael@0: print privValue[1] michael@0: michael@0: # save the public key michael@0: SetTemplate id 0 CKO_PUBLIC_KEY michael@0: NewArray pubkeyID CK_ULONG 10 michael@0: C_FindObjectsInit session id sizeA(id) michael@0: C_FindObjects session pubkeyID sizeA(pubkeyID) count michael@0: C_FindObjectsFinal session michael@0: NewTemplate pubkeyValue CKA_MODULUS,CKA_PUBLIC_EXPONENT michael@0: C_GetAttributeValue session pubkeyID[0] pubkeyValue sizeA(pubkeyValue) michael@0: BuildTemplate pubkeyValue michael@0: C_GetAttributeValue session pubkeyID[0] pubkeyValue sizeA(pubkeyValue) michael@0: print pubkeyValue[0] michael@0: print pubkeyValue[1] michael@0: michael@0: michael@0: C_Finalize null michael@0: unload michael@0: michael@0: # michael@0: # Now do the same for using softoken michael@0: # michael@0: load softokn3.dll michael@0: NewInitArg init CKF_OS_LOCKING_OK configdir=./db michael@0: C_Initialize init michael@0: C_GetSlotList false NULL slotCount michael@0: NewArray slotList CK_ULONG slotCount michael@0: C_GetSlotList false slotList slotCount michael@0: #change the following to the appropriate slot id michael@0: set slotID slotList[1] michael@0: #set slotID slotList[0] michael@0: C_GetSlotInfo slotID slotInfo michael@0: C_GetTokenInfo slotID tokenInfo michael@0: C_OpenSession slotID CKF_SERIAL_SESSION session michael@0: NewTemplate search CKA_CLASS michael@0: SetTemplate search 0 CKO_CERTIFICATE michael@0: NewArray certID CK_ULONG 10 michael@0: C_FindObjectsInit session search 1 michael@0: C_FindObjects session certID sizeA(certID) count michael@0: C_FindObjectsFinal session michael@0: # michael@0: # now read the cert out michael@0: # michael@0: #NewTemplate derCert CKA_VALUE michael@0: #NewTemplate certName CKA_LABEL,CKA_VALUE michael@0: #C_GetAttributeValue session certID[0] certName sizeA(certName) michael@0: #BuildTemplate certName michael@0: #C_GetAttributeValue session certID[0] certName sizeA(certName) michael@0: #print certName[0] michael@0: #Set countm1 count michael@0: #Decrement countm1 1 michael@0: #LoopRun pLabel1 i 0 countm1 1 michael@0: Set i 0 michael@0: run pLabel1 michael@0: NewTemplate id CKA_CLASS,CKA_ID michael@0: C_GetAttributeValue session certID[i] id sizeA(id) michael@0: BuildTemplate id michael@0: C_GetAttributeValue session certID[i] id sizeA(id) michael@0: SetTemplate id 0 CKO_PRIVATE_KEY michael@0: NewArray keyID CK_ULONG 10 michael@0: C_FindObjectsInit session id sizeA(id) michael@0: C_FindObjects session keyID sizeA(keyID) count michael@0: C_FindObjectsFinal session michael@0: michael@0: NewMechanism rsaParams CKM_RSA_PKCS michael@0: NewArray sign data 256 michael@0: NewArray sdata data 36 michael@0: C_SignInit session rsaParams keyID[0] michael@0: C_Sign session sdata sizeof(sdata) sign sizeof(sign) michael@0: save signature2 sign michael@0: save hash2 sdata michael@0: michael@0: SetTemplate id 0 CKO_PUBLIC_KEY michael@0: NewArray pubkeyID CK_ULONG 10 michael@0: C_FindObjectsInit session id sizeA(id) michael@0: C_FindObjects session pubkeyID sizeA(pubkeyID) count michael@0: C_FindObjectsFinal session michael@0: michael@0: # michael@0: # OK now we use raw unwrap and see what we have... michael@0: # michael@0: NewMechanism rawRsaParams CKM_RSA_X_509 michael@0: NewArray vdata data 256 michael@0: C_VerifyRecoverInit session rawRsaParams pubkeyID[0] michael@0: C_VerifyRecover session sign sizeof(sign) vdata sizeof(vdata) michael@0: save verify2 vdata michael@0: restore signature sign michael@0: C_VerifyRecoverInit session rawRsaParams pubkeyID[0] michael@0: C_VerifyRecover session sign sizeof(sign) vdata sizeof(vdata) michael@0: save verify vdata michael@0: michael@0: NewTemplate pubkeyValue CKA_MODULUS,CKA_PUBLIC_EXPONENT michael@0: C_GetAttributeValue session pubkeyID[0] pubkeyValue sizeA(pubkeyValue) michael@0: BuildTemplate pubkeyValue michael@0: C_GetAttributeValue session pubkeyID[0] pubkeyValue sizeA(pubkeyValue) michael@0: print pubkeyValue[0] michael@0: print pubkeyValue[1] michael@0: michael@0: michael@0: C_Finalize null michael@0: michael@0: unload