EricHerlitz / Mobile-BankId-.NET-Example

Working Swedish Mobile BankID implementation written in C# .NET
12 stars 7 forks source link

Desktop application can only find the testcert in the Personal store. #3

Closed AndersBillLinden closed 7 years ago

AndersBillLinden commented 7 years ago

I am creating a winforms application that authenticates and then collects, exactly as your console application.

If I fetch the client cert from the CurrentUser store location, it works, but not if I am using LocalMachine.

Is it impossible to use LocalMachine for this?

Working web.config snippet <clientCertificate findValue="FP Testcert 2" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" />

Does not work <clientCertificate findValue="FP Testcert 2" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" />

Screenshot: image

AndersBillLinden commented 7 years ago

I am able to find the cert using https://stackoverflow.com/questions/11115511/how-to-find-certificate-by-its-thumbprint-in-c-sharp with the parameters

string certThumbPrint = "FP Testcert 2";
X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);

well, too lazy to rename the variable, worth noting also that I changed to X509FindType.FindBySubjectName

EricHerlitz commented 7 years ago

You should be able to fetch any certificate from the LocalMachine store regardless of its type. but it requires correct access rights. But it seems as if you resolved it?

AndersBillLinden commented 7 years ago

No, I need to fetch the client cert from the LocalMachine store location.