summaryrefslogtreecommitdiff
path: root/config_files/nitrohsm-ca-docs-complete-and-very-messy/nitrohsm-in-action
diff options
context:
space:
mode:
authorhc <hc@email.ch>2024-11-20 12:51:33 +0800
committerhc <hc@email.ch>2024-11-20 12:51:33 +0800
commit853b82126baa1e8e408a10f91053c52626ffad29 (patch)
tree2fc1de9695810681ba654aab3c2a4867aacc1ac7 /config_files/nitrohsm-ca-docs-complete-and-very-messy/nitrohsm-in-action
parentb1f88b682624e85b4b743343dfaaeed113b69413 (diff)
working
Diffstat (limited to 'config_files/nitrohsm-ca-docs-complete-and-very-messy/nitrohsm-in-action')
-rw-r--r--config_files/nitrohsm-ca-docs-complete-and-very-messy/nitrohsm-in-action147
1 files changed, 147 insertions, 0 deletions
diff --git a/config_files/nitrohsm-ca-docs-complete-and-very-messy/nitrohsm-in-action b/config_files/nitrohsm-ca-docs-complete-and-very-messy/nitrohsm-in-action
new file mode 100644
index 0000000..562ebf5
--- /dev/null
+++ b/config_files/nitrohsm-ca-docs-complete-and-very-messy/nitrohsm-in-action
@@ -0,0 +1,147 @@
1
2sudo apt install pcscd pcsc-tools opensc openssl gnutls-bin
3sudo dnf install -y opensc openssl openssl-pkcs11 yubico-piv-tool yubikey-manager usbutils gnutls-utils #try this first. then sc-hsm-tool and pkcs11-tool.
4sudo dnf install -y pcsc-lite pcsc-lite-ccid
5sudo systemctl start pcscd
6sudo systemctl enable pcscd
7sudo opensc-tool -l
8
9so-pin 3537363231383830
10userpin 648219
11
127535439178124602
13
14pkcs11-tool --login --login-type so --so-pin 1234123412341234 --change-pin --new-pin 3537363231383830
15opensc-tool -l # to list devices
16sc-hsm-tool -X -r 1 # -r is device number. to reset the device, you need so pin and userpin
17sc-hsm-tool --initialize --so-pin 3537363231383830 --pin 648219 -r 1
18ykman piv reset #reset yubikey piv
19
20find / -name opensc-pkcs11.so
21
22TESTING BEFORE OPERATION
23 ubuntu ONLY UBUNTU PKCS11 WORKS TO DISPLAY ALL THE REQUIRED DATA AND PASSES ALL TESTS
24pkcs11-tool --module /usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so --login --pin 648219 --test
25/usr/lib64/opensc-pkcs11.so
26/usr/lib64/pkcs11/opensc-pkcs11.so on fedora
27pkcs11-tool --module /usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so --login --pin 648219 --list-objects
28OPENSSL_CONF=./hsm.conf openssl engine
29the following should be printed for openssl
30(dynamic) Dynamic engine loading support
31(pkcs11) pkcs11 engine
32
33
34DOCUMNETATION FOR CA + nginx
35
36pkcs11-tool --module /usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so --login --pin 648219 --keypairgen --key-type rsa:2048 --id 03 --label "serverkey"
37openssl req -engine pkcs11 -keyform engine -new -key "pkcs11:serial=DENK0302043;object=serverkey;type=private;pin-value=648219" -subj "/C=US/ST=YourState/L=YourCity/O=YourOrganization/CN=yourdomain.com" -out server.csr
38 openssl req -text -noout -verify -in server.csr # to verify the certificate
39openssl ca -config ../sign_server_and_client_csrs.ini -engine pkcs11 -keyform engine -extensions server_cert -days 375 -notext -md sha512 -create_serial -in server.csr -out server.crt
40openssl x509 -in server.crt -text -noout | grep -A 1 "Extended Key Usage" # output web server authentication
41
42010203040506070801020304050607080102030405060708 yubikey manageemnt, normal key 123456
43brew install gnutls
44yubico-piv-tool -a generate -s 9a -k -A RSA2048 -o yubi_pubkey.pem
45yubico-piv-tool -a verify-pin -a request-certificate -s 9a -i yubi_pubkey.pem -S '/CN=hii Usenamer/O=Example Corp/C=US/' -o yubi.csr
46openssl ca -config ../sign_server_and_client_csrs.ini -engine pkcs11 -keyform engine -extensions client_cert -days 375 -notext -md sha512 -create_serial -in yubi.csr -out yubi.crt
47openssl x509 -in yubi.crt -text -noout | grep -A 1 "Extended Key Usage" # output web client authentication
48cp yubi.crt yubi.crt.pem
49yubico-piv-tool -a import-certificate -s 9a -k -i yubi.crt.pem -K PEM
50p11tool --list-tokens
51curl -E 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=00000000;token=hii%20Usenamer' https://127.0.0.1 -k
52curl -E 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=00000000;token=hii%20Usenamer;pin-value=123456' https://127.0.0.1 -k
53can do curl -v xxxxxxxx as well for more verbose.
54
55openssl genrsa -out client.key 2048
56openssl req -new -key client.key -out client.csr -subj "/C=US/ST=YourState/L=YourCity/O=YourOrg/CN=client2"
57openssl ca -config ../sign_server_and_client_csrs.ini -engine pkcs11 -keyform engine -extensions client_cert -days 375 -notext -md sha512 -create_serial -in client.csr -out client.crt
58openssl x509 -in client.crt -text -noout | grep -A 1 "Extended Key Usage" # output web client authentication
59curl https://127.0.0.1 --cacert ../../intermediate/certs/chain.crt --cert client.crt --key client.key -k
60
61STILL WILL HAVE ERROR BECAUSE URL REQUEST IS 127.0.0.1, if this is a public domain, curl checks the url in the cert and the requested url and if they both match, there should be no error when curling without -k
62
63openssl version -d # to find the default config file dir
64copy hsm.conf to the directory
65sudo nano /lib/systemd/system/nginx.service
66 add this to under service
67Environment=LANG=C
68Environment="OPENSSL_CONF=/usr/lib/ssl/hsm.conf"
69sudo systemctl daemon-reload
70
71pkcs15-tool --list-info
72 to get the serial number value of the device for the key
73p11tool --list-all
74p11tool --login --list-all pkcs11:model=
75
76ssl_engine pkcs11; # put this after events section, before http.
77 ssl_certificate /home/x/auths2/config/signing_area/server_cert.crt;
78 ssl_certificate_key "engine:pkcs11:pkcs11:serial=DENK0302043;object=serverkey;type=private";
79 ssl_client_certificate /home/x/auths2/intermediate/certs/chain.crt;
80 ssl_verify_client on;
81
82cat server.crt ../intermediate/certs/intermediate.crt ../certs/root.crt > fullchain.crt
83
84curl -X POST http://127.0.0.1/generate_verification -k
85curl -X POST -d "verify=wrIFRSJZ" -E 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=00000000;token=hii%20Usenamer;pin-value=123456' https://127.0.0.1/verify -k
86curl -E 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=00000000;token=hii%20Usenamer;pin-value=123456' https://127.0.0.1/check?string=wrIFRSJZ -k
87
88#change the check to not require authentication
89
90https://www.entrust.com/sites/default/files/documentation/integration-guides/nginx-server-nhield-v12-60-11_ig.pdf
91https://docs.nitrokey.com/hsm/linux/certificate-authority
92https://github.com/OpenSC/libp11/blob/5c99a1467e624981181ada75f41315cd1cf13e37/src/eng_parse.c
93 ^ is the pkcs uri for openssl -key
94
95DOCUMNETATION FOR CA + nginx END
96
97
98 yubico
99yubico-piv-tool -a unblock-pin -P 12345678 -N 123456
100123456 pin default
10112345678 pin unlock key default
102010203040506070801020304050607080102030405060708 management key default
103ssh -I /usr/lib64/pkcs11/opensc-pkcs11.so user@ip #then enter the userpin for yubikey
104
105
106should work
107openssl dgst -engine pkcs11 -keyform engine -sha256 -sign "pkcs11:id=%01" -out signature.bin txt
108openssl dgst -engine pkcs11 -keyform engine -sha256 -verify "pkcs11:id=%01" -signature signature.bin txt
109openssl dgst -engine pkcs11 -keyform engine -sha256 -verify 01 -signature signature.bin txt #sign should work as well
110pkcs15-tool --read-public-key 01 > pubkey
111openssl dgst -sha256 -verify pubkey -signature signature.bin txt
112
113
114openssl genrsa -out rootCA.key 2048
115openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem -subj "/CN=Root CA"
116openssl genrsa -out client.key 2048
117openssl req -new -key client.key -out client.csr -subj "/CN=Client"
118openssl x509 -req -in client.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out client.crt -days 500 -sha256
119openssl verify -CAfile rootCA.pem client.crt
120#$client.crt: OK
121
122
123untested
124pkcs11-tool --module /usr/lib64/pkcs11/opensc-pkcs11.so -L #list
125yubico-piv-tool -astatus #list
126pkcs11-tool --module /usr/lib64/pkcs11/opensc-pkcs11.so --slot-index 1 --login --pin 648219 --list-objects
127
128
129 generate the key
130pkcs11-tool --module /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so --login --pin 648219 --keypairgen --key-type rsa:2048 --id 01 --label "foo"
131
132 sign the file and create an output
133pkcs11-tool --module /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so --login --pin 648219 --sign --id 01 --input-file <input-file> --output-file <signature-file>
134pkcs11-tool --module /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so --login --pin 648219 --sign --label "foo" --input-file <input-file> --output-file <signature-file>
135
136
137pkcs11-tool --module /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so --login --pin 648219 --verify --id 01 --input-file <input-file> --signature-file <signature-file>
138pkcs11-tool --module /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so --login --pin 648219 --verify --label "foo" --input-file <input-file> --signature-file <signature-file>
139
140# Example test command sequence
141echo "Test data" > testdata.txt
142pkcs11-tool --module /usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so --login --pin 648219 --id 01 --type privkey --sign -i testdata.txt -o signeddata.bin
143pkcs11-tool --module /usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so --login --pin 648219 --id 01 --type pubkey --verify -i testdata.txt -s signeddata.bin
144
145
146pkcs11-tool --module $MODULE --login --pin YOUR_PIN --list-objects
147