<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>teoman.sh</title>
    <link>http://teoman.sh/</link>
    <description>hi! I am a devops engineer and any research I conduct or article I publish is indepentent, unrelated to my employer.</description>
    <pubDate>Sat, 27 Jun 2026 03:01:46 +0000</pubDate>
    <item>
      <title>Gpg and Digital Signatures</title>
      <link>http://teoman.sh/gpg-and-digital-signatures</link>
      <description>&lt;![CDATA[Introduction&#xA;Getting software off the internet is great, until you&#39;re not getting it from the actual distributor. Being able to securely transmit data and verify the entity you&#39;re receiving it from is a major issue that is solved by PKI (Public Key Infrastructure).&#xA;GPG (GnuPG) is a utility that is based on OpenPGP (Pretty Good Privacy) which is an encryption standard for signing and encrypting data.&#xA;So basically we&#39;re able to sign, encrypt, decrypt data with gpg. Unlike SSL/TLS, there are no &#34;Authorities&#34; that you put your trust in  by default, rather, a &#34;web of trust&#34;. I might generate a key pair and stating it belongs to me, but you might not trust me. You may trust a friend of mine who signed my key, if not, you can always trust a friend of his and so on. Key Signing Parties are events that people coming together in person with their legal documents stating their identity and then proceed to sign other people&#39;s keys and getting theirs signed.&#xA;gpg key pairs are used to identify a person. Private keys are kept in secret, public ones shared to anyone to be communicated with. A message signed by private key can only be encrypted by the corresponding public key, and vice versa. This is called asymmetric encryption, in contrast to symmetric encryption, where a single key is used to encrypt and decrypt data. &#xA;gpg keys come with a bundle where the person has a primary and subordinate key pairs. To make the key management easy this bundle is just called a key pair.&#xA;Generating a GPG key pair is fairly simple: &#xA;gpg (GnuPG) 2.4.4; Copyright (C) 2024 g10 Code GmbH&#xA;This is free software: you are free to change and redistribute it.&#xA;There is NO WARRANTY, to the extent permitted by law.&#xA;Please select what kind of key you want:&#xA;   (1) RSA and RSA&#xA;   (2) DSA and Elgamal&#xA;   (3) DSA (sign only)&#xA;   (4) RSA (sign only)&#xA;   (9) ECC (sign and encrypt) default&#xA;  (10) ECC (sign only)&#xA;  (14) Existing key from card&#xA;For most use cases, the default option which is Elliptic Curve Cryptography should suffice. &#xA;Please select which elliptic curve you want:&#xA;   (1) Curve 25519 default&#xA;   (4) NIST P-384&#xA;   (6) Brainpool P-256&#xA;Proceeding with the default:&#xA;Please specify how long the key should be valid.&#xA;         0 = key does not expire&#xA;      n  = key expires in n days&#xA;      nw = key expires in n weeks&#xA;      nm = key expires in n months&#xA;      ny = key expires in n years&#xA;Key is valid for? (0) 3y&#xA;You should choose a expiration date greater than zero, but you can always update this later as well for the key.&#xA;Now, you have generated a gpg key pair for yourself! Which is visible with gpg --list-keys&#xA;Digital Signatures&#xA;Now that we have key pair, we can start to sign any kind of message we&#39;d like. &#xA;echo &#34;Some important message&#34;   message.txt&#xA;Now, at a later point in time, we&#39;ll want to make sure of this messages integrity. Thus, let&#39;s get the hash of the file as well:&#xA;&#xA;sha256sum message.txt&#xA;31d1104978e7f73a0da6375f1b0d9add90bf96fbc5ef4dc9fb16804697ef2894  message.txt&#xA;The process of digitally signing messages includes hashing the content and then encrypting this hash with the private key. If one trusts my public key belongs to me, they will be able to verify that this message belongs to me and has not been tampered with. &#xA;&#xA;Signing a message&#xA;&#xA;gpg --sign message.txt will produce a message.txt.gpg. The message is compressed then signed, this signature file is in binary format and includes the message signed.&#xA;&#xA;The signature can be verified with gpg --verify message.txt.gpg&#xA;&#xA;Clearsign&#xA;&#xA;Another way of signing a message is clearsign:&#xA;&#xA;gpg --clearsign message.txt &#xA;which outputs the signature in ASCII armored plaintext format, thus the .asc extension. This doesn&#39;t compress the message and is in human readable format.&#xA;&#xA;-----BEGIN PGP SIGNED MESSAGE-----&#xA;Hash: SHA512&#xA;&#xA;S1ome important message&#xA;-----BEGIN PGP SIGNATURE-----&#xA;&#xA;iHUEARYKAB0WIQRBrsRfnEkrg1+zF5+Om9gJHQccpwUCZsL1FgAKCRCOm9gJHQcc&#xA;p1AXAQCgkI3FykZdG1S1+X5lejmjMRFCuEkKVniMKNXZIFZjLgD/S/WrpuLA2Q0t&#xA;D17oNhH13r5v5c9j0lpfMfhrEJS8awc=&#xA;=G5hr&#xA;-----END PGP SIGNATURE-----&#xA;&#xA;Detached signatures&#xA;&#xA;The previous 2 signatures include the actual message within the signature. There is this 3rd method where the signature does not include the messsage, meaning you would need the actual message content as well in order to verify the message. This is created with:&#xA;&#xA;gpg --detach-sign message.txt which outputs message.txt.sig.&#xA;Now, with message.txt and message.txt.sig at hand, the signature can be verified: gpg --verify message.txt.sig message.txt &#xA;&#xA;gpg: Signature made Mon 19 Aug 2024 10:00:40 AM +03&#xA;gpg:                using EDDSA key 41AEC45F9C492B835FB3179F8E9BD8091D071CA7&#xA;gpg: Good signature from &#34;Teoman Yuksel root@teoman.sh&#34; [ultimate]&#xA;&#xA;Try to change the content of message.txt and then verify the signature.&#xA;&#xA;gpg: Signature made Mon 19 Aug 2024 10:00:40 AM +03&#xA;gpg:                using EDDSA key 41AEC45F9C492B835FB3179F8E9BD8091D071CA7&#xA;gpg: BAD signature from &#34;Teoman Yuksel root@teoman.sh&#34; [ultimate]&#xA;&#xA;gpg will no longer verify the signature.&#xA;&#xA;Conclusion&#xA;&#xA;gpg is a great tool utilizing PKI in the real world making possible secure communication that is still used by masses today.  &#xA;&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<h2 id="introduction">Introduction</h2>

<p>Getting software off the internet is great, until you&#39;re not getting it from the actual distributor. Being able to securely transmit data and verify the entity you&#39;re receiving it from is a major issue that is solved by PKI (Public Key Infrastructure).
GPG (GnuPG) is a utility that is based on OpenPGP (Pretty Good Privacy) which is an encryption standard for signing and encrypting data.
So basically we&#39;re able to sign, encrypt, decrypt data with gpg. Unlike SSL/TLS, there are no “Authorities” that you put your trust in  by default, rather, a “web of trust”. I might generate a key pair and stating it belongs to me, but you might not trust me. You may trust a friend of mine who signed my key, if not, you can always trust a friend of his and so on. <a href="https://en.wikipedia.org/wiki/Key_signing_party">Key Signing Parties</a> are events that people coming together in person with their legal documents stating their identity and then proceed to sign other people&#39;s keys and getting theirs signed.
<code>gpg</code> key pairs are used to identify a person. Private keys are kept in secret, public ones shared to anyone to be communicated with. A message signed by private key can only be encrypted by the corresponding public key, and vice versa. This is called asymmetric encryption, in contrast to symmetric encryption, where a single key is used to encrypt and decrypt data.
<code>gpg</code> keys come with a bundle where the person has a primary and subordinate key pairs. To make the key management easy this bundle is just called a key pair.
Generating a GPG key pair is fairly simple:
<code>gpg --full-gen-key</code></p>

<pre><code>gpg (GnuPG) 2.4.4; Copyright (C) 2024 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
   (1) RSA and RSA
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (9) ECC (sign and encrypt) *default*
  (10) ECC (sign only)
  (14) Existing key from card
</code></pre>

<p>For most use cases, the default option which is Elliptic Curve Cryptography should suffice.</p>

<pre><code>Please select which elliptic curve you want:
   (1) Curve 25519 *default*
   (4) NIST P-384
   (6) Brainpool P-256
</code></pre>

<p>Proceeding with the default:</p>

<pre><code>Please specify how long the key should be valid.
         0 = key does not expire
      &lt;n&gt;  = key expires in n days
      &lt;n&gt;w = key expires in n weeks
      &lt;n&gt;m = key expires in n months
      &lt;n&gt;y = key expires in n years
Key is valid for? (0) 3y
</code></pre>

<p>You should choose a expiration date greater than zero, but you can always update this later as well for the key.
Now, you have generated a gpg key pair for yourself! Which is visible with <code>gpg --list-keys</code></p>

<h2 id="digital-signatures">Digital Signatures</h2>

<p>Now that we have key pair, we can start to sign any kind of message we&#39;d like.
<code>echo &#34;Some important message&#34; &gt; message.txt</code>
Now, at a later point in time, we&#39;ll want to make sure of this messages integrity. Thus, let&#39;s get the hash of the file as well:</p>

<p><code>sha256sum message.txt</code></p>

<pre><code>31d1104978e7f73a0da6375f1b0d9add90bf96fbc5ef4dc9fb16804697ef2894  message.txt
</code></pre>

<p>The process of digitally signing messages includes hashing the content and then encrypting this hash with the private key. If one trusts my public key belongs to me, they will be able to verify that this message belongs to me and has not been tampered with.</p>

<h3 id="signing-a-message">Signing a message</h3>

<p><code>gpg --sign message.txt</code> will produce a <code>message.txt.gpg</code>. The message is compressed then signed, this signature file is in binary format and includes the message signed.</p>

<p>The signature can be verified with <code>gpg --verify message.txt.gpg</code></p>

<h3 id="clearsign">Clearsign</h3>

<p>Another way of signing a message is clearsign:</p>

<p><code>gpg --clearsign message.txt</code>
which outputs the signature in ASCII armored plaintext format, thus the <code>.asc</code> extension. This doesn&#39;t compress the message and is in human readable format.</p>

<pre><code class="language-message.txt.asc">-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

S1ome important message
-----BEGIN PGP SIGNATURE-----

iHUEARYKAB0WIQRBrsRfnEkrg1+zF5+Om9gJHQccpwUCZsL1FgAKCRCOm9gJHQcc
p1AXAQCgkI3FykZdG1S1+X5lejmjMRFCuEkKVniMKNXZIFZjLgD/S/WrpuLA2Q0t
D17oNhH13r5v5c9j0lpfMfhrEJS8awc=
=G5hr
-----END PGP SIGNATURE-----
</code></pre>

<h3 id="detached-signatures">Detached signatures</h3>

<p>The previous 2 signatures include the actual message within the signature. There is this 3rd method where the signature does not include the messsage, meaning you would need the actual message content as well in order to verify the message. This is created with:</p>

<p><code>gpg --detach-sign message.txt</code> which outputs <code>message.txt.sig</code>.
Now, with <code>message.txt</code> and <code>message.txt.sig</code> at hand, the signature can be verified: <code>gpg --verify message.txt.sig message.txt</code></p>

<pre><code>gpg: Signature made Mon 19 Aug 2024 10:00:40 AM +03
gpg:                using EDDSA key 41AEC45F9C492B835FB3179F8E9BD8091D071CA7
gpg: Good signature from &#34;Teoman Yuksel &lt;root@teoman.sh&gt;&#34; [ultimate]
</code></pre>

<p>Try to change the content of <code>message.txt</code> and then verify the signature.</p>

<pre><code>gpg: Signature made Mon 19 Aug 2024 10:00:40 AM +03
gpg:                using EDDSA key 41AEC45F9C492B835FB3179F8E9BD8091D071CA7
gpg: BAD signature from &#34;Teoman Yuksel &lt;root@teoman.sh&gt;&#34; [ultimate]
</code></pre>

<p><code>gpg</code> will no longer verify the signature.</p>

<h3 id="conclusion">Conclusion</h3>

<p><code>gpg</code> is a great tool utilizing PKI in the real world making possible secure communication that is still used by masses today.</p>
]]></content:encoded>
      <guid>http://teoman.sh/gpg-and-digital-signatures</guid>
      <pubDate>Mon, 19 Aug 2024 15:36:26 +0000</pubDate>
    </item>
  </channel>
</rss>