- Timestamp:
- 02/21/10 15:34:58 (5 months ago)
- Files:
-
- pykcs11/trunk/samples/LowLevel/InitTokenPin.py (modified) (2 diffs)
- pykcs11/trunk/samples/LowLevel/dumpit.py (modified) (3 diffs)
- pykcs11/trunk/samples/LowLevel/test.py (modified) (4 diffs)
- pykcs11/trunk/samples/LowLevel/test1.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pykcs11/trunk/samples/LowLevel/InitTokenPin.py
r48 r186 51 51 print "\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel() 52 52 53 print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[0], PyKCS11.LowLevel.CKF_SERIAL_SESSION |PyKCS11.LowLevel.CKF_RW_SESSION, session))53 print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[0], PyKCS11.LowLevel.CKF_SERIAL_SESSION | PyKCS11.LowLevel.CKF_RW_SESSION, session)) 54 54 print "\t\tSession:" + str(session) 55 55 print "\tC_GetSessionInfo(): " + hex(a.C_GetSessionInfo(session, sessionInfo)) … … 70 70 print "C_Finalize(): " + hex(a.C_Finalize()) 71 71 print a.Unload() 72 pykcs11/trunk/samples/LowLevel/dumpit.py
r92 r186 41 41 print "\tC_SlotInfo(): " + hex(a.C_GetSlotInfo(slotList[x], slotInfo)) 42 42 print "\t\tSlot N." + str(x) + ": ID=" + str(slotList[x]) + ", name='" + slotInfo.GetSlotDescription() + "'" 43 print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[x], CKF_SERIAL_SESSION |CKF_RW_SESSION, session))43 print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[x], CKF_SERIAL_SESSION | CKF_RW_SESSION, session)) 44 44 print "\t\tSession:" + str(session) 45 45 print "\tC_GetSessionInfo(): " + hex(a.C_GetSessionInfo(session, sessionInfo)) … … 49 49 print "\t\tTokenInfo: Label=" + tokenInfo.GetLabel() + ", ManufacturerID=" + tokenInfo.GetManufacturerID() 50 50 print "\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel() 51 51 52 52 print "\tC_Login(): " + hex(a.C_Login(session, CKU_USER, pin)) 53 53 print "\tC_Logout(): " + hex(a.C_Logout(session)) … … 62 62 #SearchTemplate[1].SetBool(CKA_TOKEN, True) 63 63 64 print "C_FindObjectsInit: " + hex(a.C_FindObjectsInit(session, SearchTemplate))65 print "C_FindObjects: " + hex(a.C_FindObjects(session, SearchResult))66 print "C_FindObjectsFinal: " + hex(a.C_FindObjectsFinal(session))64 print "C_FindObjectsInit: " + hex(a.C_FindObjectsInit(session, SearchTemplate)) 65 print "C_FindObjects: " + hex(a.C_FindObjects(session, SearchResult)) 66 print "C_FindObjectsFinal: " + hex(a.C_FindObjectsFinal(session)) 67 67 68 68 attributes = [ 69 ["CKA_CLASS", CKA_CLASS],70 ["CKA_TOKEN", CKA_TOKEN],71 ["CKA_PRIVATE", CKA_PRIVATE],72 ["CKA_LABEL", CKA_LABEL],73 ["CKA_APPLICATION", CKA_APPLICATION],74 ["CKA_VALUE", CKA_VALUE],75 ["CKA_CERTIFICATE_TYPE", CKA_CERTIFICATE_TYPE],76 ["CKA_ISSUER", CKA_ISSUER],77 ["CKA_SERIAL_NUMBER", CKA_SERIAL_NUMBER],78 ["CKA_KEY_TYPE", CKA_KEY_TYPE],79 ["CKA_SUBJECT", CKA_SUBJECT],80 ["CKA_ID", CKA_ID],81 ["CKA_SENSITIVE", CKA_SENSITIVE],82 ["CKA_ENCRYPT", CKA_ENCRYPT],83 ["CKA_DECRYPT", CKA_DECRYPT],84 ["CKA_WRAP", CKA_WRAP],85 ["CKA_UNWRAP", CKA_UNWRAP],86 ["CKA_SIGN", CKA_SIGN],87 ["CKA_SIGN_RECOVER", CKA_SIGN_RECOVER],88 ["CKA_VERIFY", CKA_VERIFY],89 ["CKA_VERIFY_RECOVER", CKA_VERIFY_RECOVER],90 ["CKA_DERIVE", CKA_DERIVE],91 ["CKA_START_DATE", CKA_START_DATE],92 ["CKA_END_DATE", CKA_END_DATE],93 ["CKA_MODULUS", CKA_MODULUS],94 ["CKA_MODULUS_BITS", CKA_MODULUS_BITS],95 ["CKA_PUBLIC_EXPONENT", CKA_PUBLIC_EXPONENT],96 ["CKA_PRIVATE_EXPONENT", CKA_PRIVATE_EXPONENT],97 ["CKA_PRIME_1", CKA_PRIME_1],98 ["CKA_PRIME_2", CKA_PRIME_2],99 ["CKA_EXPONENT_1", CKA_EXPONENT_1],100 ["CKA_EXPONENT_2", CKA_EXPONENT_2],101 ["CKA_COEFFICIENT", CKA_COEFFICIENT],102 ["CKA_PRIME", CKA_PRIME],103 ["CKA_SUBPRIME", CKA_SUBPRIME],104 ["CKA_BASE", CKA_BASE],105 ["CKA_VALUE_BITS", CKA_VALUE_BITS],106 ["CKA_VALUE_LEN", CKA_VALUE_LEN],107 ["CKA_EXTRACTABLE", CKA_EXTRACTABLE],108 ["CKA_LOCAL", CKA_LOCAL],109 ["CKA_NEVER_EXTRACTABLE", CKA_NEVER_EXTRACTABLE],110 ["CKA_ALWAYS_SENSITIVE", CKA_ALWAYS_SENSITIVE],111 ["CKA_MODIFIABLE", CKA_MODIFIABLE],112 ["CKA_ECDSA_PARAMS", CKA_ECDSA_PARAMS],113 ["CKA_EC_POINT", CKA_EC_POINT],114 ]69 ["CKA_CLASS", CKA_CLASS], 70 ["CKA_TOKEN", CKA_TOKEN], 71 ["CKA_PRIVATE", CKA_PRIVATE], 72 ["CKA_LABEL", CKA_LABEL], 73 ["CKA_APPLICATION", CKA_APPLICATION], 74 ["CKA_VALUE", CKA_VALUE], 75 ["CKA_CERTIFICATE_TYPE", CKA_CERTIFICATE_TYPE], 76 ["CKA_ISSUER", CKA_ISSUER], 77 ["CKA_SERIAL_NUMBER", CKA_SERIAL_NUMBER], 78 ["CKA_KEY_TYPE", CKA_KEY_TYPE], 79 ["CKA_SUBJECT", CKA_SUBJECT], 80 ["CKA_ID", CKA_ID], 81 ["CKA_SENSITIVE", CKA_SENSITIVE], 82 ["CKA_ENCRYPT", CKA_ENCRYPT], 83 ["CKA_DECRYPT", CKA_DECRYPT], 84 ["CKA_WRAP", CKA_WRAP], 85 ["CKA_UNWRAP", CKA_UNWRAP], 86 ["CKA_SIGN", CKA_SIGN], 87 ["CKA_SIGN_RECOVER", CKA_SIGN_RECOVER], 88 ["CKA_VERIFY", CKA_VERIFY], 89 ["CKA_VERIFY_RECOVER", CKA_VERIFY_RECOVER], 90 ["CKA_DERIVE", CKA_DERIVE], 91 ["CKA_START_DATE", CKA_START_DATE], 92 ["CKA_END_DATE", CKA_END_DATE], 93 ["CKA_MODULUS", CKA_MODULUS], 94 ["CKA_MODULUS_BITS", CKA_MODULUS_BITS], 95 ["CKA_PUBLIC_EXPONENT", CKA_PUBLIC_EXPONENT], 96 ["CKA_PRIVATE_EXPONENT", CKA_PRIVATE_EXPONENT], 97 ["CKA_PRIME_1", CKA_PRIME_1], 98 ["CKA_PRIME_2", CKA_PRIME_2], 99 ["CKA_EXPONENT_1", CKA_EXPONENT_1], 100 ["CKA_EXPONENT_2", CKA_EXPONENT_2], 101 ["CKA_COEFFICIENT", CKA_COEFFICIENT], 102 ["CKA_PRIME", CKA_PRIME], 103 ["CKA_SUBPRIME", CKA_SUBPRIME], 104 ["CKA_BASE", CKA_BASE], 105 ["CKA_VALUE_BITS", CKA_VALUE_BITS], 106 ["CKA_VALUE_LEN", CKA_VALUE_LEN], 107 ["CKA_EXTRACTABLE", CKA_EXTRACTABLE], 108 ["CKA_LOCAL", CKA_LOCAL], 109 ["CKA_NEVER_EXTRACTABLE", CKA_NEVER_EXTRACTABLE], 110 ["CKA_ALWAYS_SENSITIVE", CKA_ALWAYS_SENSITIVE], 111 ["CKA_MODIFIABLE", CKA_MODIFIABLE], 112 ["CKA_ECDSA_PARAMS", CKA_ECDSA_PARAMS], 113 ["CKA_EC_POINT", CKA_EC_POINT], 114 ] 115 115 116 116 for x in SearchResult: 117 print "object: " + hex(x.value())118 valTemplate = ckattrlist(1)119 for attr in attributes:120 valTemplate[0].Reset()121 valTemplate[0].SetType(attr[1])122 # first call to get the attribute size and reserve the memory123 a.C_GetAttributeValue(session, x, valTemplate)124 # second call to get the attribute value125 rv = a.C_GetAttributeValue(session, x, valTemplate)126 if (rv == CKR_OK):127 print "\t" + attr[0] + ": ",128 if (valTemplate[0].IsNum()):129 print valTemplate[0].GetNum()130 if (valTemplate[0].IsBool()):131 print valTemplate[0].GetBool()132 if (valTemplate[0].IsString()):133 print valTemplate[0].GetString()134 if (valTemplate[0].IsBin()):135 print "(" + str(valTemplate[0].GetLen()) + " bytes)",136 print map(hex, valTemplate[0].GetBin())137 117 print "object: " + hex(x.value()) 118 valTemplate = ckattrlist(1) 119 for attr in attributes: 120 valTemplate[0].Reset() 121 valTemplate[0].SetType(attr[1]) 122 # first call to get the attribute size and reserve the memory 123 a.C_GetAttributeValue(session, x, valTemplate) 124 # second call to get the attribute value 125 rv = a.C_GetAttributeValue(session, x, valTemplate) 126 if (rv == CKR_OK): 127 print "\t" + attr[0] + ": ", 128 if (valTemplate[0].IsNum()): 129 print valTemplate[0].GetNum() 130 if (valTemplate[0].IsBool()): 131 print valTemplate[0].GetBool() 132 if (valTemplate[0].IsString()): 133 print valTemplate[0].GetString() 134 if (valTemplate[0].IsBin()): 135 print "(" + str(valTemplate[0].GetLen()) + " bytes)", 136 print map(hex, valTemplate[0].GetBin()) 137 138 138 print "C_Logout(): " + hex(a.C_Logout(session)) 139 139 print "C_CloseSession(): " + hex(a.C_CloseSession(session)) 140 140 print "C_Finalize(): " + hex(a.C_Finalize()) 141 141 print a.Unload() 142 pykcs11/trunk/samples/LowLevel/test.py
r92 r186 40 40 print "\tC_SlotInfo(): " + hex(a.C_GetSlotInfo(slotList[x], slotInfo)) 41 41 print "\t\tSlot N." + str(x) + ": ID=" + str(slotList[x]) + ", name='" + slotInfo.GetSlotDescription() + "'" 42 print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[x], PyKCS11.LowLevel.CKF_SERIAL_SESSION |PyKCS11.LowLevel.CKF_RW_SESSION, session))42 print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[x], PyKCS11.LowLevel.CKF_SERIAL_SESSION | PyKCS11.LowLevel.CKF_RW_SESSION, session)) 43 43 print "\t\tSession:" + str(session) 44 44 print "\tC_GetSessionInfo(): " + hex(a.C_GetSessionInfo(session, sessionInfo)) … … 48 48 print "\t\tTokenInfo: Label=" + tokenInfo.GetLabel() + ", ManufacturerID=" + tokenInfo.GetManufacturerID() 49 49 print "\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel() 50 50 51 51 print "\tC_Login(): " + hex(a.C_Login(session, PyKCS11.LowLevel.CKU_USER, pin)) 52 52 print "\tC_Logout(): " + hex(a.C_Logout(session)) … … 61 61 SearchTemplate[1].SetBool(PyKCS11.LowLevel.CKA_TOKEN, True) 62 62 63 print "C_FindObjectsInit: " + hex(a.C_FindObjectsInit(session, SearchTemplate))64 print "C_FindObjects: " + hex(a.C_FindObjects(session, SearchResult))65 print "C_FindObjectsFinal: " + hex(a.C_FindObjectsFinal(session))63 print "C_FindObjectsInit: " + hex(a.C_FindObjectsInit(session, SearchTemplate)) 64 print "C_FindObjects: " + hex(a.C_FindObjects(session, SearchResult)) 65 print "C_FindObjectsFinal: " + hex(a.C_FindObjectsFinal(session)) 66 66 67 67 for x in SearchResult: … … 73 73 #valTemplate[1].Reserve(4) 74 74 print "C_GetAttributeValue(): " + hex(a.C_GetAttributeValue(session, x, valTemplate)) 75 print "CKA_LABEL Len: ", valTemplate[0].GetLen(), " CKA_CLASS Len: ", valTemplate[1].GetLen()76 print "C_GetAttributeValue(): " + hex(a.C_GetAttributeValue(session, x, valTemplate)) 75 print "CKA_LABEL Len: ", valTemplate[0].GetLen(), " CKA_CLASS Len: ", valTemplate[1].GetLen() 76 print "C_GetAttributeValue(): " + hex(a.C_GetAttributeValue(session, x, valTemplate)) 77 77 print "\tCKO_CERTIFICATE: " + valTemplate[0].GetString() 78 78 print "\tCKA_TOKEN: " + str(valTemplate[1].GetNum()) 79 79 80 80 print "C_Logout(): " + hex(a.C_Logout(session)) 81 81 print "C_CloseSession(): " + hex(a.C_CloseSession(session)) 82 82 print "C_Finalize(): " + hex(a.C_Finalize()) 83 83 print a.Unload() 84 pykcs11/trunk/samples/LowLevel/test1.py
r92 r186 40 40 print "\tC_SlotInfo(): " + hex(a.C_GetSlotInfo(slotList[x], slotInfo)) 41 41 print "\t\tSlot N." + str(x) + ": ID=" + str(slotList[x]) + ", name='" + slotInfo.GetSlotDescription() + "'" 42 print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[x], PyKCS11.LowLevel.CKF_SERIAL_SESSION |PyKCS11.LowLevel.CKF_RW_SESSION, session))42 print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[x], PyKCS11.LowLevel.CKF_SERIAL_SESSION | PyKCS11.LowLevel.CKF_RW_SESSION, session)) 43 43 print "\t\tSession:" + str(session) 44 44 print "\tC_GetSessionInfo(): " + hex(a.C_GetSessionInfo(session, sessionInfo)) … … 48 48 print "\t\tTokenInfo: Label=" + tokenInfo.GetLabel() + ", ManufacturerID=" + tokenInfo.GetManufacturerID() 49 49 print "\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel() 50 50 51 51 print "\tC_Login(): " + hex(a.C_Login(session, PyKCS11.LowLevel.CKU_USER, pin)) 52 52 print "\tC_Logout(): " + hex(a.C_Logout(session)) 53 53 print "\tC_CloseSession(): " + hex(a.C_CloseSession(session)) 54 54 55 print "C_OpenSession(): " + hex(a.C_OpenSession(slotList[0], PyKCS11.LowLevel.CKF_RW_SESSION |PyKCS11.LowLevel.CKF_SERIAL_SESSION, session))55 print "C_OpenSession(): " + hex(a.C_OpenSession(slotList[0], PyKCS11.LowLevel.CKF_RW_SESSION | PyKCS11.LowLevel.CKF_SERIAL_SESSION, session)) 56 56 print "C_Login(): " + hex(a.C_Login(session, PyKCS11.LowLevel.CKU_USER, pin)) 57 57 … … 61 61 SearchTemplate[1].SetBool(PyKCS11.LowLevel.CKA_TOKEN, True) 62 62 63 print "C_FindObjectsInit: " + hex(a.C_FindObjectsInit(session, SearchTemplate))64 print "C_FindObjects: " + hex(a.C_FindObjects(session, SearchResult))65 print "C_FindObjectsFinal: " + hex(a.C_FindObjectsFinal(session))63 print "C_FindObjectsInit: " + hex(a.C_FindObjectsInit(session, SearchTemplate)) 64 print "C_FindObjects: " + hex(a.C_FindObjects(session, SearchResult)) 65 print "C_FindObjectsFinal: " + hex(a.C_FindObjectsFinal(session)) 66 66 67 67 for x in SearchResult: … … 75 75 binval = list(valTemplate[0].GetBin()) 76 76 print "binval=", binval 77 binval[0] = 0 ;77 binval[0] = 0 78 78 valTemplate[0].SetBin(PyKCS11.LowLevel.CKA_ISSUER, binval) 79 79 binval = valTemplate[0].GetBin() # list(valTemplate[0].GetBin()) 80 80 print "binval[0]=", binval[0] 81 binval[0] = 0 ;82 81 binval[0] = 0 82 83 83 print "C_SetAttributeValue(): " + hex(a.C_SetAttributeValue(session, x, valTemplate)) 84 84 85 85 print "C_Logout(): " + hex(a.C_Logout(session)) 86 86 print "C_CloseSession(): " + hex(a.C_CloseSession(session)) 87 87 print "C_Finalize(): " + hex(a.C_Finalize()) 88 88 print a.Unload() 89
