X509Certificate2Collection is picky…

Just a quickpost. I noticed the other day, experimenting with WIF, that the X509 Certificate Store is extremely picky on the Distinguished name when trying to locate a certificate in the certificate store. My certificate’s Distinguished name shows in the Certificate store as the following:

CN = mycomputer-wif-sign
OU = Flaktveit
O = MyCompany
S = Bergen
C = NO

The parts of the DN are separated by line breaks, and the equal signs are surrounded by white space. So you wouldn’t think it mattered an awful lot how you would provide this as a key to X509Certificate2Collection.Find

? store.Certificates.Find(findType, "CN= mycomputer-wif-sign, OU= Flaktveit, O= MyCompany, S= Bergen, C= NO", false).Count
0
? store.Certificates.Find(findType, "CN=mycomputer-wif-sign,OU=Flaktveit, O=MyCompany, S=Bergen, C=NO", false).Count
0
? store.Certificates.Find(findType, "CN=mycomputer-wif-sign, OU=Flaktveit, O=MyCompany, S=Bergen, C=NO", false).Count
1

Notice that the only one of the three that actually returns the certificate, is the one that has no whitespace surrounding the equal signs, and exactly one blank after the commas.

Please, dear X509Certificate2Collection, give me some slack? How about using some String.Split and String.Trim magic to make this work?

Just a small rant 😉

This entry was posted in .NET, C#, WIF. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s