8

I'm trying to create our own WIF Identity Provider and run it on Azure but I'm struggling when trying to automatically generate the Federation Metadata.

This line does not appear to work on Azure:

CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, signingCertificateName);

The certificate is uploaded to Azure, how can I get hold of it?

Thanks

1
  • Looks like as illustrated below the code is the same for in-house and on cloud. I was checking the name of the cert and on Azure it contained extra information which is why I couldn't find it.
    – Max
    Apr 15, 2011 at 8:44

2 Answers 2

9

As a slight variation on other answers, if you just want to get one certificate rather than iterate through all of them you could do something like this:

var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

X509Certificate2Collection matchedCertificates =
     store.Certificates.Find(X509FindType.FindBySubjectName, signingCertificateName, true);

if (matchedCertificates.Count > 0)
{
    myCertificate = matchedCertificates[0]; 
}

(which also is not Azure specific)

3
  • Excellent, even though I marked the other repsonse as answer because it highlighted my problem I have refactored my code to look like this. Thanks! +1
    – Max
    Apr 15, 2011 at 8:46
  • What is the current answer , StoreLocation.LocalMachine or StoreLocation.CurrentUser ? I understood that for web apps there is no access to localuser certificates so it must be local machine , am I wrong ? Jun 11, 2012 at 15:55
  • 1
    I've only ever used LocalMachine on Azure as I find the concept of a user a bit or a weird concept in that situation. Jun 11, 2012 at 21:15
7

Try this blog post: http://blogs.msdn.com/b/jnak/archive/2010/01/29/installing-certificates-in-windows-azure-vms.aspx

It suggests code like:

X509Certificate2Collection selectedCerts = new X509Certificate2Collection();

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
foreach (X509Certificate2 cert in store.Certificates)
{
    // do stuff with cert
}
1
  • This snippet allowed me to see that the name of the cert on Azure was different to what I was expecting and sorted my problem :)
    – Max
    Apr 15, 2011 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.