<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Operating Systems on gvisoc.com</title>
    <link>https://gvisoc.com/en/categories/operating-systems/</link>
    <description>Recent content in Operating Systems on gvisoc.com</description>
    <image>
      <title>gvisoc.com</title>
      <url>https://gvisoc.com/images/site-umina-gs.jpg</url>
      <link>https://gvisoc.com/images/site-umina-gs.jpg</link>
    </image>
    <generator>Hugo -- 0.151.0</generator>
    <language>en-AU</language>
    <managingEditor>gabriel@gvisoc.com (Gabriel Viso Carrera)</managingEditor>
    <webMaster>gabriel@gvisoc.com (Gabriel Viso Carrera)</webMaster>
    <copyright>Gabriel Viso Carrera</copyright>
    <lastBuildDate>Wed, 28 Apr 2021 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://gvisoc.com/en/categories/operating-systems/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Verify Your Downloads!</title>
      <link>https://gvisoc.com/en/posts/verify-downloads/</link>
      <pubDate>Wed, 28 Apr 2021 00:00:00 +0000</pubDate><author>gabriel@gvisoc.com (Gabriel Viso Carrera)</author>
      <guid>https://gvisoc.com/en/posts/verify-downloads/</guid>
      <description>&lt;p&gt;When we download software, we need to verify two things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The integrity of the software we have just downloaded.&lt;/li&gt;
&lt;li&gt;The authenticity of the package.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Checking these two things will ensure that the download went well, and that the software is authentic (and not malware, for example).&lt;/p&gt;
&lt;p&gt;&lt;img alt=&#34;Verifying the integrity and authenticity of a Manjaro ISO&#34; loading=&#34;lazy&#34; src=&#34;https://gvisoc.com/images/20210428-manjaro.gif&#34;&gt;&lt;/p&gt;
&lt;p&gt;For the impatient, here is the process assuming that we have downloaded:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A software package we want to use, in the example &lt;code&gt;software.pkg&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;A file containing the reference hash; in the example, &lt;code&gt;software.pkg.sha256&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;A file containing the signature of the Software Author; in the example, &lt;code&gt;software.sig&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The public keys of the Software Author; in the example, &lt;code&gt;author.gpg&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;    $ sha256sum -c software.pkg.sha256          # 1. Check the download integrity
    $ gpg --import author.gpg                   # 2a) Import downloaded public keys
    $ gpg --keyserver hkp://&amp;lt;server&amp;gt; \
                   --search-keys &amp;lt;shortID&amp;gt;      # 2b) Import public keys from a server
    $ gpg --verify software.sig software.pkg    # 3) Verify signatures
    $ gpg --list-public-keys --with-sig-check   # 4) If needed, check web of trust
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;These commands, why we run them, how they work, and how we should understand them, are discussed next. All the commands are Linux-specific, but information on Windows equivalents can be found in plenty of sites and I will probably write other post in the next few days.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>When we download software, we need to verify two things:</p>
<ul>
<li>The integrity of the software we have just downloaded.</li>
<li>The authenticity of the package.</li>
</ul>
<p>Checking these two things will ensure that the download went well, and that the software is authentic (and not malware, for example).</p>
<p><img alt="Verifying the integrity and authenticity of a Manjaro ISO" loading="lazy" src="/images/20210428-manjaro.gif"></p>
<p>For the impatient, here is the process assuming that we have downloaded:</p>
<ul>
<li>A software package we want to use, in the example <code>software.pkg</code></li>
<li>A file containing the reference hash; in the example, <code>software.pkg.sha256</code></li>
<li>A file containing the signature of the Software Author; in the example, <code>software.sig</code></li>
<li>The public keys of the Software Author; in the example, <code>author.gpg</code></li>
</ul>
<pre tabindex="0"><code>    $ sha256sum -c software.pkg.sha256          # 1. Check the download integrity
    $ gpg --import author.gpg                   # 2a) Import downloaded public keys
    $ gpg --keyserver hkp://&lt;server&gt; \
                   --search-keys &lt;shortID&gt;      # 2b) Import public keys from a server
    $ gpg --verify software.sig software.pkg    # 3) Verify signatures
    $ gpg --list-public-keys --with-sig-check   # 4) If needed, check web of trust
</code></pre><p>These commands, why we run them, how they work, and how we should understand them, are discussed next. All the commands are Linux-specific, but information on Windows equivalents can be found in plenty of sites and I will probably write other post in the next few days.</p>
<h1 id="checking-the-integrity-of-a-download">Checking the Integrity of a Download</h1>
<p>We want to check the integrity of a downloaded package to ensure that there were no transmission errors, and that nobody between our computer and the server exchanged the package for something else. We are checking that the download went well and we obtained <em>whatever</em> there was in the server: no more, and no less.</p>
<p>To do this, we verify the checksums of the files. Checksums are representations of the content smaller than the content itself, calculated by algorithms that ensure a stupidly small probability of two different files producing the same result. Some of those algorithms are members of a family called &ldquo;hashes&rdquo;. Most useful checksums, and hashes particularly, always have the same length.</p>
<p>If there was a single bit of the file that got changed over the wire, the checksum calculated in our computer over the corrupted file would be different than the checksum of the server&rsquo;s file: the checksum wouldn&rsquo;t verify.</p>
<p>In order to calculate a checksum we only need the file itself, and the right program installed.</p>
<p>For example, if we go to the <a href="https://github.com/VSCodium/vscodium/releases">downloads page</a> for <a href="https://vscodium.com/">VSCodium</a>, a fully Open Source version of Visual Studio Code, we can see that for every package there is an extra file, ending in <code>.sha256</code>:</p>
<pre><code>codium-1.55.2-1618361370.el8.x86_64.rpm
codium-1.55.2-1618361370.el8.x86_64.rpm.sha256
</code></pre>
<p>This extra file contains the reference checksum calculated over the server&rsquo;s file, and that is the exact same value that we should obtain in our computer from the downloaded copy.</p>
<p>The idea is to download both files to the same directory, and run the following command <code>sha256sum -c</code> over the checksums file:</p>
<pre><code>$ sha256sum -c codium-1.55.2-1618361370.el8.x86_64.rpm.sha256 
codium-1.55.2-1618361370.el8.x86_64.rpm: OK
</code></pre>
<p>What happened here is that the program <code>sha256sum</code> checked (<code>-c</code>) that the reference checksums present in the file <code>codium-1.55.2-1618361370.el8.x86_64.rpm.sha256</code> could be calculated locally using the downloaded file. The <code>.sha256</code> file content is the following:</p>
<pre><code>75b9f844c22c98d4da33e64b6c7c49e8b4d0d94a438e4f8ce976e7e54b40a682  codium-1.55.2-1618361370.el8.x86_64.rpm
</code></pre>
<p>That line is a &ldquo;properly formatted SHA256 checksum line&rdquo;, which is built by a SHA256 hash, two (2) spaces, and the name of the file the hash was calculated from in the server. From there, the check <code>sha256sum -c</code> performs is just to find a file that has the same name as in that line, calculate its SHA256 hash, and compare it with the first part of the line.</p>
<p>In this case the verification was complete and correct.</p>
<p>A file like that can have plenty of lines, not just one, and <code>sha256sum -c</code> will run all the checks in a batch.</p>
<p>Another possibility can be to have only the file to download, and the SHA256 line in the website, for you to see. In that case, we&rsquo;d download the file and get the SHA256 locally by executing the <code>sha256sum</code> over the downloaded file, without <code>-c</code>:</p>
<pre><code>$ sha256sum codium-1.55.2-1618361370.el8.x86_64.rpm
75b9f844c22c98d4da33e64b6c7c49e8b4d0d94a438e4f8ce976e7e54b40a682  codium-1.55.2-1618361370.el8.x86_64.rpm
</code></pre>
<p>That would give us the previously mentioned line, and we should just visually compare the hashes.</p>
<p>When the checksums are correct, we are sure that the download went well, <strong>but nothing else</strong>. It&rsquo;s up to us whether or not we trust that the publisher of the software is publishing authentic software, made by its true authors.</p>
<h1 id="checking-the-authorship-and-authenticity-of-the-software">Checking the Authorship and Authenticity of the Software</h1>
<p>If we don&rsquo;t trust the Software Publisher, that is to say, the website or the server we downloaded the package from, then checking the integrity of the download is not enough. The Publisher could have offered anything else in that file, and calculate a perfect valid reference checksum for a counterfeit package.</p>
<p>In such case of distrust, we want to check the software authorship, and therefore its authenticity. We can do that by obtaining a cryptographic signature of the package, created by the Software Author, and verifying it cryptographically.</p>
<p>There are many cryptographic signature mechanisms and algorithms, but here we will focus on signatures produced using asymmetric cryptography because they are the ones used most often, if not the only ones used to sign software.</p>
<p>In most asymmetric cryptography frameworks like PGP and GPG, the signature works as follows:</p>
<ul>
<li>
<p>A Software Author would have two keys: Private or Secret key, and Public Key. They are generated in the same process and they are inextricably linked.</p>
</li>
<li>
<p>The Public Key is generally available; the Secret Key is never shared with anyone.</p>
</li>
<li>
<p>Using their Secret Key, the software author produce a cryptographic signature, which in the case of PGP (or GPG), it consists in:</p>
</li>
<li>
<p>calculating a hash, similar that the ones we&rsquo;ve just discussed,</p>
</li>
<li>
<p>signing the hash using the Secret Key and a cryptographic singing algorithm.</p>
</li>
</ul>
<p>The idea of signing a hash and not the file itself is that a file can have a size from a few bytes to Gigabytes or Terabytes. By signing the hash, which is much smaller and has a fixed length, the result is produced in a predictable amount of time.</p>
<p>As the Secret and Public Keys are an inextricable pair, only the Public Key of the software Author will verify correctly the signature produced with the corresponding Secret Key. As the Public Key is made available, everybody can verify the signatures using the right software.</p>
<p>Here&rsquo;s what we need to do to check a signature with a real example, a Manjaro GNU/Linux ISO file.</p>
<p><strong>First</strong>: Download the software from an, in principle, trusted server. In this case, we will download a file named <code>manjaro-xfce-21.0.2-210419-linux510.iso</code> from the <a href="https://manjaro.org/downloads/official/xfce/">Manjaro XFCE download page</a>.  This file has an associated GPG signature that we will also download, <code>manjaro-xfce-21.0.2-210419-linux510.iso.sig</code>, and a SHA1 hash printed in the web page, <code>7d9d5d886188ebb0a05c9ceeabdb068fb2544feb</code>.</p>
<p><img alt="Manjaro download page" loading="lazy" src="/images/20210428-manjarodownload.png"></p>
<p><strong>Second</strong>: <strong>Check the hash</strong> as we discussed earlier in this post, to make sure that the package is uncorrupted. In this case we need to compute the hash and compare it visually with the reference one, present in the download page.</p>
<pre><code>$ sha1sum manjaro manjaro-xfce-21.0.2-210419-linux510.iso
7d9d5d886188ebb0a05c9ceeabdb068fb2544feb  manjaro-xfce-21.0.2-210419-linux510.iso
</code></pre>
<p>It verifies, so let&rsquo;s go with the GPG signature.</p>
<p><strong>Third</strong>: For us to be able to verify a GPG signature, we first need to <strong>obtain the public keys of the Software Author</strong>. In this case, <a href="https://wiki.manjaro.org/index.php?title=How-to_verify_GPG_key_of_official_.ISO_images">Manjaro offers two sets of public keys</a>, the general Manjaro ones, and Philip Müller&rsquo;s, &ldquo;just in case we didn&rsquo;t trust the server where Manjaro made the general keys file available&rdquo;. That statement is a bit of food for thought that we&rsquo;ll discuss later, and a good example because it shows two ways for obtaining public keys.</p>
<p>First, we download and import the Manjaro general keys.</p>
<pre><code>$ wget https://[url to the manjaro keys]/manjaro.gpg -O manjaro.gpg
$ gpg --import manjaro.gpg
</code></pre>
<p>On April 28th 2021 this imported 22 keys into the keyring, allowing us to verify packages signed by several people and machines at Manjaro.</p>
<p>To download Philip Müller&rsquo;s keys from a public PGP Key Server, use the following:</p>
<pre><code>$ gpg --keyserver hkp://pool.sks-keyservers.net --search-keys 11C7F07E
gpg: data source: http://194.95.66.28:11371
(1) Philip Müller (Called Little) &lt;REDACTED@manjaro.org&gt;
      2048 bit RSA key CAA6A59611C7F07E, created: 2012-05-05
Keys 1-1 of 1 for &quot;11C7F07E&quot;.  Enter number(s), N)ext, or Q)uit &gt; 1
gpg: key CAA6A59611C7F07E: &quot;Philip Müller (Called Little) &lt;REDACTED@manjaro.org&gt;&quot; not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
</code></pre>
<p>Note that <code>Enter number(s), N)ext, or Q)uit &gt;</code> is an actual prompt and we have to select the key, <code>1</code> in this case. Pay attention to the <code>CAA6A59611C7F07E</code> part: is an identifier for the key. Another thing to note is that the string we used to search the key (<code>11C7F07E</code>) is part of the key identifier. The lower part of a key&rsquo;s ID is often referred to as &ldquo;short identifier of the key&rdquo; for obvious reasons.</p>
<p>The keys can also be searched by some other identificative fields, for example an email (real email omitted for privacy reasons!):</p>
<pre><code>$ gpg --keyserver hkp://pool.sks-keyservers.net --search-keys &quot;REDACTED@manjaro.org&quot;

gpg: data source: http://194.95.66.28:11371
(1) Philip Müller (Called Little) &lt;REDACTED@manjaro.org&gt;
      2048 bit RSA key CAA6A59611C7F07E, created: 2012-05-05
...
</code></pre>
<p>The key ID identifies the pair of keys, not just the Public Key. It is important to know the ID of key pair, as it is the only way to really identify a key used to produce a signature and therefore the key needed to verify it. There can be many keys for a single email address, not all of them legit. The way to know the key needed to verify a signature is try to verify it without importing any key, as it will output the ID of the key pair that was used:</p>
<pre><code>gpg: Signature made Mon 19 Apr 2021 18:47:28 AEST
gpg:                using RSA key 3B794DE6D4320FCE594F4171279E7CF5D8D56EC8
gpg: Can't check signature: No public key
</code></pre>
<p><strong>Fourth</strong>: If the download of the iso verified the hash on previous steps, then check the signatures:</p>
<pre><code>$ gpg --verify manjaro-xfce-21.0.2-210419-linux510.iso.sig  manjaro-xfce-21.0.2-210419-linux510.iso
gpg: Signature made Mon 19 Apr 2021 18:47:28 AEST
gpg:                using RSA key 3B794DE6D4320FCE594F4171279E7CF5D8D56EC8
gpg: Good signature from &quot;Manjaro Build Server &lt;build@manjaro.org&gt;&quot; [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 3B79 4DE6 D432 0FCE 594F  4171 279E 7CF5 D8D5 6EC8
</code></pre>
<p>In this case, the signing key was one of the keys present in the file <code>manjaro.gpg</code>, the one for the <em>Manjaro Build Server</em> with identifier <code>3B794DE6D4320FCE594F4171279E7CF5D8D56EC8</code>. The verification process was correct, so we need that something called <em>Manjaro Build Server</em> is the creator of the ISO we&rsquo;ve just downloaded.</p>
<p><strong>Fifth</strong>: If we want to check the authenticity of such <em>Manjaro Build Server</em> dude, we can do so by validating its key using Philip Müller&rsquo;s key (provided we  trust him). That can be done by check the <em>web of trust</em> for Manjaro Build Server key, and see whether Philip is part of that web of trust. For this one, issue the following command:</p>
<pre><code>$ gpg --list-public-keys --with-sig-check
</code></pre>
<p>Within the output of this command we can see all the public keys we have in our keyring, and who has signed them. Signing a Public Key with your own secret key is, in this context, the ultimate vouching act. In the case of the Manjaro Build Server, which we can identify by looking at its identifier, we can see that within its signers there is Philip Müller (the ID is the same previously imported <code>CAA6A59611C7F07E</code>):</p>
<pre><code>pub   rsa3072 2020-10-28 [SC] [expires: 2022-10-28]
      3B794DE6D4320FCE594F4171279E7CF5D8D56EC8
uid           [ unknown] Manjaro Build Server &lt;build@manjaro.org&gt;
sig!         8238651DDF5E0594 2020-10-29  Matti Hyttinen &lt;REDACTED@manjaro.org&gt;
sig!         DAD3B211663CA268 2020-10-29  Bernhard Landauer &lt;REDACTED@manjaro.org&gt;
sig!         084A7FC0035B1D49 2020-10-29  Dan Johansen (Manjaro) &lt;REDACTED@manjaro.org&gt;
sig!         CAA6A59611C7F07E 2020-10-29  Philip Müller (Called Little) &lt;REDACTED@manjaro.org&gt;
sig!3        279E7CF5D8D56EC8 2020-10-28  Manjaro Build Server &lt;build@manjaro.org&gt;
sub   rsa3072 2020-10-28 [E] [expires: 2022-10-28]
sig!         279E7CF5D8D56EC8 2020-10-28  Manjaro Build Server &lt;build@manjaro.org&gt;
</code></pre>
<p>Therefore, if we trust Philip Müller, we can trust the downloaded ISO signature because Philip has endorsed the Manjaro Build Server by signing its key with his own.</p>
<h1 id="package-managers">Package Managers</h1>
<p>The above process is what we need to do for the software we download manually, from the web.</p>
<p>Package Managers for GNU/Linux, as apt, pacman or yum among others, for Windows as Chocolatey, and for macOS as homebrew, <em>should</em> do all the avobe automatically, transparently and by default. Check the documentation of the system and package manager you use (and trust) to check specific details.</p>
<h1 id="this-is-all-about-who-we-trust">This is All About Who We Trust</h1>
<p>If we pay attention to how this works, we&rsquo;ll se that all this is about trust. There is no technique that would give us 100% certainty of the authenticity of a software package. We need to judge if we trust the Software Publisher, and if we trust the Software Author, and if we believe their public keys really belong to them &ndash;the actual persons or companies. Check after check, we are traversing a web of trust that is effective as long as we can find a point we can trust.</p>
<h1 id="further-reading">Further Reading</h1>
<p>A good introduction of the web of trust, and links to further material, can be found <a href="https://en.wikipedia.org/wiki/Web_of_trust">in the Wikipedia</a>.</p>
<p>More on the cryptographic suite used by most software publishers, authors and distribution channels can be found in the <a href="https://www.gnupg.org/gph/en/manual.html">GNU Privacy Handbook</a>.</p>
]]></content:encoded>
    </item>
    <item>
      <title>Fixing a Common User Home Service Error in Synology NASes</title>
      <link>https://gvisoc.com/en/posts/fixing-homes-error-synology-nas/</link>
      <pubDate>Sat, 06 Feb 2021 16:32:00 +0000</pubDate><author>gabriel@gvisoc.com (Gabriel Viso Carrera)</author>
      <guid>https://gvisoc.com/en/posts/fixing-homes-error-synology-nas/</guid>
      <description>&lt;p&gt;If you have a Synology NAS and you are a technology enthusiast, or have some interest in using such machines as home servers, you may run into a problem that is quite common. Judging from the amount of Google results, the User Home service gets somehow broken quite often the first time it is activated, and neither is detected by some other services that use it as a dependency, nor can it be deactivated.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>If you have a Synology NAS and you are a technology enthusiast, or have some interest in using such machines as home servers, you may run into a problem that is quite common. Judging from the amount of Google results, the User Home service gets somehow broken quite often the first time it is activated, and neither is detected by some other services that use it as a dependency, nor can it be deactivated.</p>
<p>I came across the cause of the problem and its solution; keep reading to know more.</p>
<h1 id="the-symptoms">The Symptoms</h1>
<p>At some point you need to activate User Home service as per the requirements of some other package (for example, Synology Mail), or just because you want to work through SSH, or any other valid reason. Although you activate it, the dependent package keeps asking you to enable it. Or, if you just enabled it to use home folders via SSH, although you land on a home directory when you log in through SSH, you can&rsquo;t see it through DS File or File Station:</p>
<p><img alt="FileStation Not Showing Homes" loading="lazy" src="/images/20210206-filestation.png"></p>
<p>In the above picture you should see a folder for each user under <code>homes</code>, plus a <code>home</code> directory that would host your files (it&rsquo;s like a symbolic link dynamically created when you log in to the NAS through DSM or DS File).</p>
<p>If you try to disable and re-enable User Homes Service, DSM shows a sad and brief &ldquo;Operation Failed&rdquo; error pop up, and in Log Center you just see a useless message &ldquo;User home service disable failed&rdquo; like the one below:</p>
<p><img alt="Log Station Message" loading="lazy" src="/images/20210206-logcenter.png"></p>
<h1 id="the-problem">The Problem</h1>
<p>The problem is that the user homes&rsquo; hosting folder, named <code>homes</code>, should be created in one of the main volumes inside the disk array, for instance, <code>/volume1/homes</code>, and a symbolic link back should be created at <code>/var/services/homes</code>. Instead, in this case the <code>homes</code> folder was created in that location directly, as a regular folder (<code>/var/services/homes</code>). We can check it by doing SSH to the NAS:</p>
<pre><code>user@hostname:~$ pwd
/var/services/homes/user
user@hostname:~$ cd ../..
user@hostname:/var/services$ ls -lda homes
drwxr-xr-x 6 root root 4096 Feb 5 08:00 homes 
</code></pre>
<p>The expected result of a successful User Home service activation is this one instead:</p>
<pre><code>user@hostname:/var/services$ ls -lda homes
lrwxr-xr-x 6 root root 4096 Feb 5 08:10 homes -&gt; /volume1/homes 
</code></pre>
<p>Not only you can see where it points, but also the <code>l</code> flag on the folder permissions, meaning <em>link</em>, instead of a <code>d</code> from <em>directory</em>.</p>
<p>It is important to note that, although the user still has its home folder that works, <strong>the user homes created this way are outside the disk array and in the operating system&rsquo;s filesystem</strong>. This fact have several consequences, all of them dangerous for our files, for DSM&rsquo;s stability, and therefore for our NAS reliability.</p>
<p>In the first place, it causes almost every Synology package that depends on the User Home service to fail. Synology packages usually operate with directories under the volumes created inside the disk array, not under <code>/var/services/</code>, and that&rsquo;s why Synology Mail didn&rsquo;t detect the user homes directories and kept asking for User Home service to be enabled. As with Synology Mail, if the NAS is kept in this situation, the files in those directories won&rsquo;t be accessible by any backup or synchronisation service, and something as simple as updating DSM can have all the files under <code>/var/services/homes/</code> wiped, and lost forever.</p>
<p>Another consequence is that all user home directories will be lost in the event of machine upgrades or replacement, meaning that in the event of moving the disks to a new NAS, those user home directories won&rsquo;t be carried over.</p>
<p>A much worse scenario would be the one where we run out of space in the system&rsquo;s partitions because we put too many files under our home directories, phisically located under <code>/var</code>, causing DSM to crash and, probably, to have problems to boot.</p>
<h1 id="the-solution">The Solution</h1>
<p>Solving the problem is as easy as login in through SSH to back up our files and delete the <code>/var/services/homes</code> folder:</p>
<pre><code>user@hostname:~$ cd /var/services
user@hostname:/var/services$ tar cfz /volume1/[dest. folder]/homes-backup.tgz homes
user@hostname:/var/services$ sudo rm -rf homes
</code></pre>
<p>After that, we create a symbolic link to <code>/volume1/homes</code>:</p>
<pre><code>user@hostname:/var/services$ sudo ln -s /volume1/homes homes
user@hostname:/var/services$ ls -lda homes
lrwxr-xr-x 6 root root 4096 Feb 5 08:10 homes -&gt; /volume1/homes
</code></pre>
<p>Finally, we log into the DSM web interface, to disable without error and re-enable the User Home service.</p>
<p>No services should fail on activation, and the DSM File Station should show all users&rsquo; home directories; time to restore the previous users&rsquo; home folders contents if needed.</p>
]]></content:encoded>
    </item>
    <item>
      <title>Installing Linux with Secure Boot</title>
      <link>https://gvisoc.com/en/posts/linux-secure-boot/</link>
      <pubDate>Mon, 15 Jun 2020 10:55:00 +0000</pubDate><author>gabriel@gvisoc.com (Gabriel Viso Carrera)</author>
      <guid>https://gvisoc.com/en/posts/linux-secure-boot/</guid>
      <description>This post is motivated by the confusion and the still prevalent recommendation of disabling Secure Boot when installing GNU/Linux, no matter what distribution we are talking about. However, many distributions do support Secure Boot since a while ago.</description>
      <content:encoded><![CDATA[<p>This post is motivated by the confusion and the still prevalent recommendation of disabling Secure Boot when installing GNU/Linux, no matter what distribution we are talking about.</p>
<p>Contrary to the mainstream trend of such a disablement and proceeding with an outdated bootstrap, security-wise, many distributions do support Secure Boot since a while ago.</p>
<p>In this post I will provide some links, references, and &ldquo;glue text to make sense&rdquo; in order to provide clarity about Secure Boot: what it is, what it provides, and what it takes from us &ndash;mostly in terms of user experience, or friction.</p>
<p>I do not want to reinvent the wheel or take credit for the existing state of the art, but to provide some insight that I hope it will be easy to understand to the Linux novel users. Or at least, to provide a lead that can be followed to read more and understand what&rsquo;s happening.</p>
<h2 id="structure">Structure</h2>
<p>You will find:</p>
<ol>
<li>What I assume you know, or a list of things for you to search about.</li>
<li>A process to install a Linux system with Secure Boot enabled.</li>
<li>Post-Install situations affected by Secure Boot</li>
<li>What is Secure Boot, and what&rsquo;s it based on.</li>
</ol>
<h2 id="what-i-assume-you-already-know-aka-what-youre-supposed-to-search-in-the-interwebs-if-not">What I assume you already know (a.k.a., what you&rsquo;re supposed to search in the interwebs if not!)</h2>
<p>I assume that you are familiar with the following concepts, which I try to summarise. But, please: use your search engine.</p>
<ul>
<li>Kernel: it&rsquo;s the hert of the operating system. It provides the applications with access to the hardware.</li>
<li>Modules: specialised code that the Kernel will load to tailor its capabilities to very specific hardware or configurations. Many times, when it allows the Kernel to understand a piece of hardware, it can be called &ldquo;a driver&rdquo; like in Windows lingo, but there are modules for many other things.</li>
<li>Root password: it&rsquo;s the password of the root user, which is the most powerful authority in a Unix or Unix-like system, as GNU/Linux for instance. Absolute privileges.</li>
<li>BIOS: stands for Basic Input and Ouput System, and it was the way that older (early 2000&rsquo;s and before) computers had to connect the Operating Systems to the hardware. This included a boot menu and a very few more options, and many specialised configurations for some hardware devices had to be done by plugging, unplugging or changing physical jumpers in the motherboard.</li>
<li>(U)EFI: stands for (Unified) Extensible Firmware Interface. It&rsquo;s the evolution of BIOS, looks after the same hardware to operating system bridge. It is much more advanced and comes with many more options, many of them enabled for modern system by default, like the GUID Partition Table for the Disks, and the Secure Boot.</li>
<li>GUID Partition Table. A modern partition schema that identifies partitions on the disk by giving them Globally Unique IDentifiers, rather than names. Amongst other things, supports much larger disk sizes.</li>
<li>Secure Boot deserves a whole section on its own. Go and check &ldquo;What is Secure Boot&rdquo; at the end of this post.</li>
</ul>
<h2 id="installation-process">Installation Process</h2>
<h3 id="check-whether-you-actually-have-uefi">Check whether you actually have UEFI</h3>
<p>First of all, have a look at what you have in your computer: whether BIOS or EFI. If you have BIOS you can skip the whole article, because Secure Boot was introduced in the UEFI.</p>
<p>If you&rsquo;re not sure which system your motherboard uses, and if you still have Windows there, check the following:</p>
<ul>
<li>Look for an EFI folder within <code>c:\windows\boot</code></li>
<li>Open the Disk Management Utility and check if you have a partition labeled EFI in your system disk, like this one:</li>
</ul>
<p><img alt="EFI Partition" loading="lazy" src="/images/20200615-diskmgrefi.png"></p>
<p>If you don&rsquo;t have Windows or you are unsure,</p>
<ul>
<li>Reboot the computer and look for a message telling you to press a key to enter setup.</li>
<li>Press that key, quick!</li>
<li>No worries, it happens to everybody. Reboot and try again.</li>
<li>Once inside, and without changing anything, look for indications of an EFI system: search for options like &ldquo;Secure Boot&rdquo;, &ldquo;Legacy/UEFI&rdquo; boot mode.</li>
</ul>
<p>If your system shows any of the above symptoms, you have an UEFI.</p>
<h3 id="choosing-a-distribution-that-supports-secure-boot">Choosing a distribution that supports Secure Boot</h3>
<p>There is a way to query distrowatch to get a list of the distributions that may support Secure Boot by searching included packages like <a href="https://distrowatch.com/search.php?pkg=shim&amp;amp;relation=lessequal&amp;amp;pkgver=1&amp;amp;distrorange=InAny"><code>shim</code></a> or <a href="https://distrowatch.com/search.php?pkg=efibootmgr&amp;amp;pkgver=0.&amp;amp;distrorange=InLatest#pkgsearch"><code>efibootmgr</code></a>, but the best way is to check your favourite distribution&rsquo;s documentation (kudos to <a href="https://firmwaresecurity.com/2019/04/29/list-of-linux-distros-support-of-trustedsecuremeasuredboot-and-fwupd-needed/">firmwaresecurity.com for the queries hint</a>).</p>
<p>The good news is that the support of Secure Boot is already in the Kernel and the base system for all of them, so it would be a matter of time and ideology for it to arrive to your computer. If you want to install a different distribution than those, you&rsquo;ll have to disable Secure Boot in your EFI.</p>
<h3 id="download-and-verify-an-iso-preferably-a-live-one-with-non-free-firmware-and-modules-included">Download and verify an ISO, preferably a Live one with non-free firmware and modules included</h3>
<p>It is advisable, always, to download an ISO installation image that offers you the possibility of trying Linux in your system without installing it first. This will give you an idea of whether or not your installation media will have the required modules for your hardware, most precisely (and critically neccessary) one module for the graphics adapter and another one for the network. Also, depending on your hardware and distribution, you may have to download specifically an ISO with <em>non-free</em> software included for it to work! This is almost always necessary (99%+ cases) in the case of Debian and most  laptops.</p>
<p>Download your distribution in ISO format, as usual, and look for a way to verify the files you download. Most every website that offers free or open source software these days will have a side or footnote telling offering you &ldquo;the hashes&rdquo; or the &ldquo;sums&rdquo;: MD5 or SHA checksum strings.</p>
<p>Checksums are strings that represent the contents of a file, much smaller than the files they represent. They are generated by a mathematical algorithm that ensures that the probability of getting the same result with different files is ridiculously small. So ridiculous that it&rsquo;s difficult to explain, but the chances are cosmically low.</p>
<p>These are techniques that allow you to check that the ISO you downloaded has not been corrupted by the download process, and more importantly, that they are authentic. It helps you know that the mirror or the server where the actual file is hosted, usually different than the server that publishes the checksums, has not been compromised: you&rsquo;re downloading an authentic image, without any malware with it. What they do is run the same procedures that you&rsquo;re about to run, in their side, and tell you to check that you get the same results.</p>
<p>If your distribution publisher offers you SHA verification sums, open Windows PowerShell and run <code>Get-FileHash</code> over the ISO you just downloaded:</p>
<p><img alt="Checking the sum!" loading="lazy" src="/images/20200615-getfilehash.png"></p>
<p>If your distribution publisher if offering MD5 sums, then open the regular command prompt and use <code>certutil -hashfile</code> over the file.</p>
<p>Whichever method you use, your local result should match with the check sums provided by the software publisher (leaving uppercase or lowercase aside).</p>
<p>If they provided some other methods, check their documentation.</p>
<h3 id="creating-a-usb-that-boots-under-uefi-conditions">Creating a USB that boots under UEFI conditions</h3>
<p>In order to create a bootable USB drive under UEFI&rsquo;s newer boot schema, that USB has to be formatted using GPT (Guid Partition Table), as the MBR (Master Boot Record) drives are considered legacy!</p>
<p>To do that, you can use Rufus to create the USB. Rufus is an open source program that you can download from its official site <a href="https://rufus.ie/">https://rufus.ie/</a>, and will offer you a simple, but powerful interface to create the bootable thumbdrive. Just make sure that you select GPT as Partition Scheme, and UEFI as Target System, leaving all other options by default (unless you wanted a persistent partition to use in a Live System):</p>
<p><img alt="Rufus" loading="lazy" src="/images/20200615-rufus.png"></p>
<h3 id="reboot-in-linux">Reboot in Linux</h3>
<ul>
<li>
<p>Reboot the computer and look for a message telling you to press a key to show the boot menu.</p>
</li>
<li>
<p>Press that key, quick!</p>
</li>
<li>
<p>No worries, it happens to everybody. Reboot and try again.</p>
</li>
<li>
<p>Search for your USB drive.</p>
</li>
<li>
<p>They are usually by the EFI the word &ldquo;USB&rdquo; and the brand of the device, plus some other model numbers and maybe the capacity.</p>
</li>
<li>
<p>Select it and press the Enter key.</p>
</li>
</ul>
<p>Select the option to <em>run</em> Linux, or to <em>try Linux</em> without installing.</p>
<p>If everything works, specially the graphics and the network, then you&rsquo;re good to go and install it.</p>
<h3 id="installing-with-secure-boot-things-that-can-happen">Installing with Secure Boot: things that can happen.</h3>
<p>In most of the cases, the installation process will be smooth and without any surprise. But, in some cases, either:</p>
<ul>
<li>The installation would remain stopped in a package for too long. If you expand the details of the installation process, you may see something like the below image.</li>
<li>You will prompted by the system that some third party software needs to be installed and you will to do some funky stuff for it to work, something similar to this:</li>
</ul>
<p><img alt="UbuntuPrompt" loading="lazy" src="/images/20200615-ubuntuprompt.png"></p>
<p>This is caused by Secure Boot, and nothing is wrong. What is happening is the following: the system found that it needs to install a package that will be loaded at boot time, but it is not signed. Secure Boot requires the software that runs at boot to be signed by a trusted key. The installation process can create a key for you, called &ldquo;Machine Owner Key&rdquo;, and sign the software with it, but in order to make the EFI trust the signature, it needs you to collaborate.</p>
<ul>
<li>Press the Enter key, or the tab key to focus OK and then Enter, or click OK if the prompt is run in a graphical environment.</li>
<li>In the next screen, you will be prompted to set a password: do it and jot it down in a paper, as you will prompted to write it in the first reboot.</li>
</ul>
<blockquote>
<p><strong>Here be dragons</strong>: if you have a non-english keyboard, <em>refrain yourself from using symbols that may be in a different key than the one in a US layout keyboard</em>, as they can cause problems when typing the password later.</p></blockquote>
<p>Once done, the installation should continue.</p>
<p>When you finish installing the system, it will reboot.</p>
<p>If you were prompted with such an ugly message, you will see a succession of screens like the following (taken from <a href="https://gist.github.com/reillysiemens/ac6bea1e6c7684d62f544bd79b2182a4">this Gist</a>, as they are the same in any case) in this first reboot:</p>
<p><img alt="1st screen" loading="lazy" src="/images/20200615-mokenroll1.png"></p>
<p>Select <strong>Enroll</strong> and press Enter.</p>
<p><img alt="2nd screen" loading="lazy" src="/images/20200615-mokenroll2.png"></p>
<p>Press <strong>Continue</strong>. Yes, it is a weird screen. If you press <code>View key 0</code> you&rsquo;ll see some information about the key you are enrolling, but it&rsquo;s quite technical and can be nonsense, specially if it was the installation program who created the MOK key.</p>
<p><img alt="3rd screen" loading="lazy" src="/images/20200615-mokenroll3.png"></p>
<p>Select <strong>Yes</strong>.</p>
<p><img alt="4th screen" loading="lazy" src="/images/20200615-mokenroll4.png"></p>
<p>Type the password you&rsquo;ve in your piece of paper and press Enter.</p>
<p><img alt="5th screen" loading="lazy" src="/images/20200615-mokenroll5.png"></p>
<p>Press Enter</p>
<p>When the system reboot, and provided that the installation program meets its quality goals, things should work.</p>
<h2 id="post-install-miscellanea">Post-Install Miscellanea</h2>
<table>
  <thead>
      <tr>
          <th>Case</th>
          <th>Solution</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>I am installing a binary package and I&rsquo;m prompted with the nefarious screen of the MOK!</td>
          <td>Repeat the process as told in the previous section. This is what will happen in many systems when you try to install third party binary packages. There are other systems, like Debian, that while supporting Secure Boot, they don&rsquo;t have an interactive process like that.</td>
      </tr>
      <tr>
          <td>I&rsquo;m trying to install a module that I know I need and it should work, but it won&rsquo;t load</td>
          <td>If you are getting a laconic <code>Permission Denied</code>, or <code>Operation not permitted</code> after trying to install a module in the Kernel, check <code>dmesg</code> after <code>modprobe module</code>, then look for something like <code>Lockdown: modprobe: Loading of unsigned module is restricted; see man kernel_lockdown.7</code>. If this is your case, you will have to create a MOK key, sign a module with it, and enroll the MOK key, <em>all manually</em>! Don&rsquo;t worry and go to the next section.</td>
      </tr>
      <tr>
          <td>I want to compile and install a module</td>
          <td>If this is your case, you will have to create a MOK key, sign a module with it, and enroll the MOK key, <em>all manually</em>! Don&rsquo;t worry and go to the next section.</td>
      </tr>
  </tbody>
</table>
<h2 id="manually-signing-binaries-eg-modules">Manually signing binaries (e.g.: modules)</h2>
<p>This is the case of a module compiled by hand, or when you install unsigned modules with Secure Boot installed, in more crude distributions like Debian.</p>
<p>The steps for Debian (credit to its official documentation and to my experience) are:</p>
<ul>
<li>Compile your software.</li>
<li><code>modprobe</code> will fail. Check that it is due to a Kernel Lockdown state imposed by the Secure Boot, to discard other errors. In <code>dmesg</code>, search for something with similar semantics to this:</li>
</ul>
<p><code>Lockdown: modprobe: Loading of unsigned module is restricted; see man kernel_lockdown.7</code></p>
<ul>
<li>If you have already enrolled a Machine Owner Key (MOK) yourself, and it is available for you, put it in your home directory and jump to step &ldquo;<strong>Open a terminal to sign the binary</strong>&rdquo;. Otherwise, continue here.</li>
<li>Install the packages <code>mokutil</code> and <code>openssl</code>.</li>
<li>Open a terminal and create a MOK (Machine Owner Key) with the following process (<code># commented</code>), documented <a href="https://wiki.debian.org/SecureBoot#Enroling_a_new_key">here</a>:</li>
</ul>
<pre tabindex="0"><code>    # Go to your home folder
    cd ~
    # Create a Machine Owner Key pair valid for 100 years. 
    # In the following, replace &#34;gabriel&#34; for your user name
    openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -days 36500 -subj &#34;/CN=gabriel/&#34; -nodes
</code></pre><ul>
<li>You will obtain two files, <code>MOK.der</code> and <code>MOK.priv</code> in your home folder. Enroll the keys in your EFI</li>
</ul>
<pre tabindex="0"><code>    # If you don&#39;t have sudo installed, run `su` and type the root password
    # before the following commands without sudo
    sudo mokutil --import MOK.der
    # This will prompt for a one time password to set up.
</code></pre><ul>
<li>Reboot the computer. You will be promted with the blue screens of section &ldquo;Installing with Secure Boot: things that can happen&rdquo;. In this case, if you select the options to <code>View Key 0</code>, you will be able to see your name and the name of your computer. In my example, I saw &ldquo;gabriel@rodas&rdquo;, and rodas is my computer named after <a href="https://en.wikipedia.org/wiki/Playa_de_Rodas">this beach</a> very close to my hometown.</li>
<li><strong>Open a terminal to sign the binary</strong>. Follow the process changing the <code>/path/to/file.ko</code> with the path to the file you need to sign.</li>
</ul>
<pre tabindex="0"><code>    # Assuming that you have kernel version X.Y.Z
    # Replace &#34;gabriel&#34; by your username.
    cd /lib/linux-kbuild-X-Y/
    sudo scripts/sign-file sha256 /home/gabriel/MOK.priv /home/gabriel/MOK.der /path/to/your/file.ko
</code></pre><ul>
<li>
<p>Try to load again the module</p>
<p>sudo modprobe /path/to/your/file.ko</p>
</li>
</ul>
<p>It should work now. This is the most common use case for this.</p>
<blockquote>
<p><strong>Here be dragons</strong>: hold your horses, one last thing before you go. Take these two files, <code>MOK.der</code> and <code>MOK.priv</code>, away from your user directory, hide them in a safe place. Personally, I keep them attached to an entry in my password manager, well encrypted. <strong>They are the door for someone to sign any malware so it can run at your computer&rsquo;s boot</strong>!</p></blockquote>
<h2 id="what-about-signing-a-custom-kernel">What about signing a custom Kernel?</h2>
<p>If you need to sign a Kernel, the <code>/path/to/your/file.ko</code> looks like <code>/boot/vmlinuz-[KERNEL-VERSION]</code>, and probably you will have to follow more steps. Although I haven&rsquo;t had the need for it, I found several forum and Stack Overflow questions that pointed to <a href="https://github.com/jakeday/linux-surface/blob/master/SIGNING.md">this document</a> as a valid process to do it.</p>
<h2 id="what-is-secure-boot">What is Secure Boot</h2>
<p>Secure Boot is a mechanism designed to protect the process of booting your computer, that is to say, making your boot secure. It is not a very creative name.</p>
<p>It was introduced at some point in the UEFI specifications, and it made a weird entrance in the scene because some poor communications skills and shady decisions from Microsoft. They told at some point that, for any PC machine to be Windows-Certified, they should pre-ship a cryptographic key (similar to the Machine Owner Key we&rsquo;ve used before in this post, but Microsoft&rsquo;s) to digitally verify the Windows bootable parts and the Kernel. They didn&rsquo;t specify at the point that they didn&rsquo;t care whether the Secure Boot could be disabled, or that many other keys should be able to be shipped or installed alonside Microsoft&rsquo;s! Thanks to that narrow statement, the community went crazy and, although they fixed the statement pretty much immediately, for many time Secure Boot was seen as a Microsoft attempt to close PC hardware to them. You can check this story <a href="https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface#Secure_boot_criticism">here</a>. It is true that the controversy continued for a while, specially related to ARM devices, but as always: technology isn&rsquo;t bad by itself, it is us who make good or bad use of it.</p>
<p>Indeed, Secure Boot is (to me) pretty awesome as it is a simple but powerful way to protect the boot sequence of your system against malware.</p>
<p>The &ldquo;Secure&rdquo; word of Secure Boot comes from Information Security, as it is based on asymmetric criptography. It works in such a way that, for the EFI to load any code at boot time, being it a Kernel, modules, or the GRUB itself, such code has to be cryptoraphically signed by a trusted key. Let&rsquo;s decypher such two sentences.</p>
<ul>
<li>
<p><strong>Asymmetric cryptography</strong> refers to a compendium of techniques that are based in a pair of keys, public key and secret key. They public key is meant to be available to everybody, while the secret key has to be kept secret to its owner.</p>
</li>
<li>
<p>That par of keys are often packed in a single software artefact called &ldquo;certificate&rdquo;, in such a way that the private part is protected by a passphrase. It can also be splitted in such a way that you can produce a certificate that will only contain the public key, to be able to share it. It provides two operations: encryption and signature.</p>
</li>
<li>
<p>Asymmetric Encryption works the following way: if I want to <strong>encrypt a message for you</strong>, so that only you are able to understand it, I will <strong>use your public key</strong> and a lot of standard maths. Once done, only your private key, plus a lot of standard maths, can decrypt it!</p>
</li>
<li>
<p>Asymmetric Signature works the opposite: if I want to prove you that <strong>it was me who wrote</strong> a message, I will <strong>sign it using my private key</strong> and a lot of standard maths. You will be able to check the signature using my public key and a lot of standard maths.</p>
</li>
<li>
<p>If someone changes a single character of that message, the signature won&rsquo;t be valid anymore.</p>
</li>
<li>
<p>The last point is great: a signature identifies the author of a message, and protects the communication against tampering.</p>
</li>
<li>
<p>We can cryptographically sign a message, or a binary file like a Kernel, or a module.</p>
</li>
<li>
<p>According to the above, when we sign some code and install it to be loaded at boot time, like a Kernel or a module, the EFI need to have available the public key to check the signatures. This defines the need of <em>enrolling public keys in the EFI</em>.</p>
</li>
<li>
<p>You can create a pair of keys, enroll the public key, and use them to sign software you create or compile, if you are the root user of a GNU/Linux system. When you create your own pair of keys, they are together called a <strong>Machine Owner Key</strong>, or MOK.</p>
</li>
<li>
<p>Enrolling a public key in the EFI is a process not only means to make available the public key to the EFI: it also makes the EFI trust that signature. Practically speaking, it will ultimately trust the software that is signed with a trusted key, and load and execute it with all the consequences.</p>
</li>
<li>
<p>Only a trusted software manudacturer, or an administrator of an operating system (root user in Linux) can enroll a key in the EFI and manually sign software.</p>
</li>
<li>
<p>Enrolling a key in the EFI is a process that requires such an administrator to collaborate and actively accept and prove his or her identity after a reboot. It cannot be automated by a malware process.</p>
</li>
</ul>
<p>A bit of recap. If you have the system bootstrap process checking signatures of the binary code that it loads, this means a lot of security.</p>
<p>Let&rsquo;s understand the two main <em>vectors of attack</em> it mitigates.</p>
<ol>
<li><strong>Only trusted signers</strong> (meaning software manufaturers, or you) <strong>can install code that runs automatically in the bootstrap of the system.</strong> That means, that if some random guy comes to your desk with a USB while you&rsquo;re away, he won&rsquo;t be able to infect your computer&rsquo;s bootstrap by putting some modules or writing code in the bootable partitions. He or she would have to enroll a key, too, and that requires (in Linux) to know the root password, which is meant to be secret and complex. They will have to be able not only to write code to the EFI, which may or may not be a challenge, but to hack the operating system they want to compromise.</li>
<li>If you accidentally allow a malware to run in your computer, that malware cannot infect the bootstrap chain even if it has the maximum privileges, as it will require active cooperation by an admin user to create and enroll its own MOK: check back the rest of the article at the point we set up a password, reboot, and type the password when enrolling the key. The only thing you have to do is to never leave your MOK private key in the computer to prevent the malware to sign itself with your own keys!</li>
</ol>
<p>I hope you didn&rsquo;t have to search many terms, and that this article was, at least, easy to follow. Feel free to send me some comments to comments (at) gvisoc (dot) com!</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
