tech:notes_hsm
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| tech:notes_hsm [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:notes_hsm [2025/04/14 15:05] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | {{tag> | + | < |
| + | {{tag> | ||
| - | = Notes HSM | + | # Notes HSM |
| Todo : | Todo : | ||
| Ligne 38: | Ligne 39: | ||
| - | < | + | ~~~bash |
| hsmwiz | hsmwiz | ||
| pkcs15-tool --dump | pkcs15-tool --dump | ||
| Ligne 45: | Ligne 46: | ||
| # Si KO faire : | # Si KO faire : | ||
| hsmwiz explorer | hsmwiz explorer | ||
| - | </ | + | ~~~ |
| 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. | ||
| - | < | + | ~~~bash |
| #set +o history | #set +o history | ||
| export HISTCONTROL = ignorespace | export HISTCONTROL = ignorespace | ||
| | | ||
| - | </ | + | ~~~ |
| - | < | + | ~~~bash |
| #set +o history | #set +o history | ||
| export HISTCONTROL = ignorespace | export HISTCONTROL = ignorespace | ||
| | | ||
| - | </ | + | ~~~ |
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| 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:// | * https:// | ||
| - | == Initialisation / Réinitialiseation (Reset) | + | ## Initialisation / Réinitialiseation (Reset) |
| Voir DKEK : Device Key Encryption Key | Voir DKEK : Device Key Encryption Key | ||
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| Test | Test | ||
| - | < | + | ~~~bash |
| pkcs11-tool --test --login --pin 648219 | pkcs11-tool --test --login --pin 648219 | ||
| - | </ | + | ~~~ |
| - | < | + | ~~~bash |
| #set +o history | #set +o history | ||
| export HISTCONTROL = ignorespace | export HISTCONTROL = ignorespace | ||
| | | ||
| - | </ | + | ~~~ |
| Ou | Ou | ||
| - | < | + | ~~~bash |
| | | ||
| - | </ | + | ~~~ |
| - | == Changer PIN | + | ## Changer PIN |
| Changer PIN / Débloquer carte | Changer PIN / Débloquer carte | ||
| - | < | + | ~~~bash |
| #set +o history | #set +o history | ||
| export HISTCONTROL = ignorespace | export HISTCONTROL = ignorespace | ||
| | | ||
| - | </ | + | ~~~ |
| - | == Génération d'une clef privée sur puce | + | ## Génération d'une clef privée sur puce |
| - | < | + | ~~~bash |
| #set +o history | #set +o history | ||
| export HISTCONTROL = ignorespace | export HISTCONTROL = ignorespace | ||
| | | ||
| - | </ | + | ~~~ |
| - | < | + | ~~~bash |
| pkcs11-tool -l --keypairgen --key-type EC: | pkcs11-tool -l --keypairgen --key-type EC: | ||
| - | </ | + | ~~~ |
| - | == Importer une clef privée existante | + | ## Importer une clef privée existante |
| TODO | TODO | ||
| - | == Exporter une clef publique | + | ## Exporter une clef publique |
| - | < | + | ~~~bash |
| pkcs15-tool -D | pkcs15-tool -D | ||
| pkcs15-tool --read-public-key 0988309300f4f26c1ff2279c09026490df89189e > publickey.pem | pkcs15-tool --read-public-key 0988309300f4f26c1ff2279c09026490df89189e > publickey.pem | ||
| - | </ | + | ~~~ |
| - | == Chiffrer avec la clef publique | + | ## Chiffrer avec la clef publique |
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| - | === 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: | C0E2525D567F0000: | ||
| - | </ | + | ~~~ |
| - | == Déchiffrer avec la clef privée | + | ## Déchiffrer avec la clef privée |
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| - | == Signer (RSA) | + | ## Signer (RSA) |
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| - | == Vérifier la signature (RSA) | + | ## Vérifier la signature (RSA) |
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| - | == 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' | * Que si à l' | ||
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| - | == 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 | ||
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| Importation d'un DKEK | Importation d'un DKEK | ||
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| - | == Effacer une clef privée | + | ## Effacer une clef privée |
| - | < | + | ~~~bash |
| pkcs11-tool -l --delete-object --type privkey | pkcs11-tool -l --delete-object --type privkey | ||
| pkcs11-tool -l --delete-object --type privkey | pkcs11-tool -l --delete-object --type privkey | ||
| - | </ | + | ~~~ |
| - | == Importer un certificat dans la puce | + | ## Importer un certificat dans la puce |
| - | < | + | ~~~bash |
| hsmwiz putcrt cert.pem | hsmwiz putcrt cert.pem | ||
| - | </ | + | ~~~ |
| - | == Déchiffrer les clefs privées | + | ## Déchiffrer les clefs privées |
| Voir https:// | Voir https:// | ||
| - | == 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 | ||
| - | </ | + | ~~~ |
| - | ==== Solution | + | #### Solution |
| - | < | + | ~~~bash |
| hsmwiz explore | hsmwiz explore | ||
| - | </ | + | ~~~ |
| -------------------------------- | -------------------------------- | ||
| - | < | + | ~~~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 -> | + | ~~~ |
| Deciphering DKEK share, please wait... | Deciphering DKEK share, please wait... | ||
| DKEK share imported | DKEK share imported | ||
| DKEK shares | DKEK shares | ||
| DKEK key check value : 4A44853AAAF1253E | DKEK key check value : 4A44853AAAF1253E | ||
| - | </ | + | ~~~ |
| Générer une paire de clefs | Générer une paire de clefs | ||
| - | < | + | ~~~bash |
| | | ||
| - | </ | + | ~~~ |
| Voir les clefs | Voir les clefs | ||
| - | < | + | ~~~bash |
| pkcs15-tool -D | pkcs15-tool -D | ||
| - | </ | + | ~~~ |
| Exporter la clef privée générée (chiffrée) | Exporter la clef privée générée (chiffrée) | ||
| - | < | + | ~~~bash |
| #set +o history | #set +o history | ||
| export HISTCONTROL = ignorespace | export HISTCONTROL = ignorespace | ||
| | | ||
| - | </ | + | ~~~ |
| - | === Importation carte backup | + | ### Importation carte backup |
| - | < | + | ~~~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 | ||
| | | ||
| - | </ | + | ~~~ |
| = PKI | = PKI | ||
| - | < | + | ~~~bash |
| pkcs11-tool -l --keypairgen --key-type EC: | pkcs11-tool -l --keypairgen --key-type EC: | ||
| - | </ | + | ~~~ |
| = Avoir des informations | = Avoir des informations | ||
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| ---------- | ---------- | ||
| - | == Autres | + | ## Autres |
| - | === CA | + | ### CA |
| https:// | https:// | ||
| - | < | + | ~~~bash |
| pkcs15-init --delete-objects privkey, | pkcs15-init --delete-objects privkey, | ||
| - | </ | + | ~~~ |
| https:// | https:// | ||
| - | <code -> | + | ~~~ |
| pkcs11-tool -l --login-type so --keypairgen --key-type EC: | pkcs11-tool -l --login-type so --keypairgen --key-type EC: | ||
| pkcs15-init --delete-objects privkey, | pkcs15-init --delete-objects privkey, | ||
| - | </ | + | ~~~ |
| - | <code -> | + | ~~~ |
| $ pkcs11-tool -l --login-type so --keypairgen --key-type EC: | $ pkcs11-tool -l --login-type so --keypairgen --key-type EC: | ||
| Using slot 0 with a present token (0x0) | Using slot 0 with a present token (0x0) | ||
| Ligne 379: | Ligne 380: | ||
| Usage: | Usage: | ||
| Access: | Access: | ||
| - | </ | + | ~~~ |
| - | < | + | ~~~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 | ||
| - | </ | + | ~~~ |
| = Autres | = Autres | ||
| - | < | + | ~~~bash |
| #set +o history | #set +o history | ||
| export HISTCONTROL = ignorespace | export HISTCONTROL = ignorespace | ||
| | | ||
| - | </ | + | ~~~ |
| Autres | Autres | ||
| - | <code -> | + | ~~~ |
| opensc-tool --atr | opensc-tool --atr | ||
| opensc-explorer --mf aid: | opensc-explorer --mf aid: | ||
| Ligne 410: | Ligne 411: | ||
| openssl genrsa -out rsa2048 2048 | openssl genrsa -out rsa2048 2048 | ||
| - | </ | + | ~~~ |
| Autres | Autres | ||
| - | <code -> | + | ~~~ |
| | | ||
| | | ||
| Ligne 435: | Ligne 436: | ||
| hsmwiz putcrt keyStore.p12 | hsmwiz putcrt keyStore.p12 | ||
| - | </ | + | ~~~ |
| - | + | ||
| - | == | + | |
tech/notes_hsm.1742825205.txt.gz · Dernière modification : de 127.0.0.1
