You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Method C_Login returned CKR_SESSION_HANDLE_INVALID
at Net.Pkcs11Interop.HighLevelAPI80.Session.Login(CKU userType, String pin) at PKCS11Service.Initialize() in PKCS11Service.cs:line 81 at PKCS11Service..ctor(IOptions"1 settings, ILogger"1 logger) in PKCS11\PKCS11Service.cs:line 55 at System.RuntimeMethodHandle.InvokeMethod(Object target, Span"1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor"2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor"2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor"2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor"2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) at System.Collections.Concurrent.ConcurrentDictionary"2.GetOrAdd(TKey key, Func"2 valueFactory) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at ConfigureServices.AppServices.<>c__DisplayClass0_0.<AddApplicationServices>b__40() in AppServices.cs:line 40 at System.Lazy"1.ViaFactory(LazyThreadSafetyMode mode) --- End of stack trace from previous location --- at System.Lazy"1.CreateValue()
Here it is my initialize function:
private void Initialize()
{
if (slot == null)
{
try
{
var slotList = pkcs11Library.GetSlotList(SlotsType.WithTokenPresent);
if (!slotList.Any())
throw new Exception("Could not find any slot");
slot = slotList[0];
slot.CloseAllSessions();
var session = slot.OpenSession(SessionType.ReadOnly);
if (session == null)
{
throw new Exception("Could not create new session on the given slot");
}
session.Login(CKU.CKU_USER, settings.Value.Password);
session.FindObjectsInit(privateKeyAttributeList);
var privateKeyObjectsFound = session.FindObjects(1);
session.FindObjectsFinal();
if (!privateKeyObjectsFound.Any() && privateKeyObjectsFound[0].ObjectId == CK.CK_INVALID_HANDLE)
{
throw new Exception("no private key with the lable was found");
}
keyHandle = privateKeyObjectsFound[0];
session.FindObjectsInit(certificateAttributeList);
var certificateObjectsFound = session.FindObjects(1);
session.FindObjectsFinal();
if (!certificateObjectsFound.Any() && certificateObjectsFound[0].ObjectId == CK.CK_INVALID_HANDLE)
{
throw new Exception("no certificate with the lable was found");
}
var foundAttributeValues = session.GetAttributeValue(certificateObjectsFound[0], new List<CKA>() { CKA.CKA_VALUE });
certificate = new X509Certificate2(foundAttributeValues[0].GetValueAsByteArray());
}
catch (Exception exception)
{
slot = null;
throw;
}
}
}
Could you please assist me in identifying the issue and suggest a solution? Thank you.
The text was updated successfully, but these errors were encountered:
Hello,
I am experiencing an issue as follows:
Method C_Login returned CKR_SESSION_HANDLE_INVALID
at Net.Pkcs11Interop.HighLevelAPI80.Session.Login(CKU userType, String pin) at PKCS11Service.Initialize() in PKCS11Service.cs:line 81 at PKCS11Service..ctor(IOptions"1 settings, ILogger"1 logger) in PKCS11\PKCS11Service.cs:line 55 at System.RuntimeMethodHandle.InvokeMethod(Object target, Span"1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor"2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor"2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor"2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor"2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType) at System.Collections.Concurrent.ConcurrentDictionary"2.GetOrAdd(TKey key, Func"2 valueFactory) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at ConfigureServices.AppServices.<>c__DisplayClass0_0.<AddApplicationServices>b__40() in AppServices.cs:line 40 at System.Lazy"1.ViaFactory(LazyThreadSafetyMode mode) --- End of stack trace from previous location --- at System.Lazy"1.CreateValue()
Here it is my initialize function:
private void Initialize()
{
if (slot == null)
{
try
{
var slotList = pkcs11Library.GetSlotList(SlotsType.WithTokenPresent);
if (!slotList.Any())
throw new Exception("Could not find any slot");
Could you please assist me in identifying the issue and suggest a solution? Thank you.
The text was updated successfully, but these errors were encountered: