|
710 | 710 | Perform a basic functionality test of the card:
|
711 | 711 | <programlisting>pkcs11-tool --test --login</programlisting>
|
712 | 712 |
|
713 |
| - To list all certificates on the smart card: |
| 713 | + List all certificates on the smart card: |
714 | 714 | <programlisting>pkcs11-tool --list-objects --type cert</programlisting>
|
715 | 715 |
|
716 |
| - To read the certificate with ID <replaceable>KEY_ID</replaceable> |
717 |
| - in DER format from smart card: |
718 |
| - <programlisting>pkcs11-tool --read-object --id KEY_ID --type cert --output-file cert.der</programlisting> |
| 716 | + Read the certificate with ID <varname>CERT_ID</varname> |
| 717 | + in DER format from smart card and convert it to PEM via OpenSSL: |
| 718 | + <programlisting> |
| 719 | +pkcs11-tool --read-object --id $CERT_ID --type cert \ |
| 720 | + --output-file cert.der |
| 721 | +openssl x509 -inform DER -in cert.der -outform PEM > cert.pem |
| 722 | + </programlisting> |
719 | 723 |
|
720 |
| - Write certificate to token: |
721 |
| - <programlisting> pkcs11-tool --login --write-object certificate.der --type cert</programlisting> |
722 |
| - |
723 |
| - To convert the certificate in DER format to PEM format, use OpenSSL |
724 |
| - tools: |
725 |
| - <programlisting>openssl x509 -inform DER -in cert.der -outform PEM > cert.pem</programlisting> |
| 724 | + Write a certificate to token: |
| 725 | + <programlisting>pkcs11-tool --login --write-object certificate.der --type cert</programlisting> |
726 | 726 |
|
727 | 727 | Generate new RSA Key pair:
|
728 | 728 | <programlisting>pkcs11-tool --login --keypairgen --key-type RSA:2048</programlisting>
|
|
732 | 732 |
|
733 | 733 | Generate an elliptic curve key pair with OpenSSL and import it to the card as <varname>$ID</varname>:
|
734 | 734 | <programlisting>openssl genpkey -out EC_private.der -outform DER \
|
735 |
| - -algorithm EC -pkeyopt ec_paramgen_curve:P-521 |
| 735 | + -algorithm EC -pkeyopt ec_paramgen_curve:P-521 |
736 | 736 | pkcs11-tool --write-object EC_private.der --id "$ID" \
|
737 |
| - --type privkey --label "EC private key" -p "$PIN" |
| 737 | + --type privkey --label "EC private key" -p "$PIN" |
738 | 738 | openssl pkey -in EC_private.der -out EC_public.der \
|
739 |
| - -pubout -inform DER -outform DER |
| 739 | + -pubout -inform DER -outform DER |
740 | 740 | pkcs11-tool --write-object EC_public.der --id "$ID" \
|
741 |
| - --type pubkey --label "EC public key" -p $PIN</programlisting> |
| 741 | + --type pubkey --label "EC public key" -p $PIN</programlisting> |
742 | 742 |
|
743 | 743 | List private keys:
|
744 | 744 | <programlisting>pkcs11-tool --login --list-objects --type privkey</programlisting>
|
745 | 745 |
|
746 |
| - To sign some data stored in file <replaceable>data</replaceable> |
747 |
| - using the private key with ID <replaceable>ID</replaceable> and |
| 746 | + Sign some data stored in file <filename>data</filename> |
| 747 | + using the private key with ID <varname>ID</varname> and |
748 | 748 | using the RSA-PKCS mechanism:
|
749 |
| - <programlisting>pkcs11-tool --sign --id ID --mechanism RSA-PKCS --input-file data --output-file data.sig</programlisting> |
| 749 | + <programlisting> |
| 750 | +pkcs11-tool --sign --id $ID --mechanism RSA-PKCS \ |
| 751 | + --input-file data --output-file data.sig |
| 752 | + </programlisting> |
750 | 753 | The same is also possible by piping the data from stdin rather than specifying a input file:
|
751 |
| - <programlisting>dd if=data bs=128 count=1 | pkcs11-tool --sign --id ID --mechanism RSA-PKCS --pin=$PIN > data.sig</programlisting> |
| 754 | + <programlisting> |
| 755 | +dd if=data bs=128 count=1 \ |
| 756 | + | pkcs11-tool --sign --id $ID --mechanism RSA-PKCS \ |
| 757 | + > data.sig |
| 758 | + </programlisting> |
752 | 759 |
|
753 | 760 | Verify the signed data:
|
754 |
| -<programlisting>pkcs11-tool --id ID --verify -m RSA-PKCS --input-file data --signature-file data.sig</programlisting> |
| 761 | + <programlisting> |
| 762 | +pkcs11-tool --id ID --verify -m RSA-PKCS \ |
| 763 | + --input-file data --signature-file data.sig |
| 764 | + </programlisting> |
755 | 765 |
|
756 | 766 | To encrypt file using the AES key with ID 85 and using mechanism AES-CBC with padding:
|
757 | 767 | <programlisting>
|
758 | 768 | pkcs11-tool --login --encrypt --id 85 -m AES-CBC-PAD \
|
759 |
| - --iv "00000000000000000000000000000000" \ |
760 |
| - -i file.txt -o encrypted_file.data |
761 |
| - Decipher the encrypted file: |
| 769 | + --iv "00000000000000000000000000000000" \ |
| 770 | + -i file.txt -o encrypted_file.data |
762 | 771 | </programlisting>
|
| 772 | + Decipher the encrypted file: |
| 773 | + <programlisting> |
763 | 774 | pkcs11-tool --login --decrypt --id 85 -m AES-CBC-PAD \
|
764 |
| - --iv "00000000000000000000000000000000" \ |
765 |
| ---i encrypted_file.data -o decrypted.txt |
| 775 | + --iv "00000000000000000000000000000000" \ |
| 776 | + --i encrypted_file.data -o decrypted.txt |
766 | 777 | </programlisting>
|
767 | 778 |
|
768 | 779 | Use the key with ID 75 using mechanism AES-CBC-PAD, with initialization vector
|
769 | 780 | "00000000000000000000000000000000" to wrap the key with ID 76 into output file
|
770 |
| - <replaceable>exported_aes.key</replaceable> |
| 781 | + <filename>exported_aes.key</filename> |
771 | 782 | <programlisting>
|
772 | 783 | pkcs11-tool --login --wrap --id 75 --mechanism AES-CBC-PAD \
|
773 |
| - --iv "00000000000000000000000000000000" \ |
774 |
| - --application-id 76 \ |
775 |
| - --output-file exported_aes.key |
| 784 | + --iv "00000000000000000000000000000000" \ |
| 785 | + --application-id 76 \ |
| 786 | + --output-file exported_aes.key |
776 | 787 | </programlisting>
|
777 | 788 | Use the key with ID 22 and mechanism RSA-PKCS to unwrap key from file
|
778 |
| - <replaceable>aes_wrapped.key</replaceable>. After a successful unwrap operation, |
| 789 | + <filename>aes_wrapped.key</filename>. After a successful unwrap operation, |
779 | 790 | a new AES key is created on token. ID of this key is set to 90 and label of this
|
780 |
| - key is set to <replaceable>unwrapped-key</replaceable> |
| 791 | + key is set to <literal>unwrapped-key</literal> |
781 | 792 | Note: for the MyEID card, the AES key size must be present in key
|
782 | 793 | specification i.e. AES:16
|
783 | 794 | <programlisting>
|
784 | 795 | pkcs11-tool --login --unwrap --mechanism RSA-PKCS --id 22 \
|
785 |
| - -i aes_wrapped.key --key-type AES: \ |
786 |
| - --application-id 90 --applicatin-label unwrapped-key |
| 796 | + -i aes_wrapped.key --key-type AES: \ |
| 797 | + --application-id 90 --applicatin-label unwrapped-key |
787 | 798 | </programlisting>
|
788 | 799 |
|
789 | 800 | Use the SO-PIN to initialize or re-set the PIN:
|
|
0 commit comments