GithubHelp home page GithubHelp logo

Comments (13)

jariq avatar jariq commented on May 29, 2024

It seems like the PKCS#11 library you are using does not support internal locking for access from multiple threads. You should specify "false" as a value of "useOsLocking" parameter in Net.Pkcs11Interop.HighLevelAPI.Pkcs11 constructor.

Example can be found here:
http://www.pkcs11interop.net/doc/02__high_level_a_p_i_201__initialize_test_8cs-example.html

Relevant part from example:

        // If an application will not be accessing PKCS#11 library from multiple threads
        // simultaneously, it should specify "false" as a value of "useOsLocking" parameter.
        using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, false))
        {
            // Do something interesting
        }

from pkcs11interop.

vanhonit avatar vanhonit commented on May 29, 2024

Thanks you so much, but if have impolite question, are you testing all function in example docs ? because i try to run function create object but this can not create ? I'm try use command line " pkcs11-tool --module=libOpenPGP11_64.so -l -w password.txt --label "my password" --pin 123456 -y data" this work. but try with your function can't.

from pkcs11interop.

jariq avatar jariq commented on May 29, 2024

Yes all the tests have to pass before each release with Siemens CardOS card and Siemens Card API middleware. However different cards may require different treatment. For example OpenSC cards require you to login with Security Officer PIN (PUK) if you want to create new object on the card. I simply cannot cover all possibilities in examples.

You're quite lucky that pkcs11-tool is able to create your object because now you can use pkcs11-logger to intercept all PKCS#11 function calls made by pkcs11-tool and then repeat this sequence in your program.

This is how you should modify your command to log all PKCS#11 function calls:

PKCS11_LOGGER_ORIG_LIB="libOpenPGP11_64.so" pkcs11-tool --module=pkcs11-logger.so -l -w password.txt --label "my password" --pin 123456 -y data

All functions along with the input and output parameters should be logged to "/tmp/pkcs11-logger.log".

Please also note that each PKCS#11 function returns CKR code that tells you why did the function fail. CKR code should be present in every Pkcs11Exception coming out of the Pkcs11Interop library. Please see the documentation - http://pkcs11interop.net/doc/ - for the complete list of CKR codes.

Please provide me with the full stack trace of the exception you receive if you need more assistance.

from pkcs11interop.

vanhonit avatar vanhonit commented on May 29, 2024

Hi Jariq,
Please see my log:

0x000021e3 : 0x4ed0b780 : ****************************** 2013-05-13 16:44:00 ***
0x000021e3 : 0x4ed0b780 : PCKS11-LOGGER 1.0 - Successfuly loaded /home/honnguyen/libOpenPGP11_64.so
0x000021e3 : 0x4ed0b780 : ****************************** 2013-05-13 16:44:00 ***
0x000021e3 : 0x4ed0b780 : Calling C_Initialize
0x000021e3 : 0x4ed0b780 : Input
0x000021e3 : 0x4ed0b780 :  pInitArgs: (nil)
0x000021e3 : 0x4ed0b780 : Returning 0 (CKR_OK)
0x000021e3 : 0x4ed0b780 : ****************************** 2013-05-13 16:44:00 ***
0x000021e3 : 0x4ed0b780 : Calling C_GetSlotList
0x000021e3 : 0x4ed0b780 : Input
0x000021e3 : 0x4ed0b780 :  tokenPresent: 0
0x000021e3 : 0x4ed0b780 :  pSlotList: (nil)
0x000021e3 : 0x4ed0b780 :  pulCount: 0x7fff18e7aaf0
0x000021e3 : 0x4ed0b780 :  *pulCount: 0
0x000021e3 : 0x4ed0b780 : Output
0x000021e3 : 0x4ed0b780 :  pSlotList: (nil)
0x000021e3 : 0x4ed0b780 :  pulCount: 0x7fff18e7aaf0
0x000021e3 : 0x4ed0b780 :  *pulCount: 2
0x000021e3 : 0x4ed0b780 : Returning 0 (CKR_OK)
0x000021e3 : 0x4ed0b780 : ****************************** 2013-05-13 16:44:00 ***
0x000021e3 : 0x4ed0b780 : Calling C_GetSlotList
0x000021e3 : 0x4ed0b780 : Input
0x000021e3 : 0x4ed0b780 :  tokenPresent: 0
0x000021e3 : 0x4ed0b780 :  pSlotList: 0x7ffc46ce9ca0
0x000021e3 : 0x4ed0b780 :  pulCount: 0x7fff18e7aaf0
0x000021e3 : 0x4ed0b780 :  *pulCount: 2
0x000021e3 : 0x4ed0b780 : Output
0x000021e3 : 0x4ed0b780 :  pSlotList: 0x7ffc46ce9ca0
0x000021e3 : 0x4ed0b780 :  pSlotList[0]: 2
0x000021e3 : 0x4ed0b780 :  pSlotList[1]: 1
0x000021e3 : 0x4ed0b780 :  pulCount: 0x7fff18e7aaf0
0x000021e3 : 0x4ed0b780 :  *pulCount: 2
0x000021e3 : 0x4ed0b780 : Returning 0 (CKR_OK)
0x000021e3 : 0x4ed0b780 : ****************************** 2013-05-13 16:44:00 ***
0x000021e3 : 0x4ed0b780 : Calling C_OpenSession
0x000021e3 : 0x4ed0b780 : Input
0x000021e3 : 0x4ed0b780 :  slotID: 2
0x000021e3 : 0x4ed0b780 :  flags: 6
0x000021e3 : 0x4ed0b780 :   CKF_RW_SESSION: TRUE
0x000021e3 : 0x4ed0b780 :   CKF_SERIAL_SESSION: TRUE
0x000021e3 : 0x4ed0b780 :  pApplication: (nil)
0x000021e3 : 0x4ed0b780 :  Notify: (nil)
0x000021e3 : 0x4ed0b780 :  phSession: 0x7fff18e7aae8
0x000021e3 : 0x4ed0b780 :  *phSession: 140733611223784
0x000021e3 : 0x4ed0b780 : Output
0x000021e3 : 0x4ed0b780 :  phSession: 0x7fff18e7aae8
0x000021e3 : 0x4ed0b780 :  *phSession: 1
0x000021e3 : 0x4ed0b780 : Returning 0 (CKR_OK)
0x000021e3 : 0x4ed0b780 : ****************************** 2013-05-13 16:44:01 ***
0x000021e3 : 0x4ed0b780 : Calling C_Login
0x000021e3 : 0x4ed0b780 : Input
0x000021e3 : 0x4ed0b780 :  hSession: 1
0x000021e3 : 0x4ed0b780 :  userType: 1 (CKU_USER)
0x000021e3 : 0x4ed0b780 :  pPin: 0x7ffc46ce9598
0x000021e3 : 0x4ed0b780 :  *pPin: 123456
0x000021e3 : 0x4ed0b780 :  ulPinLen: 6
0x000021e3 : 0x4ed0b780 : Returning 0 (CKR_OK)
0x000021e3 : 0x4ed0b780 : ****************************** 2013-05-13 16:44:01 ***
0x000021e3 : 0x4ed0b780 : Calling C_CreateObject
0x000021e3 : 0x4ed0b780 : Input
0x000021e3 : 0x4ed0b780 :  hSession: 1
0x000021e3 : 0x4ed0b780 :  pTemplate: 0x7ffc4605ee20
0x000021e3 : 0x4ed0b780 :  ulCount: 5
0x000021e3 : 0x4ed0b780 :   Attribute 0
0x000021e3 : 0x4ed0b780 :    Attribute: 116142993789943808 (Unknown)
0x000021e3 : 0x4ed0b780 :    pValue: 0x400000000
0x000021e3 : 0x4ed0b780 :    ulValueLen: 116265658055917569
0x000021fd : 0xccac8780 : ****************************** 2013-05-13 16:44:17 ***
0x000021fd : 0xccac8780 : PCKS11-LOGGER 1.0 - Successfuly loaded /home/honnguyen/libOpenPGP11_64.so
0x000021fd : 0xccac8780 : ****************************** 2013-05-13 16:44:17 ***
0x000021fd : 0xccac8780 : Calling C_Initialize
0x000021fd : 0xccac8780 : Input
0x000021fd : 0xccac8780 :  pInitArgs: (nil)
0x000021fd : 0xccac8780 : Returning 0 (CKR_OK)
0x000021fd : 0xccac8780 : ****************************** 2013-05-13 16:44:17 ***
0x000021fd : 0xccac8780 : Calling C_GetSlotList
0x000021fd : 0xccac8780 : Input
0x000021fd : 0xccac8780 :  tokenPresent: 0
0x000021fd : 0xccac8780 :  pSlotList: (nil)
0x000021fd : 0xccac8780 :  pulCount: 0x7fff9f13a2e0
0x000021fd : 0xccac8780 :  *pulCount: 0
0x000021fd : 0xccac8780 : Output
0x000021fd : 0xccac8780 :  pSlotList: (nil)
0x000021fd : 0xccac8780 :  pulCount: 0x7fff9f13a2e0
0x000021fd : 0xccac8780 :  *pulCount: 2
0x000021fd : 0xccac8780 : Returning 0 (CKR_OK)
0x000021fd : 0xccac8780 : ****************************** 2013-05-13 16:44:17 ***
0x000021fd : 0xccac8780 : Calling C_GetSlotList
0x000021fd : 0xccac8780 : Input
0x000021fd : 0xccac8780 :  tokenPresent: 0
0x000021fd : 0xccac8780 :  pSlotList: 0x7f7ac4aa6ca0
0x000021fd : 0xccac8780 :  pulCount: 0x7fff9f13a2e0
0x000021fd : 0xccac8780 :  *pulCount: 2
0x000021fd : 0xccac8780 : Output
0x000021fd : 0xccac8780 :  pSlotList: 0x7f7ac4aa6ca0
0x000021fd : 0xccac8780 :  pSlotList[0]: 2
0x000021fd : 0xccac8780 :  pSlotList[1]: 1
0x000021fd : 0xccac8780 :  pulCount: 0x7fff9f13a2e0
0x000021fd : 0xccac8780 :  *pulCount: 2
0x000021fd : 0xccac8780 : Returning 0 (CKR_OK)
0x000021fd : 0xccac8780 : ****************************** 2013-05-13 16:44:17 ***
0x000021fd : 0xccac8780 : Calling C_OpenSession
0x000021fd : 0xccac8780 : Input
0x000021fd : 0xccac8780 :  slotID: 2
0x000021fd : 0xccac8780 :  flags: 6
0x000021fd : 0xccac8780 :   CKF_RW_SESSION: TRUE
0x000021fd : 0xccac8780 :   CKF_SERIAL_SESSION: TRUE
0x000021fd : 0xccac8780 :  pApplication: (nil)
0x000021fd : 0xccac8780 :  Notify: (nil)
0x000021fd : 0xccac8780 :  phSession: 0x7fff9f13a2d8
0x000021fd : 0xccac8780 :  *phSession: 140735862252248
0x000021fd : 0xccac8780 : Output
0x000021fd : 0xccac8780 :  phSession: 0x7fff9f13a2d8
0x000021fd : 0xccac8780 :  *phSession: 1
0x000021fd : 0xccac8780 : Returning 0 (CKR_OK)
0x000021fd : 0xccac8780 : ****************************** 2013-05-13 16:44:18 ***
0x000021fd : 0xccac8780 : Calling C_Login
0x000021fd : 0xccac8780 : Input
0x000021fd : 0xccac8780 :  hSession: 1
0x000021fd : 0xccac8780 :  userType: 1 (CKU_USER)
0x000021fd : 0xccac8780 :  pPin: 0x7f7ac4aa6598
0x000021fd : 0xccac8780 :  *pPin: 123456
0x000021fd : 0xccac8780 :  ulPinLen: 6
0x000021fd : 0xccac8780 : Returning 0 (CKR_OK)
0x000021fd : 0xccac8780 : ****************************** 2013-05-13 16:44:18 ***
0x000021fd : 0xccac8780 : Calling C_CreateObject
0x000021fd : 0xccac8780 : Input
0x000021fd : 0xccac8780 :  hSession: 1
0x000021fd : 0xccac8780 :  pTemplate: 0x7f7ac414be20
0x000021fd : 0xccac8780 :  ulCount: 5
0x000021fd : 0xccac8780 :   Attribute 0
0x000021fd : 0xccac8780 :    Attribute: 141068166477381632 (Unknown)
0x000021fd : 0xccac8780 :    pValue: 0x400000000
0x000021fd : 0xccac8780 :    ulValueLen: 141061225810231297
0x000022e7 : 0x1cab6780 : ****************************** 2013-05-13 16:55:55 ***
0x000022e7 : 0x1cab6780 : PCKS11-LOGGER 1.0 - Successfuly loaded /home/honnguyen/libOpenPGP11_64.so
0x000022e7 : 0x1cab6780 : ****************************** 2013-05-13 16:55:55 ***
0x000022e7 : 0x1cab6780 : Calling C_Initialize
0x000022e7 : 0x1cab6780 : Input
0x000022e7 : 0x1cab6780 :  pInitArgs: (nil)
0x000022e7 : 0x1cab6780 : Returning 0 (CKR_OK)
0x000022e7 : 0x1cab6780 : ****************************** 2013-05-13 16:55:55 ***
0x000022e7 : 0x1cab6780 : Calling C_GetSlotList
0x000022e7 : 0x1cab6780 : Input
0x000022e7 : 0x1cab6780 :  tokenPresent: 0
0x000022e7 : 0x1cab6780 :  pSlotList: (nil)
0x000022e7 : 0x1cab6780 :  pulCount: 0x7fff520e14d0
0x000022e7 : 0x1cab6780 :  *pulCount: 0
0x000022e7 : 0x1cab6780 : Output
0x000022e7 : 0x1cab6780 :  pSlotList: (nil)
0x000022e7 : 0x1cab6780 :  pulCount: 0x7fff520e14d0
0x000022e7 : 0x1cab6780 :  *pulCount: 2
0x000022e7 : 0x1cab6780 : Returning 0 (CKR_OK)
0x000022e7 : 0x1cab6780 : ****************************** 2013-05-13 16:55:56 ***
0x000022e7 : 0x1cab6780 : Calling C_GetSlotList
0x000022e7 : 0x1cab6780 : Input
0x000022e7 : 0x1cab6780 :  tokenPresent: 0
0x000022e7 : 0x1cab6780 :  pSlotList: 0x7f8114a94ca0
0x000022e7 : 0x1cab6780 :  pulCount: 0x7fff520e14d0
0x000022e7 : 0x1cab6780 :  *pulCount: 2
0x000022e7 : 0x1cab6780 : Output
0x000022e7 : 0x1cab6780 :  pSlotList: 0x7f8114a94ca0
0x000022e7 : 0x1cab6780 :  pSlotList[0]: 2
0x000022e7 : 0x1cab6780 :  pSlotList[1]: 1
0x000022e7 : 0x1cab6780 :  pulCount: 0x7fff520e14d0
0x000022e7 : 0x1cab6780 :  *pulCount: 2
0x000022e7 : 0x1cab6780 : Returning 0 (CKR_OK)
0x000022e7 : 0x1cab6780 : ****************************** 2013-05-13 16:55:56 ***
0x000022e7 : 0x1cab6780 : Calling C_OpenSession
0x000022e7 : 0x1cab6780 : Input
0x000022e7 : 0x1cab6780 :  slotID: 2
0x000022e7 : 0x1cab6780 :  flags: 6
0x000022e7 : 0x1cab6780 :   CKF_RW_SESSION: TRUE
0x000022e7 : 0x1cab6780 :   CKF_SERIAL_SESSION: TRUE
0x000022e7 : 0x1cab6780 :  pApplication: (nil)
0x000022e7 : 0x1cab6780 :  Notify: (nil)
0x000022e7 : 0x1cab6780 :  phSession: 0x7fff520e14c8
0x000022e7 : 0x1cab6780 :  *phSession: 140734570042568
0x000022e7 : 0x1cab6780 : Output
0x000022e7 : 0x1cab6780 :  phSession: 0x7fff520e14c8
0x000022e7 : 0x1cab6780 :  *phSession: 1
0x000022e7 : 0x1cab6780 : Returning 0 (CKR_OK)
0x000022e7 : 0x1cab6780 : ****************************** 2013-05-13 16:55:56 ***
0x000022e7 : 0x1cab6780 : Calling C_Login
0x000022e7 : 0x1cab6780 : Input
0x000022e7 : 0x1cab6780 :  hSession: 1
0x000022e7 : 0x1cab6780 :  userType: 1 (CKU_USER)
0x000022e7 : 0x1cab6780 :  pPin: 0x7f8114a94598
0x000022e7 : 0x1cab6780 :  *pPin: 123456
0x000022e7 : 0x1cab6780 :  ulPinLen: 6
0x000022e7 : 0x1cab6780 : Returning 0 (CKR_OK)
0x000022e7 : 0x1cab6780 : ****************************** 2013-05-13 16:55:57 ***
0x000022e7 : 0x1cab6780 : Calling C_CreateObject
0x000022e7 : 0x1cab6780 : Input
0x000022e7 : 0x1cab6780 :  hSession: 1
0x000022e7 : 0x1cab6780 :  pTemplate: 0x7f811461a5f0
0x000022e7 : 0x1cab6780 :  ulCount: 1
0x000022e7 : 0x1cab6780 :   Attribute 0
0x000022e7 : 0x1cab6780 :    Attribute: 172409607988183057 (Unknown)
0x000022e7 : 0x1cab6780 :    pValue: 0x1300000000
0x000022e7 : 0x1cab6780 :    ulValueLen: 39401024

I see when call C_CreateObject the Attribute give wrong. Here true attibute

0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:46 ***
0x00002404 : 0x4605f740 : PCKS11-LOGGER 1.0 - Successfuly loaded /home/honnguyen/libOpenPGP11_64.so
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:46 ***
0x00002404 : 0x4605f740 : Calling C_GetFunctionList
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  ppFunctionList: 0x6179f0
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  Note: Returning function list of PCKS11-LOGGER
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:46 ***
0x00002404 : 0x4605f740 : Calling C_Initialize
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  pInitArgs: (nil)
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:46 ***
0x00002404 : 0x4605f740 : Calling C_GetSlotList
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  tokenPresent: 0
0x00002404 : 0x4605f740 :  pSlotList: (nil)
0x00002404 : 0x4605f740 :  pulCount: 0x617a00
0x00002404 : 0x4605f740 :  *pulCount: 0
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pSlotList: (nil)
0x00002404 : 0x4605f740 :  pulCount: 0x617a00
0x00002404 : 0x4605f740 :  *pulCount: 2
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetSlotList
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  tokenPresent: 0
0x00002404 : 0x4605f740 :  pSlotList: 0x1a71d40
0x00002404 : 0x4605f740 :  pulCount: 0x617a00
0x00002404 : 0x4605f740 :  *pulCount: 2
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pSlotList: 0x1a71d40
0x00002404 : 0x4605f740 :  pSlotList[0]: 2
0x00002404 : 0x4605f740 :  pSlotList[1]: 1
0x00002404 : 0x4605f740 :  pulCount: 0x617a00
0x00002404 : 0x4605f740 :  *pulCount: 2
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetSlotInfo
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  slotID: 2
0x00002404 : 0x4605f740 :  pInfo: 0x7fffe6985450
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pInfo: 0x7fffe6985450
0x00002404 : 0x4605f740 :   slotDescription: German Privacy Foundation Crypto Stick v1.2 00 00               
0x00002404 : 0x4605f740 :   manufacturerID: Dr. Peter Koch                  
0x00002404 : 0x4605f740 :   flags: 7
0x00002404 : 0x4605f740 :    CKF_TOKEN_PRESENT: TRUE
0x00002404 : 0x4605f740 :    CKF_REMOVABLE_DEVICE: TRUE
0x00002404 : 0x4605f740 :    CKF_HW_SLOT: TRUE
0x00002404 : 0x4605f740 :   hardwareVersion:
0x00002404 : 0x4605f740 :    major: 0
0x00002404 : 0x4605f740 :    minor: 0
0x00002404 : 0x4605f740 :   firmwareVersion:
0x00002404 : 0x4605f740 :    major: 1
0x00002404 : 0x4605f740 :    minor: 46
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_OpenSession
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  slotID: 2
0x00002404 : 0x4605f740 :  flags: 6
0x00002404 : 0x4605f740 :   CKF_RW_SESSION: TRUE
0x00002404 : 0x4605f740 :   CKF_SERIAL_SESSION: TRUE
0x00002404 : 0x4605f740 :  pApplication: (nil)
0x00002404 : 0x4605f740 :  Notify: (nil)
0x00002404 : 0x4605f740 :  phSession: 0x7fffe6984df0
0x00002404 : 0x4605f740 :  *phSession: 140737062129136
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  phSession: 0x7fffe6984df0
0x00002404 : 0x4605f740 :  *phSession: 1
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetTokenInfo
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  slotID: 2
0x00002404 : 0x4605f740 :  pInfo: 0x7fffe6984c80
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pInfo: 0x7fffe6984c80
0x00002404 : 0x4605f740 :   label: CryptoStick C7F                 
0x00002404 : 0x4605f740 :   manufacturerID: Dr. Peter Koch                  
0x00002404 : 0x4605f740 :   model: OpenPGP Card    
0x00002404 : 0x4605f740 :   serialNumber: 00000C7F        
0x00002404 : 0x4605f740 :   flags: 1036
0x00002404 : 0x4605f740 :    CKF_RNG: FALSE
0x00002404 : 0x4605f740 :    CKF_WRITE_PROTECTED: FALSE
0x00002404 : 0x4605f740 :    CKF_LOGIN_REQUIRED: TRUE
0x00002404 : 0x4605f740 :    CKF_USER_PIN_INITIALIZED: TRUE
0x00002404 : 0x4605f740 :    CKF_RESTORE_KEY_NOT_NEEDED: FALSE
0x00002404 : 0x4605f740 :    CKF_CLOCK_ON_TOKEN: FALSE
0x00002404 : 0x4605f740 :    CKF_PROTECTED_AUTHENTICATION_PATH: FALSE
0x00002404 : 0x4605f740 :    CKF_DUAL_CRYPTO_OPERATIONS: FALSE
0x00002404 : 0x4605f740 :    CKF_TOKEN_INITIALIZED: TRUE
0x00002404 : 0x4605f740 :    CKF_SECONDARY_AUTHENTICATION: FALSE
0x00002404 : 0x4605f740 :    CKF_USER_PIN_COUNT_LOW: FALSE
0x00002404 : 0x4605f740 :    CKF_USER_PIN_FINAL_TRY: FALSE
0x00002404 : 0x4605f740 :    CKF_USER_PIN_LOCKED: FALSE
0x00002404 : 0x4605f740 :    CKF_USER_PIN_TO_BE_CHANGED: FALSE
0x00002404 : 0x4605f740 :    CKF_SO_PIN_COUNT_LOW: FALSE
0x00002404 : 0x4605f740 :    CKF_SO_PIN_FINAL_TRY: FALSE
0x00002404 : 0x4605f740 :    CKF_SO_PIN_LOCKED: FALSE
0x00002404 : 0x4605f740 :    CKF_SO_PIN_TO_BE_CHANGED: FALSE
0x00002404 : 0x4605f740 :   ulMaxSessionCount: 0
0x00002404 : 0x4605f740 :   ulSessionCount: 18446744073709551615
0x00002404 : 0x4605f740 :   ulMaxRwSessionCount: 0
0x00002404 : 0x4605f740 :   ulRwSessionCount: 18446744073709551615
0x00002404 : 0x4605f740 :   ulMaxPinLen: 8
0x00002404 : 0x4605f740 :   ulMinPinLen: 4
0x00002404 : 0x4605f740 :   ulTotalPublicMemory: 18446744073709551615
0x00002404 : 0x4605f740 :   ulFreePublicMemory: 18446744073709551615
0x00002404 : 0x4605f740 :   ulTotalPrivateMemory: 18446744073709551615
0x00002404 : 0x4605f740 :   ulFreePrivateMemory: 18446744073709551615
0x00002404 : 0x4605f740 :   hardwareVersion:
0x00002404 : 0x4605f740 :    major: 0
0x00002404 : 0x4605f740 :    minor: 0
0x00002404 : 0x4605f740 :   firmwareVersion:
0x00002404 : 0x4605f740 :    major: 0
0x00002404 : 0x4605f740 :    minor: 0
0x00002404 : 0x4605f740 :   utcTime: 0000000000000000
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_Login
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  userType: 1 (CKU_USER)
0x00002404 : 0x4605f740 :  pPin: 0x7fffe69874a8
0x00002404 : 0x4605f740 :  *pPin: 123456
0x00002404 : 0x4605f740 :  ulPinLen: 6
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_CreateObject
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe69821b0
0x00002404 : 0x4605f740 :  ulCount: 4
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 0 (CKA_CLASS)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981b10
0x00002404 : 0x4605f740 :    ulValueLen: 8
0x00002404 : 0x4605f740 :    *pValue: HEX(0000000000000000)
0x00002404 : 0x4605f740 :   Attribute 1
0x00002404 : 0x4605f740 :    Attribute: 1 (CKA_TOKEN)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981aef
0x00002404 : 0x4605f740 :    ulValueLen: 1
0x00002404 : 0x4605f740 :    *pValue: HEX(01)
0x00002404 : 0x4605f740 :   Attribute 2
0x00002404 : 0x4605f740 :    Attribute: 17 (CKA_VALUE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe69839b0
0x00002404 : 0x4605f740 :    ulValueLen: 58
0x00002404 : 0x4605f740 :    *pValue: HEX(7361647364617364617364616461736461736461736461736461736461736461736461646173646173646167666462646267666A67686B6A6C0A)
0x00002404 : 0x4605f740 :   Attribute 3
0x00002404 : 0x4605f740 :    Attribute: 3 (CKA_LABEL)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6987496
0x00002404 : 0x4605f740 :    ulValueLen: 11
0x00002404 : 0x4605f740 :    *pValue: HEX(6D792070617373776F7264)
0x00002404 : 0x4605f740 :  phObject: 0x7fffe6981b18
0x00002404 : 0x4605f740 :  *phObject: 230514781399
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  phObject: 0x7fffe6981b18
0x00002404 : 0x4605f740 :  *phObject: 1
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetAttributeValue
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  hObject: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a20
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 3 (CKA_LABEL)
0x00002404 : 0x4605f740 :    pValue: (nil)
0x00002404 : 0x4605f740 :    ulValueLen: 0
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a20
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 3 (CKA_LABEL)
0x00002404 : 0x4605f740 :    pValue: (nil)
0x00002404 : 0x4605f740 :    ulValueLen: 11
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetAttributeValue
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  hObject: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a20
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 3 (CKA_LABEL)
0x00002404 : 0x4605f740 :    pValue: 0x1a72500
0x00002404 : 0x4605f740 :    ulValueLen: 11
0x00002404 : 0x4605f740 :    *pValue: HEX(0000000000000000000000)
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a20
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 3 (CKA_LABEL)
0x00002404 : 0x4605f740 :    pValue: 0x1a72500
0x00002404 : 0x4605f740 :    ulValueLen: 11
0x00002404 : 0x4605f740 :    *pValue: HEX(6D792070617373776F7264)
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetAttributeValue
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  hObject: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a60
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 16 (CKA_APPLICATION)
0x00002404 : 0x4605f740 :    pValue: (nil)
0x00002404 : 0x4605f740 :    ulValueLen: 0
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a60
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 16 (CKA_APPLICATION)
0x00002404 : 0x4605f740 :    pValue: (nil)
0x00002404 : 0x4605f740 :    ulValueLen: 18446744073709551615
0x00002404 : 0x4605f740 : Returning 18 (CKR_ATTRIBUTE_TYPE_INVALID)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetAttributeValue
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  hObject: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a60
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 18 (CKA_OBJECT_ID)
0x00002404 : 0x4605f740 :    pValue: (nil)
0x00002404 : 0x4605f740 :    ulValueLen: 0
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a60
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 18 (CKA_OBJECT_ID)
0x00002404 : 0x4605f740 :    pValue: (nil)
0x00002404 : 0x4605f740 :    ulValueLen: 18446744073709551615
0x00002404 : 0x4605f740 : Returning 18 (CKR_ATTRIBUTE_TYPE_INVALID)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetAttributeValue
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  hObject: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a30
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 368 (CKA_MODIFIABLE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981a2f
0x00002404 : 0x4605f740 :    ulValueLen: 1
0x00002404 : 0x4605f740 :    *pValue: HEX(00)
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a30
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 368 (CKA_MODIFIABLE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981a2f
0x00002404 : 0x4605f740 :    ulValueLen: 18446744073709551615
0x00002404 : 0x4605f740 :    *pValue: *** cannot be displayed ***
0x00002404 : 0x4605f740 : Returning 18 (CKR_ATTRIBUTE_TYPE_INVALID)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetAttributeValue
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  hObject: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a30
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 2 (CKA_PRIVATE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981a2f
0x00002404 : 0x4605f740 :    ulValueLen: 1
0x00002404 : 0x4605f740 :    *pValue: HEX(00)
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a30
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 2 (CKA_PRIVATE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981a2f
0x00002404 : 0x4605f740 :    ulValueLen: 1
0x00002404 : 0x4605f740 :    *pValue: HEX(00)
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetAttributeValue
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  hObject: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a30
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 368 (CKA_MODIFIABLE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981a2f
0x00002404 : 0x4605f740 :    ulValueLen: 1
0x00002404 : 0x4605f740 :    *pValue: HEX(00)
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a30
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 368 (CKA_MODIFIABLE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981a2f
0x00002404 : 0x4605f740 :    ulValueLen: 18446744073709551615
0x00002404 : 0x4605f740 :    *pValue: *** cannot be displayed ***
0x00002404 : 0x4605f740 : Returning 18 (CKR_ATTRIBUTE_TYPE_INVALID)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_GetAttributeValue
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 :  hObject: 1
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a30
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 2 (CKA_PRIVATE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981a2f
0x00002404 : 0x4605f740 :    ulValueLen: 1
0x00002404 : 0x4605f740 :    *pValue: HEX(00)
0x00002404 : 0x4605f740 : Output
0x00002404 : 0x4605f740 :  pTemplate: 0x7fffe6981a30
0x00002404 : 0x4605f740 :  ulCount: 1
0x00002404 : 0x4605f740 :   Attribute 0
0x00002404 : 0x4605f740 :    Attribute: 2 (CKA_PRIVATE)
0x00002404 : 0x4605f740 :    pValue: 0x7fffe6981a2f
0x00002404 : 0x4605f740 :    ulValueLen: 1
0x00002404 : 0x4605f740 :    *pValue: HEX(00)
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_CloseSession
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  hSession: 1
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)
0x00002404 : 0x4605f740 : ****************************** 2013-05-13 17:18:47 ***
0x00002404 : 0x4605f740 : Calling C_Finalize
0x00002404 : 0x4605f740 : Input
0x00002404 : 0x4605f740 :  pReserved: (nil)
0x00002404 : 0x4605f740 : Returning 0 (CKR_OK)

from pkcs11interop.

jariq avatar jariq commented on May 29, 2024

Can you please provide the code that produced this log?

from pkcs11interop.

vanhonit avatar vanhonit commented on May 29, 2024

Yes, I only copy all from your example

using System;
using Net.Pkcs11Interop.HighLevelAPI;
using Net.Pkcs11Interop.Common;
using System.Collections.Generic;
namespace test
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            //CKR rv = CKR.CKR_OK;
            Environment.SetEnvironmentVariable("PKCS11_LOGGER_ORIG_LIB", "/home/honnguyen/libOpenPGP11_64.so");
            using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath,false))
            {
                List slots = pkcs11.GetSlotList(false);
                Console.WriteLine(slots.Count);
                /*Console.WriteLine(slots.Count);
                SlotInfo slotinfo = slots[0].GetSlotInfo();
                Console.WriteLine(slotinfo.ManufacturerId);*/
                Slot slot = slots[0];
                
                // Open RO session
                using (Session session = slot.OpenSession(false))
                {
                     // Login as normal user
                    session.Login(CKU.CKU_USER, Settings.NormalUserPin);
                    
                    // Prepare attribute template of new data object
                    List objectAttributes = new List();
                    objectAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, 0));
                    objectAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN, new byte[] { 0x01 }));
                    objectAttributes.Add(new ObjectAttribute(CKA.CKA_APPLICATION, Settings.ApplicationName));
                    objectAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, Settings.ApplicationName));
                    objectAttributes.Add(new ObjectAttribute(CKA.CKA_VALUE, "Data object content"));
                    // Create object
                    session.CreateObject(objectAttributes);
                    // Do something interesting with new object
                    // Destroy object
                    //session.DestroyObject(objectHandle);
                    session.Logout();
                }
            }
        }
    }
}

from pkcs11interop.

jariq avatar jariq commented on May 29, 2024

Thank you for the logs and the code. I was able to reproduce the error on Fedora 18 x86_64 and I am currently working on the fix for this issue. I will keep you updated.

from pkcs11interop.

jariq avatar jariq commented on May 29, 2024

I've been hacking on this problem a lot lately. Marshaling in 64-bit mono seems to be very different than in 32-bit mono. Anyway this will require a lot more time to fix than I expected and it is also possible that 64-bit mono will not be supported by pkcs11interop. Can you try to move your project to 32-bit OS?

from pkcs11interop.

vanhonit avatar vanhonit commented on May 29, 2024

Thank you very much !

from pkcs11interop.

inorton avatar inorton commented on May 29, 2024

AIUI, on amd64 linux CK_ULONG and CK_LONG are 64bits, on windows and 32bit linux it is always 32bits. That might be your problem. Also, I notice the delegates assume that CK_*_PTR types are uint rather than IntPtr

Eg:

internal delegate CKR C_GetSlotListDelegate(bool tokenPresent, uint[] slotList, ref uint count);

on 64bit unix this should possibly be:

internal delegate CKR C_GetSlotListDelegate(bool tokenPresent, IntPtr[] slotList, ref Uint64 count);

I'm testing on amd64 with an nShield ( I work at Thales ) and I get very odd results possibly due to this. Many of the tests pass when running under the mono soft debugger while fail otherwise. I'll have a tinker on my fork and see what I can report.

from pkcs11interop.

jariq avatar jariq commented on May 29, 2024

Yes you are right Ian. CK_ULONG C type has to be interpreted as ulong C# type on 64bit Linux while it has to be interpreted as uint C# type on 32bit Linux and both 32bit and 64bit Windows. I am already working on the new version of Pkcs11Interop library that should be usable across all the mentioned platforms.

from pkcs11interop.

inorton avatar inorton commented on May 29, 2024

I started a similar project a while ago, I couldn't think of an easy way of
having all the types switchable depending on the runtime platform. I was
later thinking of using some form of dynamic proxy but it seemed hard to do.

On 28 July 2013 21:41, Jaroslav Imrich [email protected] wrote:

Yes you are correct Ian. CK_ULONG C type has to be interpreted as ulong C#
type on 64bit Linux while it has to be interpreted as uint C# type on 32bit
Linux and both 32bit and 64bit Windows. I am already working on the new
version of Pkcs11Interop library that should be usable across all the
mentioned platforms.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-21690594
.

from pkcs11interop.

jariq avatar jariq commented on May 29, 2024

FYI: Pkcs11Interop 2.0 has just been released. It supports platforms with 32-bit C 'long' type (Win32, Win64 and Linux32) and also platforms with 64-bit C 'long' type (Linux64).

from pkcs11interop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.