<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Nicolas Martyanoff – Brain dump</title>
    <description>Brain dump</description>
    <language>en-us</language>
    <managingEditor>nicolas@n16f.net (Nicolas Martyanoff)</managingEditor>
    <webMaster>nicolas@n16f.net (Nicolas Martyanoff)</webMaster>
    <link>https://www.n16f.net/tags/gpg/index.xml</link>
    <atom:link href="https://www.n16f.net/tags/gpg/index.xml" rel="self" type="application/rss+xml" />
    <lastBuildDate>Sun, 26 Jun 2022 00:00:00 +0000</lastBuildDate>

    
    <item xml:base="https://www.n16f.net/blog/exporting-1password-data-for-backup/">
      <title>Exporting 1Password data for backup</title>
      <link>https://www.n16f.net/blog/exporting-1password-data-for-backup/</link>
      <pubDate>Sun, 26 Jun 2022 18:00:00 +0000</pubDate>
      <guid isPermaLink="true">https://www.n16f.net/blog/exporting-1password-data-for-backup/</guid>
      <author>nicolas@n16f.net (Nicolas Martyanoff)</author>

      <description>&lt;p&gt;Storing credentials and confidential data in a secure location is important,
and I have been happy with &lt;a href=&#34;https://1password.com&#34;&gt;1Password&lt;/a&gt; for years.&lt;/p&gt;
&lt;p&gt;But having all this critical information stored in a single location is
dangerous; losing access to my 1Password account would be quite annoying,
forcing me to reinitialize passwords on dozens of websites and making me lose
a lot of information.&lt;/p&gt;
&lt;p&gt;Fortunately it is possible to export all data from 1Password. It does not seem
to be doable directly from their web interface, but their &lt;a href=&#34;https://1password.com/downloads/command-line/&#34;&gt;command-line
tool&lt;/a&gt; supports it.&lt;/p&gt;
&lt;p&gt;You will need first to connect your account. For example for a personal
account:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;op account add --address my.1password.com --email YOUR_EMAIL_ADDRESS
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that you will not stay signed-in, and will have to re-enter your password
later using: &lt;code&gt;eval $(op signin)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;There is no command to directly export all entries, but it can be done with a
small script. If you are not familiar with GPG, feel free to refer to my
&lt;a href=&#34;https://www.n16f.net/blog/using-gnupg/&#34;&gt;GnuPG introduction&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-sh&#34;&gt;#!/bin/sh

set -eu
set -o pipefail

# Configuration
gpg_key_id=&amp;quot;YOUR_GPG_KEY_ID&amp;quot;

# Command line
if [ $# -lt 1 ]; then
    echo &amp;quot;usage: $0 &amp;lt;output-file&amp;gt;&amp;quot; &amp;gt;&amp;amp;2
    exit 1
fi

output_file=$1

# Keep permissions tight
umask 177

# Sign in to the 1Password account
eval $(op signin)

# Create a temporary file to store the list of item ids (this list does not
# contain any confidential data).
item_file=$(mktemp)
trap &amp;quot;rm -f $item_file&amp;quot; EXIT

# Export a list containing the identifier and vault identifier of each item
op --format json item list | jq -r &#39;.[] | .id + &amp;quot; &amp;quot; + .vault.id&#39; &amp;gt;$item_file

# Export all items, encrypt all data and store them in the output file
while read item_id vault_id; do
    op --format json item get $item_id --vault $vault_id
done &amp;lt; $item_file | gpg --encrypt --sign --recipient $gpg_key_id &amp;gt;|$output
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The resulting file can then be stored anywhere, without any specific
protection since it is encrypted.&lt;/p&gt;
</description>

      
      <category>onepassword</category>
      
      <category>gpg</category>
      
    </item>
    
    <item xml:base="https://www.n16f.net/blog/using-gnupg/">
      <title>Using GnuPG</title>
      <link>https://www.n16f.net/blog/using-gnupg/</link>
      <pubDate>Sat, 29 Jan 2022 18:00:00 +0000</pubDate>
      <guid isPermaLink="true">https://www.n16f.net/blog/using-gnupg/</guid>
      <author>nicolas@n16f.net (Nicolas Martyanoff)</author>

      <description>&lt;p&gt;&lt;em&gt;Edit (2023-02-07)&lt;/em&gt;&lt;br&gt;
Updated to mention subkey selection during renewal.&lt;/p&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;I recently tried to learn more about GnuPG and it turned out to be more
difficult than expected. So here are my notes regarding various GnuPG
operations.&lt;/p&gt;
&lt;p&gt;GnuPG 2.2.32 was used for all commands.&lt;/p&gt;
&lt;h2 id=&#34;configuration&#34;&gt;Configuration&lt;/h2&gt;
&lt;h3 id=&#34;gnupg&#34;&gt;GnuPG&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;gpg&lt;/code&gt; command line tool looks for &lt;code&gt;$HOME/.gnupg/gpg.conf&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Options are provided using the command line arguments used by the &lt;code&gt;gpg&lt;/code&gt;
program without the &lt;code&gt;--&lt;/code&gt; prefix. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;verbose
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;causes GnuPG to behave as if the &lt;code&gt;--verbose&lt;/code&gt; option was passed to every
command.&lt;/p&gt;
&lt;p&gt;I went with the following configuration:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Do not print any greeting message
no-greeting

# Do not include comment or version numbers in signatures
no-comments
no-emit-version

# Display long key ids to minimize collision risks
keyid-format long

# Set preferences when signing and encrypting
# Use gpg --version to see available algorithms
personal-digest-preferences SHA256
personal-cipher-preferences AES256
personal-compress-preferences ZLIB

# Use AES256 as default cipher
cipher-algo AES256

# Use SHA256 as default digest
digest-algo SHA256
cert-digest-algo SHA256

# Use ZLIB as default compression algorithm
compress-algo ZLIB

# Always export in ASCII format by default
armor
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&#34;password-prompts&#34;&gt;Password prompts&lt;/h3&gt;
&lt;p&gt;GnuPG uses the pinentry collection of programs to prompt for passwords. We can
configure the GPG agent to always use the terminal version of pinentry instead
of spawning a graphical prompt.&lt;/p&gt;
&lt;p&gt;The agent is configured in &lt;code&gt;$HOME/.gnupg/gpg-agent.conf&lt;/code&gt;; to use the terminal
prompt, set the following option:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pinentry-program /usr/bin/pinentry-tty
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the agent has to be restarted after any modification:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-sh&#34;&gt;gpgconf --reload gpg-agent
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;managing-keys&#34;&gt;Managing keys&lt;/h2&gt;
&lt;h3 id=&#34;creating-a-key&#34;&gt;Creating a key&lt;/h3&gt;
&lt;p&gt;Use the &lt;code&gt;--full-gen-key&lt;/code&gt; option to create a new key. The &lt;code&gt;--gen-key&lt;/code&gt; option
can also be used but offer less control on the process.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;--expert&lt;/code&gt; option can also be used to access more advanced features such
as ECC support.&lt;/p&gt;
&lt;p&gt;The process is interactive.&lt;/p&gt;
&lt;p&gt;Once created, the new key should be visible in the list of keys which can be
visualized with &lt;code&gt;gpg --list-keys&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;using-multiple-identities&#34;&gt;Using multiple identities&lt;/h3&gt;
&lt;p&gt;A key can contain multiple identities. Edit the key with
&lt;code&gt;gpg --edit-key &amp;lt;key-id&amp;gt;&lt;/code&gt; and use the &lt;code&gt;adduid&lt;/code&gt; command to add a new identity.
You then need to trust the new identity. Use the &lt;code&gt;uid &amp;lt;n&amp;gt;&lt;/code&gt; command to select
the new uid, and run the &lt;code&gt;trust&lt;/code&gt; command to select the trust level (probably
&lt;code&gt;ultimate&lt;/code&gt; since this is your own key). Make sure to use the &lt;code&gt;primary&lt;/code&gt; command
to select the current identity as the main one. Use the &lt;code&gt;save&lt;/code&gt; command to
write the modification and exit.&lt;/p&gt;
&lt;p&gt;Note that modifying the list of identities changes the public key. If you
published it, you will need to update it.&lt;/p&gt;
&lt;h3 id=&#34;deleting-a-key&#34;&gt;Deleting a key&lt;/h3&gt;
&lt;p&gt;Keys can be deleted using &lt;code&gt;gpg --delete-secret-keys &amp;lt;key-id&amp;gt;&lt;/code&gt; and &lt;code&gt;gpg --delete-keys &amp;lt;key-id&amp;gt;&lt;/code&gt;. Note that the secret key must be deleted before the
associated public key.&lt;/p&gt;
&lt;h3 id=&#34;using-subkeys&#34;&gt;Using subkeys&lt;/h3&gt;
&lt;p&gt;Newly created keys contain a public key, a secret key which can be used for
signing and certifying other signatures, and a secret subkey which can be used
for encryption.&lt;/p&gt;
&lt;p&gt;It is a good idea to store the signing secret key in a safe location and to
generate new signing subkeys for each device which will need to sign content.
This way, if a device is compromised, one can revoke the associated signing
subkey and generate a new one without compromising the primary identity which
is guaranteed by the primary signing key.&lt;/p&gt;
&lt;p&gt;To create a new subkey, edit the key with &lt;code&gt;gpg --edit-key &amp;lt;keyid&amp;gt;&lt;/code&gt; and use the
&lt;code&gt;addkey&lt;/code&gt; command. Again, the &lt;code&gt;--expert&lt;/code&gt; option can be passed to the
&lt;code&gt;--edit-key&lt;/code&gt; command to be able to create ECC keys. The &lt;code&gt;addkey&lt;/code&gt; command will
ask for a kind of key; to create a signing sub key, opt to &amp;ldquo;set your own
capabilities&amp;rdquo;, and select the &lt;code&gt;sign&lt;/code&gt; and &lt;code&gt;authenticate&lt;/code&gt; capabilities. Use the
&lt;code&gt;save&lt;/code&gt; command to write the modification and exit.&lt;/p&gt;
&lt;p&gt;At this point, it is possible to export both the new signing subkey and the
encryption subkey and import then on the new device. Take care too use the &lt;code&gt;!&lt;/code&gt;
suffix to only export these subkeys, as described in the next section. For
example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-sh&#34;&gt;gpg --export-secret-keys &amp;lt;signing-subkey-id&amp;gt;! &amp;lt;encryption-subkey-id&amp;gt;!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you want to remove the primary secret key from the local GnuPG directory,
first obtain its keygrip using &lt;code&gt;gpg --with-keygrip --list-secret-keys&lt;/code&gt;, then
delete the key stored in &lt;code&gt;$HOME/.gnupg/private-keys-v1.d/&amp;lt;keygrip&amp;gt;.key&lt;/code&gt;. You
can check that the primary secret key is not here anymore: when listing secret
keys, the deleted key type will have the &lt;code&gt;#&lt;/code&gt; suffix, e.g. &lt;code&gt;sec#&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;exporting-keys&#34;&gt;Exporting keys&lt;/h3&gt;
&lt;p&gt;The most obvious way to share public keys is to export them from the local
keyring. The keyring is stored in &lt;code&gt;$HOME/.gnupg/pubring.kbx&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;gpg --export &amp;lt;user-id&amp;gt;&lt;/code&gt; command outputs one or more public keys
associated with a user id. Note that there are multiple way to select a user
id. See the &lt;a href=&#34;https://www.gnupg.org/documentation/manuals/gnupg/Specify-a-User-ID.html&#34;&gt;official
documentation&lt;/a&gt;
for more information.&lt;/p&gt;
&lt;p&gt;Using the key id or the email address is the simplest way to select the public
key.&lt;/p&gt;
&lt;p&gt;Secret key exports works the same way but use the &lt;code&gt;--export-secret-key&lt;/code&gt;
command. Note that exporting a subkey will by default export the entire secret
key. Add a &lt;code&gt;!&lt;/code&gt; suffix to the key id to export a single subkey.&lt;/p&gt;
&lt;p&gt;When backing up keys, use &lt;code&gt;--export-options backup&lt;/code&gt; to include all necessary
data for later restoration.&lt;/p&gt;
&lt;h3 id=&#34;publishing-a-key&#34;&gt;Publishing a key&lt;/h3&gt;
&lt;p&gt;Public keys can be published on internet servers to make it easier for other
people to download them.&lt;/p&gt;
&lt;p&gt;Note that the presence of a key on a public server does not imply it actually
belong to the person identified by the key: anyone can generate keys using any
name or email address.&lt;/p&gt;
&lt;p&gt;Also remember that published keys can never be deleted.&lt;/p&gt;
&lt;p&gt;To publish a key, simply use &lt;code&gt;gpg --keyserver &amp;lt;address&amp;gt; --send-keys &amp;lt;key-id&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;importing-a-key&#34;&gt;Importing a key&lt;/h3&gt;
&lt;p&gt;Public and private keys can be imported in the local keyring, making them
available for verification or decryption. Simply &lt;code&gt;gpg --import &amp;lt;file&amp;gt;&lt;/code&gt;. It is
also possible to pipe the public key directly into &lt;code&gt;gpg --import&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;revoking-a-key&#34;&gt;Revoking a key&lt;/h3&gt;
&lt;p&gt;Compromised keys must be revoked to signal that someone other than the owner
of the key has access to it.&lt;/p&gt;
&lt;p&gt;Revocation uses a revocation certificate which is generated from the private
key using &lt;code&gt;gpg --gen-revoke &amp;lt;key-id&amp;gt;&lt;/code&gt;. The command is interactive and asks for
the reason of the revocation.&lt;/p&gt;
&lt;p&gt;The revocation certificate can then be imported or published like any other
public key. After importing a revocation certificate in a keyring, the key
will be marked as revoked.&lt;/p&gt;
&lt;h3 id=&#34;renewing-a-key&#34;&gt;Renewing a key&lt;/h3&gt;
&lt;p&gt;If a key has an expiration date, it may need to be renewed. This can be done
by editing the key. Start the edition shell using &lt;code&gt;gpg --edit-key &amp;lt;key-id&amp;gt;&lt;/code&gt;,
and select the subkey you want to modify using the &lt;code&gt;key &amp;lt;index&amp;gt;&lt;/code&gt; command. Then
run the &lt;code&gt;expire&lt;/code&gt; interactive command. You can then write the modification and
exit with &lt;code&gt;save&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Do not forget to backup the new version of the private key and to publish the
new version of the public key.&lt;/p&gt;
&lt;p&gt;Note that you should generate and backup a new revocation certificate.&lt;/p&gt;
&lt;h2 id=&#34;using-keys&#34;&gt;Using keys&lt;/h2&gt;
&lt;h3 id=&#34;encrypting-a-file&#34;&gt;Encrypting a file&lt;/h3&gt;
&lt;p&gt;Data are encrypted using &lt;code&gt;gpg --encrypt --recipient &amp;lt;key-id&amp;gt;&lt;/code&gt;, and decrypted
using &lt;code&gt;gpg --decrypt&lt;/code&gt;. Encrypted messages contain the key id; decrypting the
file requires the presence of the associated secret key in the local GnuPG
directory.&lt;/p&gt;
&lt;h3 id=&#34;signing-a-file&#34;&gt;Signing a file&lt;/h3&gt;
&lt;p&gt;Data are signed using &lt;code&gt;gpg --sign &amp;lt;file&amp;gt;&lt;/code&gt;. The output contains both the data
and the signature.&lt;/p&gt;
&lt;p&gt;Signed data are verified using &lt;code&gt;gpg --verify&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It is also possible to generate a separate — or detached — signature using
&lt;code&gt;gpg --detach-sig&lt;/code&gt;, e.g.:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-sh&#34;&gt;gpg --output my-file.asc --detach-sig my-file
gpg --verify my-file.asc my-file
&lt;/code&gt;&lt;/pre&gt;
</description>

      
      <category>gpg</category>
      
    </item>
    
  </channel>
</rss>
