質問

I have a certificate uploaded to azure and it's in the configuration like...

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2014-01.2.3">
  <Role name="MyRole">
    <Instances count="1" />
    <ConfigurationSettings>
          ...
    </ConfigurationSettings>
    <Certificates>
      <Certificate name="MyCert" thumbprint="CB3611F7D2406AB12094AE9489C50FE1A8B6BFF6" thumbprintAlgorithm="sha1" />
    </Certificates>
  </Role>
</ServiceConfiguration>

Is there anything like...

X509Certificate2 myCert = Config.Certs["MyCert"];

or even similar to get the thumbprint to pull it out of the store directly? I don't see anywhere in the runtime SDK where I can get the cert or even the thumbprint.

役に立ちましたか?

解決

There is no way to enumerate the certs. The standard way to implement this is to add the cert thumbprint as a configuration setting in the csdef/cscfg and then look up the thumbprint at runtime via that configuration setting.

他のヒント

private static X509Certificate2 GetCertificate()
    {
        var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
        store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
        X509Certificate2Collection matchedCertificates =
                store.Certificates.Find(X509FindType.FindByThumbprint, "XXXXX", false);

        X509Certificate2 cert;
        if (matchedCertificates.Count > 0)
        {
           cert = matchedCertificates[0];
        }
        store.Close();            
        return cert;
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top