Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
nitrokey:arch:3a [15.12.2024 21:22. ] – [Nitrokey Start und Thunderbird] djangonitrokey:arch:3a [16.12.2024 20:52. ] (aktuell) django
Zeile 230: Zeile 230:
 Authentication key: [none] Authentication key: [none]
 General key info..: [none]</code> General key info..: [none]</code>
 +
 +==== nitropy ====
 +FIXME 
 +
 +
 +
 +
 +   # pacman -S python-pynitrokey
 +
 +
 +   # nitropy --help
 +<code>Usage: nitropy [OPTIONS] COMMAND [ARGS]...
 +
 +Options:
 +  -h, --help  Show this message and exit.
 +
 +Commands:
 +  fido2    Interact with Nitrokey FIDO2 devices, see subcommands.
 +  list     List Nitrokey devices (in firmware or bootloader mode)
 +  nethsm   Interact with NetHSM devices, see subcommands.
 +  nk3      Interact with Nitrokey 3 devices, see subcommands.
 +  nkpk     Interact with Nitrokey Passkey devices, see subcommands.
 +  pro      Interact with Nitrokey Pro devices, see subcommands.
 +  start    Interact with Nitrokey Start devices, see subcommands.
 +  storage  Interact with Nitrokey Storage devices, see subcommands.
 +  version  Version of pynitrokey library and tool.</code>
 +
 +   # nitropy nk3 test
 +<code>Command line tool to interact with Nitrokey devices 0.6.0
 +THIS COMMAND SHOULD NOT BE RUN AS ROOT!
 +
 +Please install udev rules and run `nitropy` as regular user (without sudo).
 +We suggest using: https://raw.githubusercontent.com/Nitrokey/libnitrokey/master/data/41-nitrokey.rules
 +For more information, see: https://docs.nitrokey.com/software/nitropy/linux/udev.html
 +
 +Set ALLOW_ROOT=1 environment variable to disable this warning.
 +
 +Found 1 NK3 device(s):
 +- Nitrokey 3 at /dev/hidraw0
 +
 +Running tests for Nitrokey 3 at /dev/hidraw0
 +
 +[1/5] uuid      UUID query              SUCCESS  6447F2534D3A582D0000000000000000
 +[2/5] version  Firmware version query  SUCCESS  v1.7.2
 +[3/5] status    Device status            SUCCESS  Status(init_status=<InitStatus: 0>, ifs_blocks=241, efs_blocks=471, variant=<Variant.NRF52: 2>)
 +Running SE050 test: |                                                                                                                                                                                 
 +[4/5] se050    SE050                    SUCCESS  SE050 firmware version: 3.1.1 - 1.11, (persistent: (30140,), transient_deselect: (271,), transient_reset: (256,))
 +Please press the touch button on the device ...
 +Please press the touch button on the device ...
 +[5/5] fido2    FIDO2                    SUCCESS 
 +
 +5 tests, 5 successful, 0 skipped, 0 failed
 +
 +Summary: 1 device(s) tested, 1 successful, 0 failed</code>
 +
 +Das Protokoll im Verzeichnis **''/tmp''** von **''nitropy''** zeigt im Zweifelsfall weitere Informationen die bei der weiteren Betrachtung oder Fehlereingrenzung wertvolle Informationen liefern kann.
 +
 +   # ls -al /tmp/nitropy.log.gkod8a3k 
 +<code>-rw-r--r-- 1 root root 5795 Dec 16 21:16 /tmp/nitropy.log.gkod8a3k</code>
 +
 +   # cat /tmp/nitropy.log.gkod8a3k
 +<code>368        INFO pynitrokey.cli Timestamp: 2024-12-16 21:16:27.120247
 +368        INFO pynitrokey.cli OS: uname_result(system='Linux', node='pml010074', release='6.6.65-1-lts', version='#1 SMP PREEMPT_DYNAMIC Wed, 11 Dec 2024 15:35:54 +0000', machine='x86_64')
 +368        INFO pynitrokey.cli Python version: 3.12.7
 +369        INFO pynitrokey.cli Cli arguments: ['nk3', 'test']
 +372        INFO pynitrokey.cli pynitrokey version: 0.6.0
 +373        INFO pynitrokey.cli cryptography version: 43.0.3
 +374        INFO pynitrokey.cli ecdsa version: 0.19.0
 +374        INFO pynitrokey.cli fido2 version: 1.1.3
 +375        INFO pynitrokey.cli pyusb version: 1.2.1
 +376        INFO pynitrokey.cli.trussed.test platform: Linux-6.6.65-1-lts-x86_64-with-glibc2.40
 +376        INFO pynitrokey.cli.trussed.test uname: uname_result(system='Linux', node='pml010074', release='6.6.65-1-lts', version='#1 SMP PREEMPT_DYNAMIC Wed, 11 Dec 2024 15:35:54 +0000', machine='x86_64')
 +512       DEBUG       root print: Found 1 NK3 device(s):
 +512       DEBUG       root print: - Nitrokey 3 at /dev/hidraw0
 +512       DEBUG       root print: Running tests for Nitrokey 3 at /dev/hidraw0
 +520       DEBUG       root print: [1/5] uuid      UUID query              SUCCESS  6447F2534D3A582D0000000000000000
 +528       DEBUG       root print: [2/5] version  Firmware version query  SUCCESS  v1.7.2
 +536        INFO pynitrokey.cli.trussed.tests Device status: Status(init_status=<InitStatus: 0>, ifs_blocks=241, efs_blocks=471, variant=<Variant.NRF52: 2>)
 +536       DEBUG       root print: [3/5] status    Device status            SUCCESS  Status(init_status=<InitStatus: 0>, ifs_blocks=241, efs_blocks=471, variant=<Variant.NRF52: 2>)
 +669       DEBUG       root print: [4/5] se050    SE050                    SUCCESS  SE050 firmware version: 3.1.1 - 1.11, (persistent: (30140,), transient_deselect: (271,), transient_reset: (256,))
 +1782      DEBUG fido2.server Fido2Server initialized for RP: PublicKeyCredentialRpEntity(name='Example RP', id='example.com')
 +1782      DEBUG fido2.server Starting new registration, existing credentials: 
 +1786      DEBUG       root print: Please press the touch button on the device ...
 +1796      DEBUG fido2.client Register a new credential for RP ID: example.com
 +1838      DEBUG fido2.ctap2.base Calling CTAP2 make_credential
 +1996      DEBUG  fido2.hid Got keepalive status: 01
 +2248      DEBUG  fido2.hid Got keepalive status: 01
 +2496      DEBUG  fido2.hid Got keepalive status: 01
 +2748      DEBUG  fido2.hid Got keepalive status: 01
 +2996      DEBUG  fido2.hid Got keepalive status: 01
 +3248      DEBUG  fido2.hid Got keepalive status: 01
 +3496      DEBUG  fido2.hid Got keepalive status: 01
 +3744      DEBUG  fido2.hid Got keepalive status: 01
 +3996      DEBUG  fido2.hid Got keepalive status: 01
 +4244      DEBUG  fido2.hid Got keepalive status: 02
 +4496      DEBUG  fido2.hid Got keepalive status: 01
 +4744      DEBUG  fido2.hid Got keepalive status: 01
 +4996      DEBUG  fido2.hid Got keepalive status: 01
 +5244      DEBUG  fido2.hid Got keepalive status: 01
 +5492      DEBUG  fido2.hid Got keepalive status: 01
 +5744      DEBUG  fido2.hid Got keepalive status: 01
 +5992      DEBUG  fido2.hid Got keepalive status: 01
 +6244      DEBUG  fido2.hid Got keepalive status: 01
 +6492      DEBUG  fido2.hid Got keepalive status: 01
 +6740      DEBUG  fido2.hid Got keepalive status: 01
 +6992      DEBUG  fido2.hid Got keepalive status: 01
 +7240      DEBUG  fido2.hid Got keepalive status: 01
 +7492      DEBUG  fido2.hid Got keepalive status: 01
 +7740      DEBUG  fido2.hid Got keepalive status: 01
 +7992      DEBUG  fido2.hid Got keepalive status: 01
 +8256      DEBUG  fido2.hid Got keepalive status: 01
 +8512      DEBUG  fido2.hid Got keepalive status: 01
 +8796      DEBUG  fido2.hid Got keepalive status: 01
 +9056      DEBUG  fido2.hid Got keepalive status: 01
 +9199      DEBUG fido2.server Verifying attestation of type packed
 +9200       INFO fido2.server New credential registered: a3005878bd496f7f5e7c10b12264abdc7274b8a2a8a1724eab6a6b2cf29737921dfb1c4793c1b3645547b7287ca5cd6087b3cd0c06e03c9115de4aeba206f2cfc14da879c4cf8c2045165008c9b3aa4591cee5b2cb825ee6c86f4ebe2f6bc8c4769902a550d389e11b235485931334234f15bf64de04d075aa27d394014c680a5adb95a30d02ed6d9e7f02505d85c63ba65a973e074ce94856cbb2a0
 +9201      DEBUG fido2.server Starting new authentication, for credentials: a3005878bd496f7f5e7c10b12264abdc7274b8a2a8a1724eab6a6b2cf29737921dfb1c4793c1b3645547b7287ca5cd6087b3cd0c06e03c9115de4aeba206f2cfc14da879c4cf8c2045165008c9b3aa4591cee5b2cb825ee6c86f4ebe2f6bc8c4769902a550d389e11b235485931334234f15bf64de04d075aa27d394014c680a5adb95a30d02ed6d9e7f02505d85c63ba65a973e074ce94856cbb2a0
 +9202      DEBUG       root print: Please press the touch button on the device ...
 +9206      DEBUG fido2.client Assert a credential for RP ID: example.com
 +9237      DEBUG fido2.ctap2.base Calling CTAP2 get_assertion
 +9304      DEBUG  fido2.hid Got keepalive status: 02
 +9552      DEBUG  fido2.hid Got keepalive status: 01
 +9804      DEBUG  fido2.hid Got keepalive status: 01
 +10052     DEBUG  fido2.hid Got keepalive status: 01
 +10328     DEBUG  fido2.hid Got keepalive status: 01
 +10588     DEBUG  fido2.hid Got keepalive status: 01
 +10755      INFO fido2.server Credential authenticated: a3005878bd496f7f5e7c10b12264abdc7274b8a2a8a1724eab6a6b2cf29737921dfb1c4793c1b3645547b7287ca5cd6087b3cd0c06e03c9115de4aeba206f2cfc14da879c4cf8c2045165008c9b3aa4591cee5b2cb825ee6c86f4ebe2f6bc8c4769902a550d389e11b235485931334234f15bf64de04d075aa27d394014c680a5adb95a30d02ed6d9e7f02505d85c63ba65a973e074ce94856cbb2a0
 +10755     DEBUG       root print: [5/5] fido2    FIDO2                    SUCCESS
 +10756     DEBUG       root print: 5 tests, 5 successful, 0 skipped, 0 failed
 +10756     DEBUG       root print: Summary: 1 device(s) tested, 1 successful, 0 failed</code>
 +
 +==== webauthn.io ====
 +
 +Was ist WebAuthn?
 +
 +Willkommen auf webauthn.io! Diese Website wurde von Duo Labs entwickelt, um WebAuthn und Passkeys zu testen. WebAuthn wird von allen gängigen Browsern, einschließlich Chrome, Safari und Firefox, sowie von allen modernen Betriebssystemen, einschließlich Android, iOS, macOS und Windows, unterstützt.
 +
 +Eine Einführung in WebAuthn und seine Funktionen finden Sie unter webauthn.guide. Wenn Sie Ihre Website um WebAuthn-Unterstützung erweitern möchten, sind Sie bei passkeys.dev richtig. Der Code für diese Demo ist auf GitHub verfügbar.
 +
 +https://webauthn.guide/
 +
 +https://webauthn.io/
 +
 +
  
 ===== Anwendungsfälle - Software ===== ===== Anwendungsfälle - Software =====
Zeile 1327: Zeile 1471:
 Auf RSA Schlüssel muss man aber nicht mehr zwingend zurückgreifen, stehen doch aktuellere und zeitgemässere Cipher, MACs, Schlüssel Typen und Key Exchange Algorithmen zur Verfügung. Als Alternative zu einem RSA-Keys haben wir uns bereits im Abschnitt **[[#ed25519-schluessel_generieren|Nitrokey A3 Mini und GnuPG - ED25519-Schlüssel generieren]]** Schlüsselmaterial auf Basis elliptischer Kurven erstellt, unter anderem auch einen //**Authentication Key**// erstellt.  Auf RSA Schlüssel muss man aber nicht mehr zwingend zurückgreifen, stehen doch aktuellere und zeitgemässere Cipher, MACs, Schlüssel Typen und Key Exchange Algorithmen zur Verfügung. Als Alternative zu einem RSA-Keys haben wir uns bereits im Abschnitt **[[#ed25519-schluessel_generieren|Nitrokey A3 Mini und GnuPG - ED25519-Schlüssel generieren]]** Schlüsselmaterial auf Basis elliptischer Kurven erstellt, unter anderem auch einen //**Authentication Key**// erstellt. 
 Diesen Schlüssel wollen wir nun auch zur Serveradministration verwenden. Diesen Schlüssel wollen wir nun auch zur Serveradministration verwenden.
 +
 +=== SSH Client vorbereiten ===
 +Damit wir beim Verbindungsaufbau auf den Authentication Key zugreifen können, müssen wir unseren Client entsprechend vorbereiten.
 +
 +In der Konfigurationsdatei //**~/.gnupg/gpg.conf**// setzen wir als erstes die Option ''**use-agent**''.
 +   $ vim ~/.gnupg/gpg.conf
 +<file bash ~/.gnupg/gpg.conf># File re-created by pEp
 +# See backup in '/home/django/.gnupg/gpg.conf.1.pep.bkp'
 + 
 +# File re-created by pEp
 +# See backup in '/home/django/.gnupg/gpg.conf.0.pep.bkp'
 + 
 +# Created by pEpEngine
 +keyserver hkp://keys.gnupg.net
 +cert-digest-algo SHA256
 +no-emit-version 
 +no-comments 
 +personal-cipher-preferences AES AES256 AES192 CAST5
 +personal-digest-preferences SHA256 SHA512 SHA384 SHA224
 +ignore-time-conflict 
 +allow-freeform-uid
 + 
 +# Ansible generated, do not edit manual!
 +# Option use-agent für Authentication Key Nutzung des Nitrokey Start bei SSH
 +use-agent
 +</file>
 +
 +
 +Im nächsten Schritt aktivieren wir die Option ''**enable-ssh-support**'' in der Konfigurationsdatei //**~/.gnupg/gpg-agent.conf
 +**// des GPG-Agenten.
 +   $ vim ~/.gnupg/gpg-agent.conf
 +<file bash ~/.gnupg/gpg-agent.conf># File re-created by pEp                                                                                                                                                                              
 +# See backup in '/home/django/.gnupg/gpg-agent.conf.1.pep.bkp'
 + 
 +# File re-created by pEp
 +# See backup in '/home/django/.gnupg/gpg-agent.conf.0.pep.bkp'
 + 
 +default-cache-ttl 300
 +max-cache-ttl 999999
 + 
 +# Ansible generated, do not edit manual!
 +# SSH-Support activated for gnupg-agent
 +enable-ssh-support
 +</file>
 +
 +Nun werden wir noch die Datei //**~/.bashrc**// erweitern, damit der **SSH_AUTH_SOCK** für den Zugriff des SSH-Schlüssels auf dem Nitrokey Start genutzt werden kann.
 +   $ vim ~/.bashrc
 +<file bash ~/.bashrc># .bashrc
 +
 +# Source global definitions
 +if [ -f /etc/bashrc ]; then
 +        . /etc/bashrc
 +fi
 +
 +# User specific environment
 +PATH="$HOME/.local/bin:$HOME/bin:$PATH"
 +export PATH
 +
 +# Uncomment the following line if you don't like systemctl's auto-paging feature:
 +# export SYSTEMD_PAGER=
 +
 +# User specific aliases and functions
 +
 +# Django : 2024-05-25
 +#          Definition des SSH_AUTH_SOCK für den Zugriff des SSH-Schlüssels auf dem Nitrokey Start
 +unset SSH_AGENT_PID
 +        if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
 +        export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
 +fi</file>
 +
 +Damit unsere Änderungen aktiv werden, müssen wir nun zum Schluss noch den **pgp-agent** restarten bzw. einen Neustart des Clients erwirken. Wir entscheiden uns der Einfachheit halber von einen Neustart des Agenten mit Hilfe des Befehls ''**pkill gpg-agent**''.
 +   $ pkill gpg-agent
 +
 +Ein Blick in die Prozessliste zeigt, dass der Agent nicht mehr läuft.
 +   $ ps aux | grep gpg-agent
 +
 +  django    8752  0.0  0.0 215740   820 pts/1    S+   21:56   0:00 grep --color=auto gpg-agent
 +
 +Nun stecken wir unseren Nitrokey Start an den USB-Port und fragen den Kartenstatus ab.
 +   $ gpg2 --card-status
 +<code>Reader ...........: 20A0:42B2:X:0
 +Application ID ...: D276000124010304000F6447F2530000
 +Application type .: OpenPGP
 +Version ..........: 3.4
 +Manufacturer .....: Nitrokey
 +Serial number ....: 6447F253
 +Name of cardholder: Michael Nausch
 +Language prefs ...: de
 +Salutation .......: Mr.
 +URL of public key : https://keys.openpgp.org/search?q=get&search=0x0A56C9A3A69FE291
 +Login data .......: django
 +Signature PIN ....: forced
 +Key attributes ...: ed25519 cv25519 ed25519
 +Max. PIN lengths .: 127 127 127
 +PIN retry counter : 3 0 3
 +Signature counter : 10
 +KDF setting ......: off
 +UIF setting ......: Sign=off Decrypt=off Auth=off
 +Signature key ....: F5F0 CD13 074B A693 D950  F92A 0A56 C9A3 A69F E291
 +      created ....: 2024-12-15 17:08:38
 +Encryption key....: DBBD 5355 D9D0 334A A3FA  751F A89D D54D AE0E 394A
 +      created ....: 2024-12-15 17:08:38
 +Authentication key: EE7C 3807 4F0A 8F2A 5601  BF91 1E61 4A9A 36D4 DF53
 +      created ....: 2024-12-15 17:08:38
 +General key info..: pub  ed25519/0A56C9A3A69FE291 2024-12-15 Michael Nausch <michael@nausch.org>
 +sec>  ed25519/0A56C9A3A69FE291  created: 2024-12-15  expires: never     
 +                                card-no: 000F 6447F253
 +ssb>  ed25519/1E614A9A36D4DF53  created: 2024-12-15  expires: never     
 +                                card-no: 000F 6447F253
 +ssb>  cv25519/A89DD54DAE0E394A  created: 2024-12-15  expires: never     
 +                                card-no: 000F 6447F253</code>
 +
 +Ein erneuter Blick in die Prozessliste zeigt nun den neu gestarteten Agenten.
 +   $ ps aux | grep gpg-agent
 +
 +  django      1428  0.0  0.0 228968  4068 ?        SLsl 19:52   0:00 /usr/bin/gpg-agent --supervised
 +  django      5787  0.0  0.0   6392  2300 pts/0    S+   20:32   0:00 grep --color=auto gpg-agent 
 +
 +=== Public-Key des ED25519 SSH exportieren ===
 +Für den Zugriff auf unser Ziel-System mit Hilfe der SSH benötigen wir noch den öffentlichen Schlüssel unseres Authentication Keys, den wir nun exportieren werden.
 +Zunächst besorgen wir uns die betreffende Schlüsselkennung des Authentication Keys, genauer gesagt die 4 letzten Zahlenreihen des nachfolgenden Aufrufs.
 +   $ gpg2 --card-status | grep Authentication\ key
 +
 +  Authentication key: EE7C 3807 4F0A 8F2A 5601  BF91 1E61 4A9A 36D4 DF53
 +In diesem Konfigurationsbeispiel ist die Schlüssel-ID des Autentication Keys also die Nummer ''**1E614A9A36D4DF53**''.
 +
 +Nun exportieren wir den öffentlichen Schlüssel und schreiben diesen in eine separate Datei.
 +   $ gpg2 --export-ssh-key 1E614A9A36D4DF53 >> ~/.ssh/1E614A9A36D4DF53.pub
 +
 +Der Öffentliche Schlüssel in diesen Konfigurationsbeispiel lautet also:
 +   $ cat ~/.ssh/1E614A9A36D4DF53.pub
 +
 +  ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILz8sjaPGlC16rOK7s8S8gzBmbfnCOsiz4jD77+BuLn4 openpgp:0x36D4DF53
 +
 +Diesen Schlüssel kopieren wir nun auf das entsprechende Zielsystem an Ort und Stelle ''**~/.ssh/authorized_keys**''.
 +   $ scp ~/.ssh/1E614A9A36D4DF53.pub zielhost.dmz.nausch.org: && ssh zielhost.dmz.nausch.org 'cat authorized_keys >> ~/.ssh/authorized_keys'
 +
 +=== SSH-Verbindung aufbauen ===
 +Nun können wir wie gewohnt eine Verbindung zu unserem entfernten System aufbauen, sofern der GPG-Agent am laufen ist. Wir können dazu entweder erst einmal abfragen, ob dieser gestartet wurde, mit Hilfe des folgenden Aufrufs:
 +   $ ps -aux | grep gpg-agent
 +
 +  django      1430  0.0  0.0 376092  3636 ?        SLsl 20:32   0:00 /usr/bin/gpg-agent --supervised
 +
 +Oder wir fragen einfach den Karten-Status ab, was unweigerlich den Neustart des GPG-Agenten nach sich zieht.
 +   $ gpg2 --card-status
 +
 +Nun können wir die gewünschte Verbindung zum Zielsystem aufbauen.
 +   $ ssh zielhost.dmz.nausch.org
 +
 +Da der SSH-Key zur Authentication nicht im Dateisystem liegt, sondern auf der SmartCard des Nitrokey werden wir nun nach der User-PIN gefragt, damit auf den privaten Schlüssel der Karte zugegriffen werden kann.
 +
 +{{ :nitrokey:arch:ssh_001.png?nolink&280 |Bild: PIN Abfrage beim Zugriff auf den Authentication Key der SmartCard des Nitrokeys}}
 +
 +Der entsperrte Schlüssel der SmartCard des Nitrokey Start wird nun im Speicher gehalten solange wir den USB-Hardwareschlüssel nicht abziehen. 
 +
 +<WRAP center round important 90%>
 +**WICHTIG:** \\
 +Da wir den Schlüssel **__nicht__** aus einer Datei geladen hatten, können wir diese auch nicht mit Hilfe von ''**ssh-add**'' wieder entladen! Wollen wir verhindern, dass auf den im Speicher vorgehaltenen Schlüssel zugegriffen wird, müssen wir manuell den GPG-Agenten beenden.
 +   $ pkill gpg-agent
 +
 +</WRAP>
 +
 +Anschliessend lassen sich Verbindungen zu unseren Remote-Systemen erst wieder aufbauen, wenn der GPG-Agent geladen und die Karte nach Eingabe der PIN entsperrt wurde!
  
  • nitrokey/arch/3a.1734297724.txt.gz
  • Zuletzt geändert: 15.12.2024 21:22.
  • von django