Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read azure ServiceConfiguration file's certificate section using c#

Tags:

c#

.net

azure

Can we read certificate section withi ServiceConfiguration.cscfg file using c#? There is method inside RoleEnvironment class to read ConfigurationSettings, but not certificate section.

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="WindowsAzureProject7" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*">
  <Role name="MvcWebRole1" >
    <Instances count="1" />
       <Certificates>
      <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="625FBBB3B7A25C4B9D1C49D1CB1E3AE196C1A083" thumbprintAlgorithm="sha1" />
    </Certificates>
  </Role>
</ServiceConfiguration>
like image 985
bhavesh lad Avatar asked Jul 02 '12 05:07

bhavesh lad


1 Answers

Yes, there is no API to read certificate details as far as i know, however what you can do is create a configuration setting and add your certificate specific details and read it directly from the same API. Here is the trick, I used in past:

<ServiceConfiguration serviceName="RW" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
 <Role name="RR">
  <Instances count="1" />
   <ConfigurationSettings>
    <Setting name="AppFolder" value="RailsApp" />
    <Setting name="CertificateThumb" value="*************" />
   </ConfigurationSettings>
   <Certificates>
    <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="*****************************" thumbprintAlgorithm="sha1" />
   </Certificates>
 </Role>
</ServiceConfiguration>

Now, in my role specific code, I can call RoleEnvironment.GetConfigurationSettingValue to get the certificate thumb as below:

string certThumb = RoleEnvironment.GetConfigurationSettingValue("CertificateThumb");
like image 96
AvkashChauhan Avatar answered Oct 11 '22 15:10

AvkashChauhan