Hello,
I want to use SafeNet Luna SA HSM.
I have installed Luna client.
But I don’t know how to use it to link my account to retrieve my private key and certificate chain using .Net.
Does your libraries support it?
Thanks,
Josh
--
You received this message because you are subscribed to the Google Groups "Pkcs11Interop" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pkcs11intero...@googlegroups.com.
To post to this group, send email to pkcs11...@googlegroups.com.
Visit this group at http://groups.google.com/group/pkcs11interop.
Hi Jaroslav,
When I try pkcs11interop.PDF for my SafeNet HSM.
I got error on Pkcs11RsaSignature method.
The error is Value cannot be null.\r\nParameter name: value
at System.BitConverter.ToString(Byte[] value)
at Net.Pkcs11Interop.Common.ConvertUtils.BytesToHexString(Byte[] value)
at Net.Pkcs11Interop.PDF.Pkcs11RsaSignature.FindPrivateKey(String ckaLabel, Byte[] ckaId)
at Net.Pkcs11Interop.PDF.Pkcs11RsaSignature.InitializePkcs11Signature(String libraryPath, String tokenSerial, String tokenLabel, Byte[] pin, String ckaLabel, Byte[] ckaId, HashAlgorithm hashAlgorihtm)
at Net.Pkcs11Interop.PDF.Pkcs11RsaSignature..ctor(String libraryPath, String tokenSerial, String tokenLabel, String pin, String ckaLabel, String ckaId, HashAlgorithm hashAlgorihtm)
at Net.Pkcs11Interop.PDF.Tests.Pkcs11RsaSignatureExample.SignPdfDocument() in i:\josh-Document\Esign\PKCS11Interop.PDF\Pkcs11Interop.PDF-master\src\Pkcs11Interop.PDF.Tests\Pkcs11RsaSignatureExample.cs:line 88
at testPkcs11InteropPDFSign.Program.Main(String[] args) in i:\josh-Document\Esign\PKCS11Interop.PDF\Pkcs11Interop.PDF-master\src\Pkcs11InteropPDFSign\testPkcs11InteropPDFSign\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Hi Jaroslav,
I can get private key, but cannot get certificate
byte[] signingCertificate = pkcs11RsaSignature.GetSigningCertificate();
use List<ObjectHandle> foundObjects = session.FindAllObjects(privateKeyAttributes);
can see all my handles including certificates
What is wrong in GetSigningCertificate()
Thank you,
Josh
at System.BitConverter.ToString(Byte[] value)
at Net.Pkcs11Interop.Common.ConvertUtils.BytesToHexString(Byte[] value)
at Net.Pkcs11Interop.PDF.Pkcs11RsaSignature.GetSigningCertificate()
at Net.Pkcs11Interop.PDF.Tests.Pkcs11RsaSignatureExample.SignPdfDocument() in i:\josh-Document\Esign\PKCS11Interop.PDF\Pkcs11Interop.PDF-master\src\Pkcs11Interop.PDF.Tests\Pkcs11RsaSignatureExample.cs:line 91
I have sent exception in previous email. Another question is why pkcs11RsaSignature has non-public member?
Hi Jaroslav,
Which certificate label I can rename as same as private key label?
I have 3 certificates that GlobalSign generated, and imported to HSM.

Thank you,
Josh
From: Jaroslav Imrich [mailto:jarosla...@gmail.com]
Sent: Thursday, August 6, 2015 2:26 PM
To: pkcs11...@googlegroups.com
Cc: josh....@live.ca
Subject: Re: [pkcs11interop] pkcs11interop for Luna SA HSM
Hello Josh,
Hi Jaroslav,
When I create CSR file, I used same label name for private handle.
Cmu requestcertificate , it ask me select privatehandle, the privatehandle is same as private key label (privatekey_securesign)
Thank you,
Josh
From: Jaroslav Imrich [mailto:jarosla...@gmail.com]
Sent: Thursday, August 6, 2015 2:26 PM
To: pkcs11...@googlegroups.com
Cc: josh....@live.ca
Subject: Re: [pkcs11interop] pkcs11interop for Luna SA HSM
Hello Josh,
Hi Jaroslav,
They are same label name for privatekey_securesign and GlobalSignAdobeCATest

From: Jaroslav Imrich [mailto:jarosla...@gmail.com]
Sent: Thursday, August 6, 2015 2:26 PM
To: pkcs11...@googlegroups.com
Cc: josh....@live.ca
Subject: Re: [pkcs11interop] pkcs11interop for Luna SA HSM
Hello Josh,
Sent: Thursday, August 6, 2015 2:44 PM
To: 'Jaroslav Imrich' <jarosla...@gmail.com>; pkcs11...@googlegroups.com
Hi Jaroslav,
I have changed certificate GlobalSignAdobeCATest to privatekey_securesign as same label. The problem has been solved.
I got another error on ICollection<Org.BouncyCastle.X509.X509Certificate> certPath = CertUtils.BuildCertPath(signingCertificate, otherCertificates);
“Provided certificates do not contain self-signed root certificate"
at Net.Pkcs11Interop.PDF.CertUtils.BuildCertPath(Byte[] signingCertificate, List`1 otherCertificates)
at Net.Pkcs11Interop.PDF.Tests.Pkcs11RsaSignatureExample.SignPdfDocument() in i:\josh-Document\Esign\PKCS11Interop.PDF\Pkcs11Interop.PDF-master\src\Pkcs11Interop.PDF.Tests\Pkcs11RsaSignatureExample.cs:line 97
at testPkcs11InteropPDFSign.Program.Main(String[] args) in i:\josh-Document\Esign\PKCS11Interop.PDF\Pkcs11Interop.PDF-master\src\Pkcs11InteropPDFSign\testPkcs11InteropPDFSign\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
From: Jaroslav Imrich [mailto:jarosla...@gmail.com]
Sent: Thursday, August 6, 2015 2:56 PM
To: pkcs11...@googlegroups.com
I have changed certificate GlobalSignAdobeCATest to privatekey_securesign as same label. The problem has been solved.
I got another error on ICollection<Org.BouncyCastle.X509.X509Certificate> certPath = CertUtils.BuildCertPath(signingCertificate, otherCertificates);
“Provided certificates do not contain self-signed root certificate"
Hi Jaroslav,
I have imported all certificates (3) in HSM, and pkcs11RsaSignature.GetAllCertificates() is done.
I checked your code
foreach (byte[] otherCertificate in otherCertificates)
{
BCX509.X509Certificate otherCert = ToBouncyCastleObject(otherCertificate);
otherCerts.Add(ToBouncyCastleObject(otherCertificate));
if (IsSelfSigned(otherCert))
trustAnchors.Add(new TrustAnchor(otherCert, null));
}
Why I need read CA again? The certificates should include CA. I imported all of them in HSM

Thanks,
Josh
From: Jaroslav Imrich [mailto:jarosla...@gmail.com]
Sent: Thursday, August 6, 2015 3:24 PM
To: pkcs11...@googlegroups.com
Cc: josh live <josh....@live.ca>
Subject: Re: [pkcs11interop] pkcs11interop for Luna SA HSM
Hey Josh,
I already get 3 certificates.

From: Jaroslav Imrich [mailto:jarosla...@gmail.com]
Sent: Thursday, August 6, 2015 3:24 PM
To: pkcs11...@googlegroups.com
Cc: josh live <josh....@live.ca>
Subject: Re: [pkcs11interop] pkcs11interop for Luna SA HSM
Hey Josh,
Dear Jaroslav
I am also struggling the same issue mentioned in the above cases as
1.I had check whether slots is present in HSM or not as like
if (string.IsNullOrEmpty(libraryPath))
throw new ArgumentNullException("libraryPath");
_pkcs11 = new Pkcs11(libraryPath, true);
_slot = GetUsableSlot(_pkcs11); //FindSlot(tokenSerial, tokenLabel);
I have create one methods to pass pkcss clas directly as
//NILESH
private Slot GetUsableSlot(Pkcs11 pkcs11)
{
// Get list of available slots
List<Slot> slots = pkcs11.GetSlotList(true);
// Let's use first slot with token present
return slots[0];
}
but i want to know
FindSlot(tokenSerial, tokenLabel) is not executed whether i had passed tokenlabel which is same as HSM slots.Please guide
2.Issue is Provided certificates do not contain self-signed root certificate I have do same as you mentioned solution but failed to execute
1. Import all required certificates to HSM and then use only GetAllCertificates() method of Pkcs11RsaSignature class to read them
2. Read CA certificates from somewhere else just like Pkcs11Interop.PDF.Demo.exe application does
error raise @
ICollection<Org.BouncyCastle.X509.X509Certificate> certPath = CertUtils.BuildCertPath(signingCertificate, otherCertificates);
Please guide me I am so struggling on same issue
There is two key point,
1) get root certificate from your certificate provider, e. g. Adobe root certificate
2) the label of public and private has to been same in your HSM
Josh Zhang