<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Adrian Padilla (a.k.a Grumpy Dev)</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/adrianpadilla/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/adrianpadilla/feed.xml</link>
    <description>For the code is dark and full of terrors</description>
    <lastBuildDate>Tue, 16 Apr 2019 04:27:51 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>git status in linux reporting changes in all files</title>
      <link>https://docs.microsoft.com/archive/blogs/adrianpadilla/git-status-in-linux-reporting-changes-in-all-files</link>
      <pubDate>Tue, 12 Jun 2018 13:30:32 GMT</pubDate>
      <dc:creator><![CDATA[Adrian Padilla Vega]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/adrianpadilla/?p=235</guid>
      <description><![CDATA[It has happened to me a couple times when using git on bash either natively in one of my laptops or...]]></description>
      <content:encoded><![CDATA[It has happened to me a couple times when using git on bash either natively in one of my laptops or through the Windows Linux subsystem. Note that I use Ubuntu LTS (16 and/or 18).

This becomes more obvious when doing a git status for the same repository using Windows CLI/Powershell and using Bash, especially for projects created in a Windows environment. The symptoms are essentially getting no changes on staging on the Windows environment, but reporting changes on all files on staging on Linux.

This is just because of the differences on how both Operating systems handle line breaks.

Without complex canonicalization of your files, you can simply adjust how git handles line breaks:
<pre>git config --global core.autocrlf true</pre>
Cheers]]></content:encoded>
    </item>
    <item>
      <title>Keys lost and found: How to recover certificate lost private keys</title>
      <link>https://docs.microsoft.com/archive/blogs/adrianpadilla/keys-lost-and-found-how-to-recover-certificate-lost-private-keys</link>
      <pubDate>Wed, 03 Aug 2016 11:19:09 GMT</pubDate>
      <dc:creator><![CDATA[Adrian Padilla Vega]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/adrianpadilla/?p=215</guid>
      <description><![CDATA[For whatever reason, certificate private keys keep getting lost. This is annoying specially to...]]></description>
      <content:encoded><![CDATA[For whatever reason, certificate private keys keep getting lost. This is annoying specially to grumpy devs.

The symptoms are clear: when you open certml.msc (machine) or certmgr.msc (user):

<a href="https://msdnshared.blob.core.windows.net/media/2016/08/privatekeys.png"><img src="https://msdnshared.blob.core.windows.net/media/2016/08/privatekeys.png" alt="privatekeys" width="408" height="94" class="alignnone size-full wp-image-225" /></a>

Fortunately the answer is in certutil.exe. Here are the steps:
<ul>
 	<li>Localize the certificate in Powershell in admin mode. Do "cd cert:" and then recursively traverse your certificates using let's say, your thumbprint:
<code>$found = ls -r | where { $_.Thumbprint -like 'TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT'}</code></li>
 	<li>Get the serial number of the certificate:
<code>$found[0].SerialNumber</code></li>
 	<li>Grab the serial number and feed it to certutil with the following args:
<code>certutil –repairstore my SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS</code></li>
</ul>
On success you should see some of your certificate info finishing with: "CertUtil: -repairstore command completed successfully."

Then, to keep your certificate and key safe, use the Certificates module in the Microsoft Management Console or <a href="https://technet.microsoft.com/en-us/library/hh848635.aspx">Export-PfxCertificate Powershell cmdlet </a>to export the certificate with its private key into a .pfx file.

Done! refer to the <a href="https://technet.microsoft.com/en-us/library/cc732443(v=ws.11).aspx">certutil documentation</a> for more info.

Happy coding!]]></content:encoded>
    </item>
    <item>
      <title>Certificate authentication into Azure Key Vault</title>
      <link>https://docs.microsoft.com/archive/blogs/adrianpadilla/certificate-authentication-into-azure-key-vault</link>
      <pubDate>Thu, 31 Mar 2016 11:54:33 GMT</pubDate>
      <dc:creator><![CDATA[Adrian Padilla Vega]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/adrianpadilla/?p=163</guid>
      <description><![CDATA[If you haven't, you should better Get started with Azure Key Vault  first.
Azure Key Vault is...]]></description>
      <content:encoded><![CDATA[<blockquote>If you haven't, you should better <a target="_blank" href="https://azure.microsoft.com/en-us/documentation/articles/key-vault-get-started/" title="Get started with Azure Key Vault">Get started with Azure Key Vault </a> first.</blockquote>
Azure Key Vault is amazing for keeping secrets and cryptographic keys. But I don’t understand why authentication via application secret (a string) is offered as an option. Having Azure Key Vault accessed via a secret string in your application settings is as good as having all your secrets in the config as well. Once the secret is compromised, the whole thing is vulnerable.

Having a certificate as a means for authentication? Especially if you don’t check it in the same place as your secret-accessing code? And if checked in, being as a pfx whose password is shared privately off-line? Sounds a little bit better doesn’t it?

I like particularly the idea of being the machine (through its certificate store) the one that has access, instead of a user with a string. At the end of the day X509 certificates are a little bit more complex that a 32 char string, right? A certificate in a machine store is not going to be accidentally be forwarded in an email to the wrong individual. Nor being left in a post it.

Enough with the sales work, I’m here for the code, not for being door to door with a vacuum cleaner.
<h2 id="creating-the-vault">Creating the vault</h2>
As for any other exercise, some warm-up. Before working on any Azure Powershell task remember to:
<ol>
 	<li>Log into Azure Resource manager with the Login-AzureRmAccount commandlet.</li>
 	<li>Make sure your Azure Rm is pointing to the right place using <code>Select-AzureRmSubscription -SubscriptionName {your subscription}</code></li>
</ol>
Done with the stretches, let’s create the vault.
<pre class="prettyprint"><code class=" hljs lasso"><span class="hljs-literal">New</span><span class="hljs-attribute">-AzureRmKeyVault</span> <span class="hljs-attribute">-VaultName</span> <span class="hljs-string">'{your vault name}'</span> <span class="hljs-attribute">-ResourceGroupName</span> <span class="hljs-string">'{your resource group name}'</span> <span class="hljs-attribute">-Location</span> <span class="hljs-string">'South Central US'</span></code></pre>
<h2 id="setting-up-an-ad-application-and-service-principal-to-access-the-vault">Setting up an AD application and service principal to access the vault</h2>
Access to the Azure Key Vault is granted through Azure Active Directory, so you have to have an AD account you either own or have permissions to. Specifically permissions to create AD applications.

This will create an application in your AD which is accessed with the certificate you just loaded into Powershell.
<pre class="prettyprint"><code class=" hljs php"><span class="hljs-variable">$certificate</span> = <span class="hljs-keyword">New</span>-Object System.Security.Cryptography.X509Certificates.X509Certificate2

<span class="hljs-variable">$certificate</span>.Import(<span class="hljs-string">'c:\location\certificate.cer'</span>)

$startDate = $certificate.GetEffectiveDateString()
$endDate = $certificate.GetExpirationDateString()
<span class="hljs-variable">$credValue</span> = [System.Convert]::ToBase64String(<span class="hljs-variable">$certificate</span>.GetRawCertData())
<span class="hljs-variable">$azureADApplication</span> = <span class="hljs-keyword">New</span>-AzureRmADApplication -DisplayName <span class="hljs-string">"{application name}"</span> -HomePage <span class="hljs-string">"{application page}"</span> -IdentifierUris <span class="hljs-string">"{application page}"</span> -KeyValue <span class="hljs-variable">$credValue</span> -KeyType <span class="hljs-string">"AsymmetricX509Cert"</span> -KeyUsage <span class="hljs-string">"Verify"</span> -StartDate <span class="hljs-variable">$startDate</span> -EndDate <span class="hljs-variable">$endDate</span></code></pre>
You can use <code>$azureADApplication.ApplicationId</code> to use it as “client Id” when authenticating into the key vault.

Now let’s create a service principal to access the application.
<pre class="prettyprint"><code class=" hljs lasso"><span class="hljs-variable">$principal</span><span class="hljs-subst">=</span> <span class="hljs-literal">New</span><span class="hljs-attribute">-AzureRmADServicePrincipal</span> <span class="hljs-attribute">-ApplicationId</span> <span class="hljs-variable">$azureADApplication.ApplicationId</span></code></pre>
<h2 id="granting-access-to-the-service-principal-into-the-azure-key-vault">Granting access to the service principal into the Azure key vault</h2>
Finally, we have to tell the vault that the service principal is authorized to perform these operations.
<pre class="prettyprint"><code class=" hljs lasso"><span class="hljs-built_in">Set</span><span class="hljs-attribute">-AzureRmKeyVaultAccessPolicy</span> <span class="hljs-attribute">-VaultName</span> <span class="hljs-string">'{vault name}'</span> <span class="hljs-attribute">-ServicePrincipalName</span> <span class="hljs-variable">$principal.ServicePrincipalName</span> <span class="hljs-attribute">-PermissionsToSecrets</span> <span class="hljs-literal">all</span> <span class="hljs-attribute">-ResourceGroupName</span> <span class="hljs-string">'{resource group name}'</span></code></pre>
Also use -PermissionsToKeys for grating permissions to keys as well as secrets.

Full usage here <a href="https://msdn.microsoft.com/en-us/library/mt603625.aspx">Set-AzureRmKeyVaultAccessPolicy</a>

And that’s all folks.]]></content:encoded>
    </item>
    <item>
      <title>Handling certificates for testing without storing them (and with private key!)</title>
      <link>https://docs.microsoft.com/archive/blogs/adrianpadilla/handling-certificates-for-testing-without-storing-them</link>
      <pubDate>Fri, 11 Mar 2016 19:25:53 GMT</pubDate>
      <dc:creator><![CDATA[Adrian Padilla Vega]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/adrianpadilla/?p=153</guid>
      <description><![CDATA[Just a reminder to myself and you…

I do most of my unit testing involving certificates using...]]></description>
      <content:encoded><![CDATA[Just a reminder to myself and you…

I do most of my unit testing involving certificates using <a href="http://www.bouncycastle.org/">Bouncy Castle</a>, which is amazing.

Sometimes I just want to keep my tests simpler and when I’m not working on very complex requirements I use regular self-signed certificates. I have a couple dummy ones and I like handling test certificates on its byte representation to avoid pulling them from the store.

What about those times when the private key is strictly required? (Such as this time when I was constructing SAML tokens). I keep forgetting that simple certificate byte raw data does not contain its private key! It is at the end, just the certificate.
<blockquote>I don’t use implicitly typed local variables (var) in these examples

so it is clear what is each type. Also note that the Dump( ) method is

an extension used by <a href="http://www.linqpad.net/">LINQPad</a>. I’m aware of the unnecessary conversion to Base64 string but it is how I store these certificates in my tests.</blockquote>
<h2 id="wrong-implementation">Wrong Implementation</h2>
<pre><code>using(X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
{
    // Getting original certificate and its representation. Using RawData
    store.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindByThumbprint, "{ your lame-ass thumbprint XD LOL }", false);
    X509Certificate2 originalCertificate =  foundCertificates[0];
    string base64Representation =  Convert.ToBase64String(originalCertificate.RawData);

    // Creating certificate from this representation
    byte[] restoredCertificateBytes = Convert.FromBase64String(base64Representation);
    X509Certificate2 restoredCertificate = new X509Certificate2(restoredCertificateBytes);
    restoredCertificate.HasPrivateKey.Dump(); // Results in false.
}
</code></pre>
So this results in the X509 certificate object not containing its private key. The certificate is just that, the certificate. To have a certificate and private key pair, you must use another format. The most common of course being the PKCS#12 format, best known as your ol’ pal the PFX file. You obtain this not through the RawData property but using the Export method, which also returns a
<h2 id="correct-implementation">Correct implementation</h2>
<pre><code>using(X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
{
    // Getting original certificate and its representation. Using the Export method
    store.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection foundCertificates = store.Certificates.Find(X509FindType.FindByThumbprint, "{ your lame-ass thumbprint XD LOL }", false);
    X509Certificate2 originalCertificate =  foundCertificates[0];
    string base64Representation =  Convert.ToBase64String(originalCertificate.Export(X509ContentType.Pfx, "Your (not necesarily for testing) strong password"));

    // Creating certificate from this representation
    byte[] restoredCertificateBytes = Convert.FromBase64String(base64Representation);
    X509Certificate2 restoredCertificate = new X509Certificate2(restoredCertificateBytes, "Your (not necesarily for testing) strong password");
    restoredCertificate.HasPrivateKey.Dump(); // Results in true!.
}
</code></pre>

Happy coding, happy drinking.]]></content:encoded>
    </item>
    <item>
      <title>Getting more logs when troubleshooting assembly bindings</title>
      <link>https://docs.microsoft.com/archive/blogs/adrianpadilla/getting-more-logs-when-troubleshooting-assembly-bindings</link>
      <pubDate>Sat, 20 Feb 2016 16:21:55 GMT</pubDate>
      <dc:creator><![CDATA[Adrian Padilla Vega]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/adrianpadilla/?p=81</guid>
      <description><![CDATA[When having runtime assembly binding issues, in most cases the FusionLog property of the exception...]]></description>
      <content:encoded><![CDATA[When having runtime assembly binding issues, in most cases the FusionLog property of the exception thrown is more than enough.

However, to get more insight about the binding process to troubleshoot assembly loading exceptions or even more subtle errors such as grabbing an unexpected version of the assembly, you can use the Fusion Log Viewer:

<a href="https://msdnshared.blob.core.windows.net/media/2016/02/fuslogvw.png"><img class="alignnone size-full wp-image-93" src="https://msdnshared.blob.core.windows.net/media/2016/02/fuslogvw.png" alt="fuslogvw" width="775" height="418" /></a>

&nbsp;

This comes with your Visual Studio tools and it is available in the developer command line (remember you gotta have a shortcut handy?). The callsign for this warrior is fuslogvw.exe.

More information <a title="Fuslogvw.exe" href="https://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx" target="_blank">here</a>.

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>How to get an assembly's public Token, with capital "T"</title>
      <link>https://docs.microsoft.com/archive/blogs/adrianpadilla/how-to-get-an-assemblys-public-token</link>
      <pubDate>Fri, 19 Feb 2016 15:18:44 GMT</pubDate>
      <dc:creator><![CDATA[Adrian Padilla Vega]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/adrianpadilla/?p=71</guid>
      <description><![CDATA[Sometimes I forget this simple fact and drives me crazy (and for those who are learning to do this...]]></description>
      <content:encoded><![CDATA[Sometimes I forget this simple fact and drives me crazy (and for those who are learning to do this for the first time).

The parameters of the SN.exe (Strong Name Utility) tool, are <strong>CASE SENSITIVE</strong>, so… For getting the Public key token of a Strongly named assembly:
<pre><code>sn -T "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
</code></pre>
With the <strong>T</strong> as capitalized as you can. The “straightforward” error response you get if you do -t is:
<pre><code>Failed to convert key to token -- Invalid assembly public key.
</code></pre>
And that is correct because….
<pre><code>-t[p] &lt;infile&gt;
    Display token for public key in &lt;infile&gt; (together with the public key
    itself if -tp is used).
  -T[p] &lt;assembly&gt;
    Display token for public key of &lt;assembly&gt; (together with the public key
    itself if -Tp is used).
</code></pre>
…geez, some usability please :) I promise a later post on developer usability….

Of course do this from the Developer Command Prompt, developers should always have a shortcut to this on the desktop. Grumpy dev has a shortcut. Grumpy dev is smart. Be like Grumpy dev.]]></content:encoded>
    </item>
    <item>
      <title>Versioning 2.0</title>
      <link>https://docs.microsoft.com/archive/blogs/adrianpadilla/versioning-2-0</link>
      <pubDate>Thu, 18 Feb 2016 11:39:10 GMT</pubDate>
      <dc:creator><![CDATA[Adrian Padilla Vega]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/adrianpadilla/?p=31</guid>
      <description><![CDATA[I still like our classic versioning systems, I'm an old-fashioned developer who was raised in the...]]></description>
      <content:encoded><![CDATA[I still like our classic versioning systems, I'm an old-fashioned developer who was raised in the world of Software <strong>Products</strong>.

However, a new Grumpy Dev's rant is coming up. We are not in a world of packed software anymore, with big product factories which were self-involved in their developments, and in which versioning was only to distinguish one artifact to the same one in another point of time.

Today, development is highly democratized. We have publicly shared projects. We have public web services with changing API's. We have software package sharing mechanisms such as NuGet (or npm if Node.js is your gig, or pip if you are a Python snake charmer, etc.).

Just having a linear (most likely time) progression of software versions is not enough in many scenarios. We have to make sense out of this digit string. Here is where <a href="http://semver.org/">Semantic Versioning</a> comes to the rescue.

In the words of <a href="http://tom.preston-werner.com/">Tom Preston-Werner</a>:
<ol>
	<li>MAJOR version when you make incompatible API changes,</li>
	<li>MINOR version when you add functionality in a backwards-compatible manner, and</li>
	<li>PATCH version when you make backwards-compatible bug fixes.</li>
</ol>

This gives more meaning to it, doesn't it? I'm taking a wild guess here by assuming that's why is called <em>semantic </em>versioning. Plus, in most cases you can still tell which version comes after another.

Start using semantic versioning TODAY.

"In order to be united as software developers, we must give meaning to our version numbers." - Abraham Lincoln.
]]></content:encoded>
    </item>
  </channel>
</rss>