Search code examples
.netazurecertificatex509certificate2

How do I access Azure certificate from code?


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.


Solution

  • 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.