<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sakthis Kumar</title>
    <description>The latest articles on DEV Community by Sakthis Kumar (@sakthis).</description>
    <link>https://dev.to/sakthis</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F154303%2F63553930-3e99-4d4d-bd62-288600a325cb.jpg</url>
      <title>DEV Community: Sakthis Kumar</title>
      <link>https://dev.to/sakthis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sakthis"/>
    <language>en</language>
    <item>
      <title>Azure SSL Certificate! WebApp!! WAF!!!</title>
      <dc:creator>Sakthis Kumar</dc:creator>
      <pubDate>Tue, 26 May 2020 09:06:57 +0000</pubDate>
      <link>https://dev.to/sakthis/azure-ssl-certificate-webapp-waf-1kgb</link>
      <guid>https://dev.to/sakthis/azure-ssl-certificate-webapp-waf-1kgb</guid>
      <description>&lt;p&gt;Recently happen to come across a scenario where the SSL certificate (in Azure) was auto-renewed and Azure Web Application Firewall (WAF) SSL offloading went kaput! &lt;/p&gt;

&lt;p&gt;The setup!&lt;br&gt;
Internet --&amp;gt; Azure WAF --&amp;gt; Azure WebApp&lt;/p&gt;

&lt;p&gt;Auto-renewed Cert is in KeyVault (KV). Though the KV gives you an option to export the certificate you will end up getting the "Password for the certificate is wrong" error/notification &lt;/p&gt;

&lt;p&gt;Following is what I managed to do get the certificate successfully imported into WAF listener &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Login to Azure and set the subscription&lt;/b&gt; &lt;br&gt;
Login-AzureRmAccount&lt;br&gt;
Set-AzureRmContext -SubscriptionId xxxxx-xxxxx &lt;/p&gt;

&lt;p&gt;&lt;b&gt;Download Certificate stored as PFX as Secret&lt;/b&gt; &lt;br&gt;
$vaultName  = "&lt;i&gt;yourvaultname&lt;/i&gt;"&lt;br&gt;
$keyVaultSecretName = "&lt;i&gt;secretname&lt;/i&gt;"&lt;br&gt;
$secret = Get-AzureKeyVaultSecret -VaultName $VaultName -Name $keyVaultSecretName&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Create PFX Object from the Secret we received&lt;/b&gt;&lt;br&gt;
$pfxCertObject = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @([Convert]::FromBase64String($secret.SecretValueText),"", [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Create a Password to associate with the PFX &lt;/b&gt;&lt;br&gt;
$pfxPassword = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 50 | % {[char]$_})&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Notedown the pfx password by checking&lt;/b&gt;  &lt;i&gt;(you will need this to import the certificate in the WAF")&lt;/i&gt;&lt;br&gt;
$pfxPassword&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DGYwk6S2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2eo788yh1cf0r3k9znrn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DGYwk6S2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2eo788yh1cf0r3k9znrn.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Write the PFX Object to file System and add a password to it &lt;/b&gt;&lt;br&gt;
$currentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath&lt;/p&gt;

&lt;p&gt;[Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath&lt;/p&gt;

&lt;p&gt;[io.file]::WriteAllBytes("C:\tmp\appservicecertificate.pfx",$pfxCertObject.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $pfxPassword))&lt;/p&gt;

&lt;p&gt;You should be able export the certificate from your local drive&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E4MajEhS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cn6e2qxrshtzwd1ggk7n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E4MajEhS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cn6e2qxrshtzwd1ggk7n.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt; Time to Import the SSL Certificate in WAF!&lt;/b&gt;&lt;br&gt;
(Az Portal) Home -&amp;gt; Applciation Gateway -&amp;gt; Listeners -&amp;gt; &lt;i&gt; Your Listener Name &lt;/i&gt; -&amp;gt; Certificate -&amp;gt; Select "Renew or edit selected certificate" and follow the onscreen instructions to import the renewed certificate.. &lt;/p&gt;

</description>
      <category>azure</category>
      <category>security</category>
      <category>sslcertificate</category>
      <category>azurewebapplicationfirewall</category>
    </item>
  </channel>
</rss>
