1PKCS11-TOOL(1) OpenSC Tools PKCS11-TOOL(1)
2
3
4
6 pkcs11-tool - utility for managing and using PKCS #11 security tokens
7
9 pkcs11-tool [OPTIONS]
10
12 The pkcs11-tool utility is used to manage the data objects on smart
13 cards and similar PKCS #11 security tokens. Users can list and read
14 PINs, keys and certificates stored on the token. User PIN
15 authentication is performed for those operations that require it.
16
18 --attr-from filename
19 Extract information from filename (DER-encoded certificate file)
20 and create the corresponding attributes when writing an object to
21 the token. Example: the certificate subject name is used to create
22 the CKA_SUBJECT attribute.
23
24 --change-pin, -c
25 Change the user PIN on the token
26
27 --unlock-pin
28 Unlock User PIN (without --login unlock in logged in session;
29 otherwise --login-type has to be 'context-specific').
30
31 --hash, -h
32 Hash some data.
33
34 --hash-algorithm mechanism
35 Specify hash algorithm used with RSA-PKCS-PSS signature or RSA-OAEP
36 decryption. Allowed values are "SHA-1", "SHA256", "SHA384",
37 "SHA512", and some tokens may also allow "SHA224". Default is
38 "SHA-1".
39
40 Note that the input to RSA-PKCS-PSS has to be of the size equal to
41 the specified hash algorithm. E.g., for SHA256 the signature input
42 must be exactly 32 bytes long (for mechanisms SHA256-RSA-PKCS-PSS
43 there is no such restriction). For RSA-OAEP, the plaintext input
44 size mLen must be at most keyLen - 2 - 2*hashLen. For example, for
45 RSA 3072-bit key and SHA384, the longest plaintext to encrypt with
46 RSA-OAEP is (with all sizes in bytes): 384 - 2 - 2*48 = 286, aka
47 286 bytes.
48
49 --id id, -d id
50 Specify the id of the object to operate on.
51
52 --init-pin
53 Initializes the user PIN. This option differs from --change-pin in
54 that it sets the user PIN for the first time. Once set, the user
55 PIN can be changed using --change-pin.
56
57 --init-token
58 Initialize a token: set the token label as well as a Security
59 Officer PIN (the label must be specified using --label).
60
61 --input-file filename, -i filename
62 Specify the path to a file for input.
63
64 --keypairgen, -k
65 Generate a new key pair (public and private pair.)
66
67 --keygen
68 Generate a new key.
69
70 --key-type specification
71 Specify the type and length of the key to create, for example
72 rsa:1024 or EC:prime256v1.
73
74 --usage-sign
75 Specify 'sign' key usage flag (sets SIGN in privkey, sets VERIFY in
76 pubkey).
77
78 --usage-decrypt
79 Specify 'decrypt' key usage flag (RSA only, set DECRYPT privkey,
80 ENCRYPT in pubkey).
81
82 --usage-derive
83 Specify 'derive' key usage flag (EC only).
84
85 --label name, -a name
86 Specify the name of the object to operate on (or the token label
87 when --init-token is used).
88
89 --list-mechanisms, -M
90 Display a list of mechanisms supported by the token.
91
92 --list-objects, -O
93 Display a list of objects.
94
95 --list-slots, -L
96 Display a list of available slots on the token.
97
98 --list-token-slots, -T
99 List slots with tokens.
100
101 --login, -l
102 Authenticate to the token before performing other operations. This
103 option is not needed if a PIN is provided on the command line.
104
105 --login-type
106 Specify login type ('so', 'user', 'context-specific';
107 default:'user').
108
109 --mechanism mechanism, -m mechanism
110 Use the specified mechanism for token operations. See -M for a list
111 of mechanisms supported by your token. The mechanism can also be
112 specified in hexadecimal, e.g., 0x80001234.
113
114 --mgf function
115 Use the specified Message Generation Function (MGF) function for
116 RSA-PKCS-PSS signatures or RSA-OAEP decryptions. Supported
117 arguments are MGF1-SHA1 to MGF1-SHA512 if supported by the driver.
118 The default is based on the hash selection.
119
120 --module mod
121 Specify a PKCS#11 module (or library) to load.
122
123 --moz-cert filename, -z filename
124 Test a Mozilla-like keypair generation and certificate request.
125 Specify the filename to the certificate file.
126
127 --output-file filename, -o filename
128 Specify the path to a file for output.
129
130 --pin pin, -p pin
131 Use the given pin for token operations. If set to env:VARIABLE, the
132 value of the environment variable VARIABLE is used. WARNING: Be
133 careful using this option as other users may be able to read the
134 command line from the system or if it is embedded in a script. If
135 set to env:VARIABLE, the value of the environment variable VARIABLE
136 is used.
137
138 This option will also set the --login option.
139
140 --puk puk
141 Supply User PUK on the command line.
142
143 --new-pin pin
144 Supply new User PIN on the command line.
145
146 --sensitive
147 Set the CKA_SENSITIVE attribute (object cannot be revealed in
148 plaintext).
149
150 --extractable
151 Set the CKA_EXTRACTABLE attribute (object can be extracted)
152
153 --set-id id, -e id
154 Set the CKA_ID of the object.
155
156 --show-info, -I
157 Display general token information.
158
159 --sign, -s
160 Sign some data.
161
162 --decrypt,
163 Decrypt some data.
164
165 --derive,
166 Derive a secret key using another key and some data.
167
168 --derive-pass-der,
169 Derive ECDHpass DER encoded pubkey for compatibility with some
170 PKCS#11 implementations
171
172 --salt-len bytes
173 Specify how many bytes of salt should be used in RSA-PSS
174 signatures. Accepts two special values: "-1" means salt length
175 equals to digest length, "-2" means use maximum permissible length.
176 Default is digest length (-1).
177
178 --slot id
179 Specify the id of the slot to use.
180
181 --slot-description description
182 Specify the description of the slot to use.
183
184 --slot-index index
185 Specify the index of the slot to use.
186
187 --object-index index
188 Specify the index of the object to use.
189
190 --token-label label
191 Specify the label of token. Will be used the first slot, that has
192 the inserted token with this label.
193
194 --so-pin pin
195 Use the given pin as the Security Officer PIN for some token
196 operations (token initialization, user PIN initialization, etc). If
197 set to env:VARIABLE, the value of the environment variable VARIABLE
198 is used. The same warning as --pin also applies here.
199
200 --test, -t
201 Perform some tests on the token. This option is most useful when
202 used with either --login or --pin.
203
204 --test-hotplug
205 Test hotplug capabilities (C_GetSlotList + C_WaitForSlotEvent).
206
207 --private
208 Set the CKA_PRIVATE attribute (object is only viewable after a
209 login).
210
211 --always-auth
212 Set the CKA_ALWAYS_AUTHENTICATE attribute to a private key object.
213 If set, the user has to supply the PIN for each use (sign or
214 decrypt) with the key.
215
216 --allowed-mechanisms mechanisms
217 Sets the CKA_ALLOWED_MECHANISMS attribute to a key objects when
218 importing an object or generating a keys. The argument accepts
219 comma-separated list of algorithmsm, that can be used with the
220 given key.
221
222 --test-ec
223 Test EC (best used with the --login or --pin option).
224
225 --test-fork
226 Test forking and calling C_Initialize() in the child.
227
228 --type type, -y type
229 Specify the type of object to operate on. Valid value are cert,
230 privkey, pubkey, secrkey and data.
231
232 --verbose, -v
233 Cause pkcs11-tool to be more verbose.
234
235 NB! This does not affect OpenSC debugging level! To set OpenSC
236 PKCS#11 module into debug mode, set the OPENSC_DEBUG environment
237 variable to a non-zero number.
238
239 --verify,
240 Verify signature of some data.
241
242 --read-object, -r
243 Get object's CKA_VALUE attribute (use with --type).
244
245 --delete-object, -b
246 Delete an object.
247
248 --application-label label
249 Specify the application label of the data object (use with --type
250 data).
251
252 --application-id id
253 Specify the application ID of the data object (use with --type
254 data).
255
256 --issuer data
257 Specify the issuer in hexadecimal format (use with --type cert).
258
259 --subject data
260 Specify the subject in hexadecimal format (use with --type
261 cert/privkey/pubkey).
262
263 --signature-file filename
264 The path to the signature file for signature verification
265
266 --signature-format format
267 Format for ECDSA signature: 'rs' (default), 'sequence', 'openssl'.
268
269 --write-object filename, -w filename
270 Write a key or certificate object to the token. filename points to
271 the DER-encoded certificate or key file.
272
273 --generate-random num
274 Get num bytes of random data.
275
277 To list all certificates on the smart card:
278
279 pkcs11-tool --list-objects --type cert
280
281 To read the certificate with ID KEY_ID in DER format from smart card:
282
283 pkcs11-tool --read-object --id KEY_ID --type cert --output-file cert.der
284
285 To convert the certificate in DER format to PEM format, use OpenSSL
286 tools:
287
288 openssl x509 -inform DER -in cert.der -outform PEM > cert.pem
289
290 To sign some data stored in file data using the private key with ID ID
291 and using the RSA-PKCS mechanism:
292
293 pkcs11-tool --sign --id ID --mechanism RSA-PKCS --input-file data --output-file data.sig
294
295
297 pkcs11-tool was written by Olaf Kirch <okir@suse.de>.
298
299
300
301opensc 02/10/2020 PKCS11-TOOL(1)