root/pykcs11/trunk/samples/LowLevel/InitTokenPin.py

Revision 48, 3.3 kB (checked in by lrousseau, 2 years ago)

update FSF postal address

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env python
2
3 #   Copyright (C) 2004 Midori (midori -- a-t -- paipai dot net)
4 #
5 # This file is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18
19 import PyKCS11.LowLevel
20
21 a = PyKCS11.LowLevel.CPKCS11Lib()
22 info = PyKCS11.LowLevel.CK_INFO()
23 slotInfo = PyKCS11.LowLevel.CK_SLOT_INFO()
24 lib = "pkcs11_lib.dll"
25 session = PyKCS11.LowLevel.CK_SESSION_HANDLE()
26 sessionInfo = PyKCS11.LowLevel.CK_SESSION_INFO()
27 tokenInfo = PyKCS11.LowLevel.CK_TOKEN_INFO()
28 slotList = PyKCS11.LowLevel.ckintlist()
29 pin = "123456"
30 puk = "12345678"
31 Label = "PyKCS#11 Initialized Token      "
32
33 print "Load of " + lib + ": " + str(a.Load(lib, 1))
34 print "C_GetInfo: " + hex(a.C_GetInfo(info))
35 print "Library manufacturerID: " + info.GetManufacturerID()
36 del info
37
38 print "C_GetSlotList(NULL): " + hex(a.C_GetSlotList(1, slotList))
39 print "\tAvailable Slots: " + str(len(slotList))
40
41 if len(slotList) != 0:
42     print "\tC_SlotInfo(): " + hex(a.C_GetSlotInfo(slotList[0], slotInfo))
43
44     print "\tC_GetTokenInfo(): " + hex(a.C_GetTokenInfo(slotList[0], tokenInfo))
45     print "\t\tTokenInfo: Label=" + tokenInfo.GetLabel() + ", ManufacturerID=" + tokenInfo.GetManufacturerID()
46     print "\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel()
47     print "\tC_InitToken(): " + hex(a.C_InitToken(slotList[0], puk, Label))
48
49     print "\tC_GetTokenInfo(): " + hex(a.C_GetTokenInfo(slotList[0], tokenInfo))
50     print "\t\tTokenInfo: Label=" + tokenInfo.GetLabel() + ", ManufacturerID=" + tokenInfo.GetManufacturerID()
51     print "\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel()
52
53     print "\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[0], PyKCS11.LowLevel.CKF_SERIAL_SESSION|PyKCS11.LowLevel.CKF_RW_SESSION, session))
54     print "\t\tSession:" + str(session)
55     print "\tC_GetSessionInfo(): " + hex(a.C_GetSessionInfo(session, sessionInfo))
56     print "\t\tSessionInfo: state=" + hex(sessionInfo.state) + ", flags=" + hex(sessionInfo.flags)
57
58     print "\tC_Login(SO): " + hex(a.C_Login(session, PyKCS11.LowLevel.CKU_SO, puk))
59     print "\tC_InitPIN(): " + hex(a.C_InitPIN(session, pin))
60     print "\tC_Logout(SO): " + hex(a.C_Logout(session))
61
62     print "\tC_GetTokenInfo(): " + hex(a.C_GetTokenInfo(slotList[0], tokenInfo))
63     print "\t\tTokenInfo: Label=" + tokenInfo.GetLabel() + ", ManufacturerID=" + tokenInfo.GetManufacturerID()
64     print "\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel()
65
66     print "C_Login(USER): " + hex(a.C_Login(session, PyKCS11.LowLevel.CKU_USER, pin))
67     print "C_Logout(USER): " + hex(a.C_Logout(session))
68     print "C_CloseSession(): " + hex(a.C_CloseSession(session))
69
70 print "C_Finalize(): " + hex(a.C_Finalize())
71 print a.Unload()
72
Note: See TracBrowser for help on using the browser.
(C) 2006 bit4id srl, for informations please contact info@bit4id.com
visitors since August 21, 2006