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.Trim magic to make this work?
Just a small rant 😉