Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / January 2006

Tip: Looking for answers? Try searching our database.

X509Util.FindCertificateByKeyIdentifier() takes in excess of 5mins to complete???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ste - 03 Jan 2006 20:50 GMT
X509Util.FindCertificateByKeyIdentifier() takes an extraordinary amount of time to complete.  On my system it is taking in excess of 5 minutes to complete.
I only have 85 certificates in the store.

Is this expected behaviour?

   string keyIdentifier = Convert.FromBase64String("7CwyLoUNwbbjJwx5oX75Af1cQEs=");
   X509Certificate2Collection certs2 = X509Util.FindCertificateByKeyIdentifier(keyIdentifier, StoreLocation.LocalMachine, StoreName.Root.ToString());

The FindCertificateBySubjectName() call completes instantaneously!

If i open the store via X509Store and invoke the find method on certificate collection, it returns immediately!

What is the recommended method for finding certificates in a store, X509Util or X509Certificate2Collection ?

X509 store code pasted below ..........

         // convert the base64 string to the hexadecimal equivalent
         byte[] b = Convert.FromBase64String("7CwyLoUNwbbjJwx5oX75Af1cQEs=");
         char[] h = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
         char[] c = new char[b.Length * 2];
         for (int i = 0; i < b.Length; i++)
         {
           c[i*2+0] = h[b[i] >> 4];
           c[i*2+1] = h[b[i] & 0xF];
         }
         string keyId = new string(c);

         // now open the store
         X509Store store = null;
         try
         {
             store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
             store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

             X509Certificate2Collection found = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, keyId, true);

             if (found.Count != 1)
             {
                throw new ApplicationException("The certificate specified cannot be identified by the keyId " + keyId);

             }
             return found[0];

         }
         finally
         {
             store.Close();
         }



         
Pablo Cibraro - 09 Jan 2006 20:39 GMT
Hi Ste,
Yes, I also reported that problem.
This X509 API doesn't allow to do a indexed search by KeyIdentifier so WSE has to do a sequential search, which can take a lot of time to complete if you have many certificates in your store.
In your case, WSE is doing a sequential search against 85 certificates.
Anyway, WSE keeps the certificate in a caches after finding it and therefore it only takes a lot of time the first time.

Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax
http://www.lagash.com

 X509Util.FindCertificateByKeyIdentifier() takes an extraordinary amount of time to complete.  On my system it is taking in excess of 5 minutes to complete.
 I only have 85 certificates in the store.

 Is this expected behaviour?

     string keyIdentifier = Convert.FromBase64String("7CwyLoUNwbbjJwx5oX75Af1cQEs=");
     X509Certificate2Collection certs2 = X509Util.FindCertificateByKeyIdentifier(keyIdentifier, StoreLocation.LocalMachine, StoreName.Root.ToString());

 The FindCertificateBySubjectName() call completes instantaneously!

 If i open the store via X509Store and invoke the find method on certificate collection, it returns immediately!

 What is the recommended method for finding certificates in a store, X509Util or X509Certificate2Collection ?

 X509 store code pasted below ..........

           // convert the base64 string to the hexadecimal equivalent
           byte[] b = Convert.FromBase64String("7CwyLoUNwbbjJwx5oX75Af1cQEs=");
           char[] h = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
           char[] c = new char[b.Length * 2];
           for (int i = 0; i < b.Length; i++)
           {
             c[i*2+0] = h[b[i] >> 4];
             c[i*2+1] = h[b[i] & 0xF];
           }
           string keyId = new string(c);

           // now open the store
           X509Store store = null;
           try
           {
               store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
               store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

               X509Certificate2Collection found = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, keyId, true);

               if (found.Count != 1)
               {
                  throw new ApplicationException("The certificate specified cannot be identified by the keyId " + keyId);

               }
               return found[0];

           }
           finally
           {
               store.Close();
           }

           
Ste - 09 Jan 2006 21:00 GMT
Phew...  Glad it was not just me.

In my workaround i posted the Base64 to hex code i use.. Does .NET2 or WSE have a method to do this.  I can convert a string to/from base64 easily but i have yet to find a base64 to hex.

 Hi Ste,
 Yes, I also reported that problem.
 This X509 API doesn't allow to do a indexed search by KeyIdentifier so WSE has to do a sequential search, which can take a lot of time to complete if you have many certificates in your store.
 In your case, WSE is doing a sequential search against 85 certificates.
 Anyway, WSE keeps the certificate in a caches after finding it and therefore it only takes a lot of time the first time.

 Regards,
 Pablo Cibraro
 http://weblogs.asp.net/cibrax
 http://www.lagash.com

 "Ste" <noemail@nospam.com> wrote in message news:wJ-dnbFQWeMtfifeRVny1w@pipex.net...
   X509Util.FindCertificateByKeyIdentifier() takes an extraordinary amount of time to complete.  On my system it is taking in excess of 5 minutes to complete.
   I only have 85 certificates in the store.

   Is this expected behaviour?

       string keyIdentifier = Convert.FromBase64String("7CwyLoUNwbbjJwx5oX75Af1cQEs=");
       X509Certificate2Collection certs2 = X509Util.FindCertificateByKeyIdentifier(keyIdentifier, StoreLocation.LocalMachine, StoreName.Root.ToString());

   The FindCertificateBySubjectName() call completes instantaneously!

   If i open the store via X509Store and invoke the find method on certificate collection, it returns immediately!

   What is the recommended method for finding certificates in a store, X509Util or X509Certificate2Collection ?

   X509 store code pasted below ..........

             // convert the base64 string to the hexadecimal equivalent
             byte[] b = Convert.FromBase64String("7CwyLoUNwbbjJwx5oX75Af1cQEs=");
             char[] h = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
             char[] c = new char[b.Length * 2];
             for (int i = 0; i < b.Length; i++)
             {
               c[i*2+0] = h[b[i] >> 4];
               c[i*2+1] = h[b[i] & 0xF];
             }
             string keyId = new string(c);

             // now open the store
             X509Store store = null;
             try
             {
                 store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
                 store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

                 X509Certificate2Collection found = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, keyId, true);

                 if (found.Count != 1)
                 {
                    throw new ApplicationException("The certificate specified cannot be identified by the keyId " + keyId);

                 }
                 return found[0];

             }
             finally
             {
                 store.Close();
             }

             

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.