Hi,
I'm working on a backoffice software using an HSM Luna (AWS cloudhsm service). We use currently Pkcs11Interop library for test purpose. At the beginning we use the library in a web service to decrypt TDES data sending to us by embedded devices. No problems with that. But recently we have decided to use the HSM to perform CMAC verification and calculation. So I've written a little console application to test CMAC calculation and verification. I got no problems, the application was able to connect to the HSM and do all the operations. The problems started after I have integrated the new methods into the web service. It seems just impossible to open a session with the HSM.It fails with the CKR_TOKEN_NOT_PRESENT.
Here the method I use for opening the session :
public void OpenSession(IPkcs11 pkcs11, string hsmPIN, string hsmSLOT)
{
Log.Debug("Open session with the HSM Slot " + hsmSLOT + " Pin " + hsmPIN);
Console.WriteLine("Open session with the HSM");
lock (syncRoot)
{
//// get all the slot available
ICollection<ISlot> slots = pkcs11.GetSlotList(false);
if (slots != null && slots.Count > 0)
{
ISlot slot;
if (slots.Count == 1)
{
slot = slots.ElementAt(0);
}
else
{
slot = slots.ElementAt(Convert.ToInt16(hsmSLOT));
}
//// open a session with the $HSM$
session = slot.OpenSession(true);
if (session != null)
{
session.Login(CKU.CKU_USER, hsmPIN);
}
else
{
throw new Pkcs11Exception("Unable to open session with HSM", CKR.CKR_DEVICE_ERROR);
}
}
else
{
throw new Pkcs11Exception("No Slot available on HSM", CKR.CKR_DEVICE_ERROR);
}
}
}
Other precisions :
- Both console application and web service uses the same library for opening the session.
- when i out "true" in parameter of GetSlotList. I see the exception "Unable to open session with HSM"
- when I try to dump all the slots I see 4 slots in the console application but only 3 in the web service.
the ouput coming from console Application :
Open session with the HSM Slot 0 Pin ********************
slot id 1
slot description LunaNet Slot
slot id 2
slot description Luna UHD Slot
slot id 3
slot description Luna UHD Slot
slot id 4
slot description Luna UHD Slot
the ouput coming from web service:
2016-03-17 15:45:42,624 DEBUG Vix.eO.Sure.Lib.Utility.Cryptography.HSM.Pkcs11InteropHSMAPI - Open session with the HSM Slot 0 Pin ********************
2016-03-17 15:45:42,639 DEBUG Vix.eO.Sure.Lib.Utility.Cryptography.HSM.Pkcs11InteropHSMAPI - slot id 1
2016-03-17 15:45:42,639 DEBUG Vix.eO.Sure.Lib.Utility.Cryptography.HSM.Pkcs11InteropHSMAPI - slot description Luna UHD Slot
2016-03-17 15:45:42,639 DEBUG Vix.eO.Sure.Lib.Utility.Cryptography.HSM.Pkcs11InteropHSMAPI - slot id 2
2016-03-17 15:45:42,639 DEBUG Vix.eO.Sure.Lib.Utility.Cryptography.HSM.Pkcs11InteropHSMAPI - slot description Luna UHD Slot
2016-03-17 15:45:42,639 DEBUG Vix.eO.Sure.Lib.Utility.Cryptography.HSM.Pkcs11InteropHSMAPI - slot id 3
2016-03-17 15:45:42,639 DEBUG Vix.eO.Sure.Lib.Utility.Cryptography.HSM.Pkcs11InteropHSMAPI - slot description Luna UHD Slot
It seems that the web service just doesn't see the slot with the token. And It was working before my developpement when we do only TDES decryption so I suppose I have done something wrong ;). Does anyone have an idea?
Thanks for help,