Outils pour utilisateurs

Outils du site


tech:notes_hsm

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
tech:notes_hsm [2025/03/24 15:06] – créée - modification externe 127.0.0.1tech:notes_hsm [2025/04/14 15:05] (Version actuelle) Jean-Baptiste
Ligne 1: Ligne 1:
-{{tag>Brouillon}}+<!DOCTYPE markdown> 
 +{{tag>Brouillon Crypt Sécurité Matériel}}
  
-Notes HSM+Notes HSM
  
 Todo :  Todo : 
Ligne 38: Ligne 39:
  
  
-<code bash>+~~~bash
 hsmwiz hsmwiz
 pkcs15-tool --dump pkcs15-tool --dump
Ligne 45: Ligne 46:
 # Si KO faire : # Si KO faire :
 hsmwiz explorer hsmwiz explorer
-</code>+~~~
  
  
 The DKEK must be set during initialization and before any other keys are generated. For a device initialized without a DKEK, keys can never be exported. The DKEK must be set during initialization and before any other keys are generated. For a device initialized without a DKEK, keys can never be exported.
  
-<code bash>+~~~bash
 #set +o history #set +o history
 export HISTCONTROL = ignorespace export HISTCONTROL = ignorespace
  pkcs11-tool --module /usr/local/lib/opensc-pkcs11.so --login --login-type so --so-pin 3537363231383830 --change-pin --new-pin 0123456789012345  pkcs11-tool --module /usr/local/lib/opensc-pkcs11.so --login --login-type so --so-pin 3537363231383830 --change-pin --new-pin 0123456789012345
-</code>+~~~
  
-<code bash>+~~~bash
 #set +o history #set +o history
 export HISTCONTROL = ignorespace export HISTCONTROL = ignorespace
  sc-hsm-tool --initialize --so-pin 3537363231383830 --pin 648219 --label "Nitrokey"  sc-hsm-tool --initialize --so-pin 3537363231383830 --pin 648219 --label "Nitrokey"
-</code>+~~~
  
-<code bash>+~~~bash
 sc-hsm-tool --create-dkek-share dkek-share-1.pbe --pwd-shares-threshold 3 --pwd-shares-total 5 sc-hsm-tool --create-dkek-share dkek-share-1.pbe --pwd-shares-threshold 3 --pwd-shares-total 5
-</code>+~~~
  
 Encrypting Files Encrypting Files
Ligne 74: Ligne 75:
  
  
-== Notes+## Notes
  
-=== pkcs15-init+### pkcs15-init
  
 Please note, that the SmartCard-HSM is not compatible with the pkcs15-init command. In particular it does not support pkcs15-init to import a key from PKCS#12 files. Doing so will just create certificate objects and the private key metadata, but no key. Please use the Smart Card Shell to import keys and certificates from PKCS#12 files. Please note, that the SmartCard-HSM is not compatible with the pkcs15-init command. In particular it does not support pkcs15-init to import a key from PKCS#12 files. Doing so will just create certificate objects and the private key metadata, but no key. Please use the Smart Card Shell to import keys and certificates from PKCS#12 files.
Ligne 85: Ligne 86:
 * https://docs.nitrokey.com/hsm/linux/smime.html * https://docs.nitrokey.com/hsm/linux/smime.html
  
-== Initialisation / Réinitialiseation (Reset)+## Initialisation / Réinitialiseation (Reset)
  
 Voir DKEK : Device Key Encryption Key Voir DKEK : Device Key Encryption Key
  
-<code bash>+~~~bash
 sc-hsm-tool --initialize --so-pin 3537363231383830 --pin 648219 --dkek-shares 1 sc-hsm-tool --initialize --so-pin 3537363231383830 --pin 648219 --dkek-shares 1
  
 # Ou # Ou
 sc-hsm-tool --initialize --so-pin 3537363231383830 --pin 648219 --dkek-shares 2 sc-hsm-tool --initialize --so-pin 3537363231383830 --pin 648219 --dkek-shares 2
-</code>+~~~
  
 Test Test
-<code bash>+~~~bash
 pkcs11-tool --test --login --pin 648219 pkcs11-tool --test --login --pin 648219
-</code>+~~~
  
  
-<code bash>+~~~bash
 #set +o history #set +o history
 export HISTCONTROL = ignorespace export HISTCONTROL = ignorespace
  hsmwiz format --so-pin 3537363231383830  hsmwiz format --so-pin 3537363231383830
-</code>+~~~
  
 Ou  Ou 
-<code bash>+~~~bash
  pkcs11-tool --init-token --init-pin --so-pin=3537363231383830 --label="test" --pin=648219  pkcs11-tool --init-token --init-pin --so-pin=3537363231383830 --label="test" --pin=648219
-</code>+~~~
  
  
  
-== Changer PIN +## Changer PIN 
  
 Changer PIN / Débloquer carte Changer PIN / Débloquer carte
-<code bash>+~~~bash
 #set +o history #set +o history
 export HISTCONTROL = ignorespace export HISTCONTROL = ignorespace
  pkcs11-tool --login --login-type so --so-pin=3537363231383830 --init-pin --new-pin=648219  pkcs11-tool --login --login-type so --so-pin=3537363231383830 --init-pin --new-pin=648219
-</code>+~~~
  
-== Génération d'une clef privée sur puce+## Génération d'une clef privée sur puce
  
-<code bash>+~~~bash
 #set +o history #set +o history
 export HISTCONTROL = ignorespace export HISTCONTROL = ignorespace
  pkcs11-tool --pin=648219 --keypairgen --key-type rsa:4096 --label "Nom_Clef"  pkcs11-tool --pin=648219 --keypairgen --key-type rsa:4096 --label "Nom_Clef"
-</code>+~~~
  
-<code bash>+~~~bash
 pkcs11-tool -l --keypairgen --key-type EC:secp521r1 --label root pkcs11-tool -l --keypairgen --key-type EC:secp521r1 --label root
-</code>+~~~
  
-== Importer une clef privée existante+## Importer une clef privée existante
  
 TODO TODO
  
  
-== Exporter une clef publique+## Exporter une clef publique
  
-<code bash>+~~~bash
 pkcs15-tool -D pkcs15-tool -D
 pkcs15-tool --read-public-key 0988309300f4f26c1ff2279c09026490df89189e > publickey.pem pkcs15-tool --read-public-key 0988309300f4f26c1ff2279c09026490df89189e > publickey.pem
-</code>+~~~
  
  
-== Chiffrer avec la clef publique+## Chiffrer avec la clef publique
  
-<code bash>+~~~bash
 # Depretated but work with ECC # Depretated but work with ECC
 #openssl rsautl -inkey publickey.pem -pubin -encrypt -pkcs -in plop.txt -out plop.enc #openssl rsautl -inkey publickey.pem -pubin -encrypt -pkcs -in plop.txt -out plop.enc
Ligne 157: Ligne 158:
 # Don't work with ECC # Don't work with ECC
 openssl pkeyutl -inkey c_rsa.pub -pubin -encrypt -in plop.txt -out plop.enc openssl pkeyutl -inkey c_rsa.pub -pubin -encrypt -in plop.txt -out plop.enc
-</code>+~~~
  
-=== Pb+### Pb
  
-<code ->+~~~
 $ openssl pkeyutl -inkey c_ecc.pub -pubin -encrypt -in plop.txt -out plop.enc $ openssl pkeyutl -inkey c_ecc.pub -pubin -encrypt -in plop.txt -out plop.enc
 pkeyutl: Error initializing context pkeyutl: Error initializing context
 C0E2525D567F0000:error:03000096:digital envelope routines:evp_pkey_asym_cipher_init:operation not supported for this keytype:../crypto/evp/asymcipher.c:189: C0E2525D567F0000:error:03000096:digital envelope routines:evp_pkey_asym_cipher_init:operation not supported for this keytype:../crypto/evp/asymcipher.c:189:
-</code>+~~~
  
  
-== Déchiffrer avec la clef privée+## Déchiffrer avec la clef privée
  
-<code bash>+~~~bash
 pkcs15-tool -D pkcs15-tool -D
  
 pkcs15-crypt --decipher --key f144aec7f488e2795069256c64fa27039c1a2ed2 --input plop.enc --pkcs1 --raw > plop.txt pkcs15-crypt --decipher --key f144aec7f488e2795069256c64fa27039c1a2ed2 --input plop.enc --pkcs1 --raw > plop.txt
-</code>+~~~
  
-== Signer (RSA)+## Signer (RSA)
  
-<code bash>+~~~bash
 pkcs11-tool --sign --id f144aec7f488e2795069256c64fa27039c1a2ed2 --mechanism RSA-PKCS --input-file plop.txt --output-file plop.txt.sig pkcs11-tool --sign --id f144aec7f488e2795069256c64fa27039c1a2ed2 --mechanism RSA-PKCS --input-file plop.txt --output-file plop.txt.sig
-</code>+~~~
  
-== Vérifier la signature (RSA)+## Vérifier la signature (RSA)
  
-<code bash>+~~~bash
 pkcs11-tool --verif --input-file plop.txt --mechanism RSA-PKCS --signature-file plop.txt.sig pkcs11-tool --verif --input-file plop.txt --mechanism RSA-PKCS --signature-file plop.txt.sig
-</code>+~~~
  
  
-== Utiliser la clef privée pour se connecter en SSH+## Utiliser la clef privée pour se connecter en SSH
  
 Voir :  Voir : 
Ligne 198: Ligne 199:
  
  
-== Sauvegarder vos clefs privées en les exportant chiffrées+## Sauvegarder vos clefs privées en les exportant chiffrées
  
 Ne fonctionne que si vous avez  Ne fonctionne que si vous avez 
Ligne 205: Ligne 206:
 * Que si à l'initialisation vous avez utilisé l'option ''--dkek-shares 1'' lors de l'appel à ''sc-hsm-tool --initialize'' * Que si à l'initialisation vous avez utilisé l'option ''--dkek-shares 1'' lors de l'appel à ''sc-hsm-tool --initialize''
  
-<code bash>+~~~bash
 sc-hsm-tool --wrap-key wrap-key.bin --key-reference 1 --pin 648219 sc-hsm-tool --wrap-key wrap-key.bin --key-reference 1 --pin 648219
-</code>+~~~
  
  
-== Secrets partagés n-of-m+## Secrets partagés n-of-m
  
 Voir aussi [[Crypto - Découper ses clefs en plusieurs morceaux grâce au secret reparti]] Voir aussi [[Crypto - Découper ses clefs en plusieurs morceaux grâce au secret reparti]]
  
 Génération d'un DKEK Génération d'un DKEK
-<code bash>+~~~bash
 sc-hsm-tool --create-dkek-share dkek-share-1.pbe --pwd-shares-threshold 3 --pwd-shares-total 5 sc-hsm-tool --create-dkek-share dkek-share-1.pbe --pwd-shares-threshold 3 --pwd-shares-total 5
-</code>+~~~
  
 Importation d'un DKEK Importation d'un DKEK
-<code bash>+~~~bash
 sc-hsm-tool --import-dkek-share dkek-share-1.pbe --pwd-shares-total 3 sc-hsm-tool --import-dkek-share dkek-share-1.pbe --pwd-shares-total 3
-</code>+~~~
  
  
-== Effacer une clef privée+## Effacer une clef privée
  
-<code bash>+~~~bash
 pkcs11-tool -l --delete-object --type privkey  --id 0988309300f4f26c1ff2279c09026490df89189e pkcs11-tool -l --delete-object --type privkey  --id 0988309300f4f26c1ff2279c09026490df89189e
  
 pkcs11-tool -l --delete-object --type privkey  --label 'RSAplop' pkcs11-tool -l --delete-object --type privkey  --label 'RSAplop'
-</code>+~~~
  
  
-== Importer un certificat dans la puce+## Importer un certificat dans la puce
  
-<code bash>+~~~bash
 hsmwiz putcrt cert.pem  hsmwiz putcrt cert.pem 
-</code>+~~~
  
  
-== Déchiffrer les clefs privées+## Déchiffrer les clefs privées
  
 Voir https://raymii.org/s/articles/Decrypt_NitroKey_HSM_or_SmartCard-HSM_private_keys.html Voir https://raymii.org/s/articles/Decrypt_NitroKey_HSM_or_SmartCard-HSM_private_keys.html
  
  
-== Pb+## Pb
  
-=== Unable to select file HHHH: Incorrect parameters in APDU+### Unable to select file HHHH: Incorrect parameters in APDU
  
-<code ->+~~~
 $ opensc-explorer  $ opensc-explorer 
 OpenSC Explorer version 0.22.0 OpenSC Explorer version 0.22.0
Ligne 264: Ligne 265:
 Unable to select file CC01: Incorrect parameters in APDU Unable to select file CC01: Incorrect parameters in APDU
 Unable to select file CC02: Incorrect parameters in APDU Unable to select file CC02: Incorrect parameters in APDU
-</code>+~~~
  
-==== Solution+#### Solution
  
-<code bash>+~~~bash
 hsmwiz explore hsmwiz explore
-</code>+~~~
  
 -------------------------------- --------------------------------
  
  
-<code bash>+~~~bash
 sc-hsm-tool --create-dkek-share dkek-share-alice.pbe sc-hsm-tool --create-dkek-share dkek-share-alice.pbe
 sc-hsm-tool --create-dkek-share dkek-share-bob.pbe sc-hsm-tool --create-dkek-share dkek-share-bob.pbe
Ligne 287: Ligne 288:
 sc-hsm-tool --import-dkek-share dkek-share-alice.pbe sc-hsm-tool --import-dkek-share dkek-share-alice.pbe
 sc-hsm-tool --import-dkek-share dkek-share-bob.pbe sc-hsm-tool --import-dkek-share dkek-share-bob.pbe
-</code>+~~~
  
-<code ->+~~~
 Deciphering DKEK share, please wait... Deciphering DKEK share, please wait...
 DKEK share imported DKEK share imported
 DKEK shares          : 2 DKEK shares          : 2
 DKEK key check value : 4A44853AAAF1253E DKEK key check value : 4A44853AAAF1253E
-</code>+~~~
  
 Générer une paire de clefs Générer une paire de clefs
-<code bash>+~~~bash
  pkcs11-tool --pin=648219 --keypairgen --key-type rsa:2048  pkcs11-tool --pin=648219 --keypairgen --key-type rsa:2048
-</code>+~~~
  
 Voir les clefs Voir les clefs
-<code bash>+~~~bash
 pkcs15-tool -D pkcs15-tool -D
-</code>+~~~
  
 Exporter la clef privée générée (chiffrée) Exporter la clef privée générée (chiffrée)
-<code bash>+~~~bash
 #set +o history #set +o history
 export HISTCONTROL = ignorespace export HISTCONTROL = ignorespace
  sc-hsm-tool --wrap-key key-wrap.bin --key-reference 1 --pin=648219   sc-hsm-tool --wrap-key key-wrap.bin --key-reference 1 --pin=648219 
-</code>+~~~
  
-=== Importation carte backup+### Importation carte backup
  
-<code bash>+~~~bash
 sc-hsm-tool --import-dkek-share dkek-share-alice.pbe sc-hsm-tool --import-dkek-share dkek-share-alice.pbe
 sc-hsm-tool --import-dkek-share dkek-share-bob.pbe sc-hsm-tool --import-dkek-share dkek-share-bob.pbe
Ligne 321: Ligne 322:
 export HISTCONTROL = ignorespace export HISTCONTROL = ignorespace
  sc-hsm-tool --unwrap-key key-wrap.bin --key-reference 1 --pin=648219   sc-hsm-tool --unwrap-key key-wrap.bin --key-reference 1 --pin=648219 
-</code>+~~~
  
 = PKI = PKI
  
-<code bash>+~~~bash
 pkcs11-tool -l --keypairgen --key-type EC:secp384r1 --label root pkcs11-tool -l --keypairgen --key-type EC:secp384r1 --label root
  
  
-</code>+~~~
  
 = Avoir des informations = Avoir des informations
  
-<code bash>+~~~bash
 sc-hsm-tool sc-hsm-tool
  
Ligne 339: Ligne 340:
 pkcs11-tool -O --id 0 pkcs11-tool -O --id 0
 pkcs11-tool -O --id 0988309300f4f26c1ff2279c09026490df89189e pkcs11-tool -O --id 0988309300f4f26c1ff2279c09026490df89189e
-</code>+~~~
  
 ---------- ----------
  
-== Autres+## Autres
  
-=== CA+### CA
  
 https://docs.nitrokey.com/fr/hsm/mac/pkcs11-url.html https://docs.nitrokey.com/fr/hsm/mac/pkcs11-url.html
  
  
-<code bash>+~~~bash
 pkcs15-init --delete-objects privkey,pubkey --id 3 --generate-key rsa/2048 --auth-id 3 --verify pkcs15-init --delete-objects privkey,pubkey --id 3 --generate-key rsa/2048 --auth-id 3 --verify
-</code>+~~~
  
 https://docs.nitrokey.com/pro/linux/certificate-authority.html https://docs.nitrokey.com/pro/linux/certificate-authority.html
  
-<code ->+~~~
 pkcs11-tool -l --login-type so --keypairgen --key-type EC:brainpoolP512r1 --label root # --id 03 pkcs11-tool -l --login-type so --keypairgen --key-type EC:brainpoolP512r1 --label root # --id 03
 pkcs15-init --delete-objects privkey,pubkey --id 3 --generate-key EC:brainpoolP512r1 --auth-id 3 --verify pkcs15-init --delete-objects privkey,pubkey --id 3 --generate-key EC:brainpoolP512r1 --auth-id 3 --verify
-</code>+~~~
  
-<code ->+~~~
 $ pkcs11-tool -l --login-type so --keypairgen --key-type EC:brainpoolP512r1 --label root $ pkcs11-tool -l --login-type so --keypairgen --key-type EC:brainpoolP512r1 --label root
 Using slot 0 with a present token (0x0) Using slot 0 with a present token (0x0)
Ligne 379: Ligne 380:
   Usage:      verify, derive   Usage:      verify, derive
   Access:     none   Access:     none
-</code>+~~~
    
-<code bash+~~~bash 
 pkcs11-tool --list-objects --type cert --slot 1 pkcs11-tool --list-objects --type cert --slot 1
 pkcs11-tool --list-objects --type cert --slot 0 pkcs11-tool --list-objects --type cert --slot 0
-</code>+~~~
  
  
 = Autres = Autres
  
-<code bash>+~~~bash
 #set +o history #set +o history
 export HISTCONTROL = ignorespace export HISTCONTROL = ignorespace
  pkcs11-tool --module opensc-pkcs11.so --login --pin 648219 --list-slots  pkcs11-tool --module opensc-pkcs11.so --login --pin 648219 --list-slots
-</code>+~~~
  
 Autres Autres
-<code ->+~~~
 opensc-tool --atr opensc-tool --atr
 opensc-explorer --mf aid:E82B0601040181C31F0201 opensc-explorer --mf aid:E82B0601040181C31F0201
Ligne 410: Ligne 411:
  
 openssl genrsa -out rsa2048 2048 openssl genrsa -out rsa2048 2048
-</code>+~~~
  
 Autres Autres
-<code ->+~~~
  load("tools/explore.js");  load("tools/explore.js");
  load("tools/OutlineCore.js");  load("tools/OutlineCore.js");
Ligne 435: Ligne 436:
  
 hsmwiz putcrt keyStore.p12  hsmwiz putcrt keyStore.p12 
-</code> +~~~
- +
-== +
  
  
  
  
tech/notes_hsm.1742825205.txt.gz · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki