1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
AutoGen Definitions options;
prog-name = certtool;
prog-title = "GnuTLS certificate tool";
prog-desc = "Manipulate certificates and private keys.";
detail = "Tool to parse and generate X.509 certificates, requests and private keys.
It can be used interactively or non interactively by
specifying the template command line option.";
short-usage = "certtool [options]\ncerttool --help for usage instructions.\n";
explain = "";
#define INFILE_OPT 1
#define OUTFILE_OPT 1
#define VERBOSE_OPT 1
#include args-std.def
flag = {
name = generate-self-signed;
value = s;
descrip = "Generate a self-signed certificate";
doc = "";
};
flag = {
name = generate-certificate;
value = c;
descrip = "Generate a signed certificate";
doc = "";
};
flag = {
name = generate-proxy;
descrip = "Generates a proxy certificate";
doc = "";
};
flag = {
name = generate-crl;
descrip = "Generate a CRL";
doc = "";
};
flag = {
name = update-certificate;
value = u;
descrip = "Update a signed certificate";
doc = "";
};
flag = {
name = generate-privkey;
value = p;
descrip = "Generate a private key";
doc = "";
};
flag = {
name = generate-request;
value = q;
descrip = "Generate a PKCS #10 certificate request";
flags_cant = infile;
doc = "Will generate a PKCS #10 certificate request. To specify a private key use --load-privkey.";
};
flag = {
name = verify-chain;
value = e;
descrip = "Verify a PEM encoded certificate chain";
doc = "The last certificate in the chain must be a self signed one.";
};
flag = {
name = verify;
descrip = "Verify a PEM encoded certificate chain using a trusted list";
doc = "The trusted certificate list can be loaded with --load-ca-certificate. If no
certificate list is provided, then the system's certificate list is used.";
};
flag = {
name = verify-crl;
descrip = "Verify a CRL using a trusted list";
doc = "The trusted certificate list must be loaded with --load-ca-certificate.";
flags-must = load-ca-certificate;
};
flag = {
name = generate-dh-params;
descrip = "Generate PKCS #3 encoded Diffie-Hellman parameters";
doc = "";
};
flag = {
name = get-dh-params;
descrip = "Get the included PKCS #3 encoded Diffie-Hellman parameters";
doc = "Returns stored DH parameters in GnuTLS. Those parameters are used in the SRP protocol. The parameters returned by fresh generation
are more efficient since GnuTLS 3.0.9.";
};
flag = {
name = dh-info;
descrip = "Print information PKCS #3 encoded Diffie-Hellman parameters";
doc = "";
};
flag = {
name = load-privkey;
descrip = "Loads a private key file";
arg-type = string;
doc = "This can be either a file or a PKCS #11 URL";
};
flag = {
name = load-pubkey;
descrip = "Loads a public key file";
arg-type = string;
doc = "This can be either a file or a PKCS #11 URL";
};
flag = {
name = load-request;
descrip = "Loads a certificate request file";
arg-type = file;
file-exists = yes;
doc = "";
};
flag = {
name = load-certificate;
descrip = "Loads a certificate file";
arg-type = string;
doc = "This can be either a file or a PKCS #11 URL";
};
flag = {
name = load-ca-privkey;
descrip = "Loads the certificate authority's private key file";
arg-type = string;
doc = "This can be either a file or a PKCS #11 URL";
};
flag = {
name = load-ca-certificate;
descrip = "Loads the certificate authority's certificate file";
arg-type = string;
doc = "This can be either a file or a PKCS #11 URL";
};
flag = {
name = password;
arg-type = string;
descrip = "Password to use";
doc = "";
};
flag = {
name = hex-numbers;
descrip = "Print big number in an easier format to parse";
doc = "";
};
flag = {
name = cprint;
descrip = "In certain operations it prints the information in C-friendly format";
doc = "In certain operations it prints the information in C-friendly format, suitable for including into C programs.";
};
flag = {
name = null-password;
descrip = "Enforce a NULL password";
doc = "This option enforces a NULL password. This may be different than the empty password in some schemas.";
};
flag = {
name = certificate-info;
value = i;
descrip = "Print information on the given certificate";
doc = "";
};
flag = {
name = certificate-pubkey;
descrip = "Print certificate's public key";
doc = "";
};
flag = {
name = pgp-certificate-info;
descrip = "Print information on the given OpenPGP certificate";
doc = "";
};
flag = {
name = pgp-ring-info;
descrip = "Print information on the given OpenPGP keyring structure";
doc = "";
};
flag = {
name = crl-info;
value = l;
descrip = "Print information on the given CRL structure";
doc = "";
};
flag = {
name = crq-info;
descrip = "Print information on the given certificate request";
doc = "";
};
flag = {
name = no-crq-extensions;
descrip = "Do not use extensions in certificate requests";
doc = "";
};
flag = {
name = p12-info;
descrip = "Print information on a PKCS #12 structure";
doc = "";
};
flag = {
name = p7-info;
descrip = "Print information on a PKCS #7 structure";
doc = "";
};
flag = {
name = smime-to-p7;
descrip = "Convert S/MIME to PKCS #7 structure";
doc = "";
};
flag = {
name = key-info;
value = k;
descrip = "Print information on a private key";
doc = "";
};
flag = {
name = pgp-key-info;
descrip = "Print information on an OpenPGP private key";
doc = "";
};
flag = {
name = pubkey-info;
descrip = "Print information on a public key";
doc = "The option combined with --load-request, --load-pubkey, --load-privkey and --load-certificate will extract the public key of the object in question.";
};
flag = {
name = v1;
descrip = "Generate an X.509 version 1 certificate (with no extensions)";
doc = "";
};
flag = {
name = to-p12;
descrip = "Generate a PKCS #12 structure";
doc = "It requires a certificate, a private key and possibly a CA certificate to be specified.";
flags-must = load-certificate;
};
flag = {
name = to-p8;
descrip = "Generate a PKCS #8 structure";
doc = "";
};
flag = {
name = pkcs8;
value = 8;
descrip = "Use PKCS #8 format for private keys";
doc = "";
};
flag = {
name = rsa;
descrip = "Generate RSA key";
doc = "When combined with --generate-privkey generates an RSA private key.";
};
flag = {
name = dsa;
descrip = "Generate DSA key";
doc = "When combined with --generate-privkey generates a DSA private key.";
};
flag = {
name = ecc;
descrip = "Generate ECC (ECDSA) key";
doc = "When combined with --generate-privkey generates an elliptic curve private key to be used with ECDSA.";
};
flag = {
name = ecdsa;
aliases = ecc;
};
flag = {
name = hash;
arg-type = string;
descrip = "Hash algorithm to use for signing";
doc = "Available hash functions are SHA1, RMD160, SHA256, SHA384, SHA512.";
};
flag = {
name = inder;
descrip = "Use DER format for input certificates, private keys, and DH parameters ";
disabled;
disable = "no";
doc = "The input files will be assumed to be in DER or RAW format.
Unlike options that in PEM input would allow multiple input data (e.g. multiple
certificates), when reading in DER format a single data structure is read.";
};
flag = {
name = inraw;
aliases = inder;
};
flag = {
name = outder;
descrip = "Use DER format for output certificates, private keys, and DH parameters";
disabled;
disable = "no";
doc = "The output will be in DER or RAW format.";
};
flag = {
name = outraw;
aliases = outder;
};
flag = {
name = bits;
arg-type = number;
descrip = "Specify the number of bits for key generate";
doc = "";
};
flag = {
name = sec-param;
arg-type = string;
arg-name = "Security parameter";
descrip = "Specify the security level [low, legacy, normal, high, ultra]";
doc = "This is alternative to the bits option.";
};
flag = {
name = disable-quick-random;
descrip = "No effect";
doc = "";
};
flag = {
name = template;
arg-type = file;
file-exists = yes;
descrip = "Template file to use for non-interactive operation";
doc = "";
};
flag = {
name = ask-pass;
disabled;
descrip = "Enable interaction for entering password when in batch mode.";
doc = "This option will enable interaction to enter password when in batch mode. That is useful when the template option has been specified.";
};
flag = {
name = pkcs-cipher;
arg-type = string;
arg-name = "Cipher";
descrip = "Cipher to use for PKCS #8 and #12 operations";
doc = "Cipher may be one of 3des, 3des-pkcs12, aes-128, aes-192, aes-256, rc2-40, arcfour.";
};
doc-section = {
ds-type = 'SEE ALSO';
ds-format = 'texi';
ds-text = <<-_EOT_
p11tool (1)
_EOT_;
};
doc-section = {
ds-type = 'EXAMPLES';
ds-format = 'texi';
ds-text = <<-_EOT_
@subheading Generating private keys
To create an RSA private key, run:
@example
$ certtool --generate-privkey --outfile key.pem --rsa
@end example
To create a DSA or elliptic curves (ECDSA) private key use the
above command combined with 'dsa' or 'ecc' options.
@subheading Generating certificate requests
To create a certificate request (needed when the certificate is issued by
another party), run:
@example
certtool --generate-request --load-privkey key.pem \
--outfile request.pem
@end example
If the private key is stored in a smart card you can generate
a request by specifying the private key object URL.
@example
$ ./certtool --generate-request --load-privkey "pkcs11:..." \
--load-pubkey "pkcs11:..." --outfile request.pem
@end example
@subheading Generating a self-signed certificate
To create a self signed certificate, use the command:
@example
$ certtool --generate-privkey --outfile ca-key.pem
$ certtool --generate-self-signed --load-privkey ca-key.pem \
--outfile ca-cert.pem
@end example
Note that a self-signed certificate usually belongs to a certificate
authority, that signs other certificates.
@subheading Generating a certificate
To generate a certificate using the previous request, use the command:
@example
$ certtool --generate-certificate --load-request request.pem \
--outfile cert.pem --load-ca-certificate ca-cert.pem \
--load-ca-privkey ca-key.pem
@end example
To generate a certificate using the private key only, use the command:
@example
$ certtool --generate-certificate --load-privkey key.pem \
--outfile cert.pem --load-ca-certificate ca-cert.pem \
--load-ca-privkey ca-key.pem
@end example
@subheading Certificate information
To view the certificate information, use:
@example
$ certtool --certificate-info --infile cert.pem
@end example
@subheading PKCS #12 structure generation
To generate a PKCS #12 structure using the previous key and certificate,
use the command:
@example
$ certtool --load-certificate cert.pem --load-privkey key.pem \
--to-p12 --outder --outfile key.p12
@end example
Some tools (reportedly web browsers) have problems with that file
because it does not contain the CA certificate for the certificate.
To work around that problem in the tool, you can use the
--load-ca-certificate parameter as follows:
@example
$ certtool --load-ca-certificate ca.pem \
--load-certificate cert.pem --load-privkey key.pem \
--to-p12 --outder --outfile key.p12
@end example
@subheading Diffie-Hellman parameter generation
To generate parameters for Diffie-Hellman key exchange, use the command:
@example
$ certtool --generate-dh-params --outfile dh.pem --sec-param normal
@end example
@subheading Proxy certificate generation
Proxy certificate can be used to delegate your credential to a
temporary, typically short-lived, certificate. To create one from the
previously created certificate, first create a temporary key and then
generate a proxy certificate for it, using the commands:
@example
$ certtool --generate-privkey > proxy-key.pem
$ certtool --generate-proxy --load-ca-privkey key.pem \
--load-privkey proxy-key.pem --load-certificate cert.pem \
--outfile proxy-cert.pem
@end example
@subheading Certificate revocation list generation
To create an empty Certificate Revocation List (CRL) do:
@example
$ certtool --generate-crl --load-ca-privkey x509-ca-key.pem \
--load-ca-certificate x509-ca.pem
@end example
To create a CRL that contains some revoked certificates, place the
certificates in a file and use @code{--load-certificate} as follows:
@example
$ certtool --generate-crl --load-ca-privkey x509-ca-key.pem \
--load-ca-certificate x509-ca.pem --load-certificate revoked-certs.pem
@end example
To verify a Certificate Revocation List (CRL) do:
@example
$ certtool --verify-crl --load-ca-certificate x509-ca.pem < crl.pem
@end example
_EOT_;
};
doc-section = {
ds-type = 'FILES';
ds-format = 'texi';
ds-text = <<-_EOT_
@subheading Certtool's template file format
A template file can be used to avoid the interactive questions of
certtool. Initially create a file named 'cert.cfg' that contains the information
about the certificate. The template can be used as below:
@example
$ certtool --generate-certificate --load-privkey key.pem \
--template cert.cfg --outfile cert.pem \
--load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem
@end example
An example certtool template file that can be used to generate a certificate
request or a self signed certificate follows.
@example
# X.509 Certificate options
#
# DN options
# The organization of the subject.
organization = "Koko inc."
# The organizational unit of the subject.
unit = "sleeping dept."
# The locality of the subject.
# locality =
# The state of the certificate owner.
state = "Attiki"
# The country of the subject. Two letter code.
country = GR
# The common name of the certificate owner.
cn = "Cindy Lauper"
# A user id of the certificate owner.
#uid = "clauper"
# Set domain components
#dc = "name"
#dc = "domain"
# If the supported DN OIDs are not adequate you can set
# any OID here.
# For example set the X.520 Title and the X.520 Pseudonym
# by using OID and string pairs.
#dn_oid = 2.5.4.12 Dr.
#dn_oid = 2.5.4.65 jackal
# This is deprecated and should not be used in new
# certificates.
# pkcs9_email = "none@@none.org"
# An alternative way to set the certificate's distinguished name directly
# is with the "dn" option. The attribute names allowed are:
# C (country), street, O (organization), OU (unit), title, CN (common name),
# L (locality), ST (state), placeOfBirth, gender, countryOfCitizenship,
# countryOfResidence, serialNumber, telephoneNumber, surName, initials,
# generationQualifier, givenName, pseudonym, dnQualifier, postalCode, name,
# businessCategory, DC, UID, jurisdictionOfIncorporationLocalityName,
# jurisdictionOfIncorporationStateOrProvinceName,
# jurisdictionOfIncorporationCountryName, XmppAddr, and numeric OIDs.
#dn = "cn=Nik,st=Attiki,C=GR,surName=Mavrogiannopoulos,2.5.4.9=Arkadias"
# The serial number of the certificate
# Comment the field for a time-based serial number.
serial = 007
# In how many days, counting from today, this certificate will expire.
# Use -1 if there is no expiration date.
expiration_days = 700
# Alternatively you may set concrete dates and time. The GNU date string
# formats are accepted. See:
# http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html
#activation_date = "2004-02-29 16:21:42"
#expiration_date = "2025-02-29 16:24:41"
# X.509 v3 extensions
# A dnsname in case of a WWW server.
#dns_name = "www.none.org"
#dns_name = "www.morethanone.org"
# A subject alternative name URI
#uri = "http://www.example.com"
# An IP address in case of a server.
#ip_address = "192.168.1.1"
# An email in case of a person
email = "none@@none.org"
# Challenge password used in certificate requests
challenge_password = 123456
# Password when encrypting a private key
#password = secret
# An URL that has CRLs (certificate revocation lists)
# available. Needed in CA certificates.
#crl_dist_points = "http://www.getcrl.crl/getcrl/"
# Whether this is a CA certificate or not
#ca
# for microsoft smart card logon
# key_purpose_oid = 1.3.6.1.4.1.311.20.2.2
### Other predefined key purpose OIDs
# Whether this certificate will be used for a TLS client
#tls_www_client
# Whether this certificate will be used for a TLS server
#tls_www_server
# Whether this certificate will be used to sign data (needed
# in TLS DHE ciphersuites).
signing_key
# Whether this certificate will be used to encrypt data (needed
# in TLS RSA ciphersuites). Note that it is preferred to use different
# keys for encryption and signing.
encryption_key
# Whether this key will be used to sign other certificates.
#cert_signing_key
# Whether this key will be used to sign CRLs.
#crl_signing_key
# Whether this key will be used to sign code.
#code_signing_key
# Whether this key will be used to sign OCSP data.
#ocsp_signing_key
# Whether this key will be used for time stamping.
#time_stamping_key
# Whether this key will be used for IPsec IKE operations.
#ipsec_ike_key
### end of key purpose OIDs
# When generating a certificate from a certificate
# request, then honor the extensions stored in the request
# and store them in the real certificate.
#honor_crq_extensions
# Path length contraint. Sets the maximum number of
# certificates that can be used to certify this certificate.
# (i.e. the certificate chain length)
#path_len = -1
#path_len = 2
# OCSP URI
# ocsp_uri = http://my.ocsp.server/ocsp
# CA issuers URI
# ca_issuers_uri = http://my.ca.issuer
# Certificate policies
# policy1 = 1.3.6.1.4.1.5484.1.10.99.1.0
# policy1_txt = "This is a long policy to summarize"
# policy1_url = http://www.example.com/a-policy-to-read
# policy2 = 1.3.6.1.4.1.5484.1.10.99.1.1
# policy2_txt = "This is a short policy"
# policy2_url = http://www.example.com/another-policy-to-read
# Options for proxy certificates
# proxy_policy_language = 1.3.6.1.5.5.7.21.1
# Options for generating a CRL
# next CRL update will be in 43 days (wow)
#crl_next_update = 43
# this is the 5th CRL by this CA
#crl_number = 5
@end example
_EOT_;
};
|