Hi Everyone,
One of our clients requires the ability to connect to a website which uses a smartcard with a pincode for authentication. When I connect the smartcard to my computer, the certificate on the card will be stored inside the Windows certificate store, from where I fetch the certificate in c#. When the certificate is later used for authentication, Windows will automatically ask for the pincode.
When using Google ChromeWhen using Google Chrome, the browser will display a popup from which I can choose a certificate (see figure 1).
After choosing the certificate Windows will display a window where I will be asked for the pincode of my smartcard (see figure 2).
After filling in my pincode and pressing ok I will be authenticated.
Figure1:
In case the image is not displaying:
figure1Figure2:
In case the image is not displaying:
figure2When using EO webbrowserWhen using EO webbrowser no popup is showed where I can choose the certificate from. A NeedClientCertificate is fired instead, which I try to handle as following:
(Some of it is pretty much hard coded, but I'm planning to fix this later.
I x'ed out the real value for the serialNumber variable on purpose aswel.)
- Fetch the certificate from the Windows certificate store
- Choose the right certificate from the certificate collection
- Pass the certificate to the Continue method
Code: C#
//fetch certificates from the Windows certificate store
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection coll = store.Certificates;
//Look for the right certificate
X509Certificate2 cert = null;
foreach (X509Certificate2 c in coll) {
String serialNumber = "XXXX";
if (c.SerialNumber.Equals(serialNumber))
{
cert = c;
break;
}
String name = c.Subject;
String name2 = c.FriendlyName;
Console.WriteLine(name + " " + name2);
}
//pass the certificate as parameter to the Continue method
e.Continue(cert);
After doing this Windows will ask for my pincode again the same way as when using a normal Google Chrome browser (figure 2).
The problem is that this will fire a LoadFailed event. No CertificateError event is fired however.
The LoadFailedEventArgs always contains the following details:
Url: null
ErrorMessage:Error code:-117
ErrorCode:-117
HttpStatusCode: 0
I know I did not provide you with a lot of details on the certificate itself so far. This is because the certificate is highly personal. In case there are any more questions regarding the certificate, please feel free to ask and I will provide the information if possible.
Thanks for your help!
Kind regards,
Joeri