-
Notifications
You must be signed in to change notification settings - Fork 8
/
tls-ca-manage.sh
executable file
·2699 lines (2440 loc) · 94.8 KB
/
tls-ca-manage.sh
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# TODO: Add:
# 0.domainComponent = "org"
# 1.domainComponent = "simple"
# to "[req_dn]" of "intermediate_ca.cnf"
execute() {
if [[ "$VERBOSITY" -ge 1 || -n "$DRY_RUN" ]]; then
echo "COMMAND: $@"
fi
if [ -z "$DRY_RUN" ]; then
$@
return $?
fi
}
# NAME
# tls-ca-manage.sh - Manage Root and Intermediate Certificate Authorities
#
# SYNOPSIS
# tls-ca-manage.sh [OPTION]... create [CA-NAME]
# tls-ca-manage.sh [OPTION]... verify [CA-NAME]
# tls-ca-manage.sh [OPTION]... renew [CA-NAME]
# tls-ca-manage.sh [OPTION]... revoke [CA-NAME]
#
# DESCRIPTION
# A front-end tool to OpenSSL that enables creation, renewal,
# revocation, and verification of Certificate Authorities (CA).
#
# CA can be Root CA or Intermediate CA.
#
# Mandatory arguments to long options are mandatory for
# short options too.
#
# -a, --algorithm
# Selects the cipher algorithm.
# Valid algorithms are: rsa, ecdsa, poly1305 OR ed25519
# These value are case-sensitive.
# If no algorithm specified, then RSA is used by default.
#
# -b, --base-dir
# The top-level directory of SSL, typically /etc/ssl
# Useful for testing this command in non-root shell
# or maintaining SSL certs elsewhere (other than /etc/ssl).
#
# -c, --cipher
# Specify the encryption method of the PEM key file in
# which to protect the key with. Default is plaintext file.
#
# -f, --force-delete
# Forces deletion of its specified CA's configuration file
# as pointed to by CA-NAME argument.
#
# -g, --group
# Use this Unix group name for all files created or updated.
# Default is ssl-cert group.
#
# -h, --help
#
# -i, --intermediate-node [TODO]
# Makes this CA the intermediate node where additional CA(s)
# can be branched from this CA. Root CA is also an intermediate
# node but top-level, self-signed intermediate node.
#
# Not specifying --intermediate-node option means that this CA
# cannot borne any additional CA branches and can only sign
# other certificates.
#
# Dictacts the presence of 'pathlen=0' in basicConstraints
# during the CA Certificate Request stage.
#
# Not specifying --parent-ca and not specifying --intermediate-node
# means this certificate is a self-signed standalone
# test certificate which cannot sign any other certificate.
#
# If --intermediate-node and no --parent-ca, creates your Root CA.
#
# -k, --key-size
# Specifies the number of bits in the key. The choice of key
# size depends on the algorithm (-a) used.
# The key size does not need to be specified if using a default
# algorithm. The default key size is 4096 bits.
#
# Key size for ed25519 algorithm gets ignored here.
# Valid poly1305 key sizes are:
# Valid rsa key sizes are: 4096, 2048, 1024 or 512.
# Valid ecdsa key sizes are: 521, 384, 256, 224 or 192.
#
# -m, --message-digest
# blake2b512 blake2s256 gost md4
# md5 rmd160 sha1 sha224
# sha256 sha3-224 sha3-256 sha3-384
# sha3-512 sha384 sha512 sha512-224
# sha512-256 shake128 shake256 sm3
#
# -n, --nested-ca
# First chaining of first-level CAs are placed in subdirectory inside
# its Root CA directory, and subsequent chaining of second-level CA
# get nesting also in subdirectory inside its respective Intermediate
# CA directory. Very few organizations use this.
#
# -p, --parent-ca
# Specifies the Parent CA name. It may often be the Root CA name
# or sometimes the Intermediate CA name. The Parent CA name is
# the same CA-NAME used when creating the parent CA.
#
# -r, --reason
# Specifies the reason for the revocation.
# The value can be one of the following: unspecified,
# keyCompromise, CACompromise, affiliationChanged,
# superseded, cessationOfOperation, certificateHold,
# and removeFromCRL. (from RFC5280)
# Used only with 'revoke' command
#
# -s, --serial
# Specifies the starting serial ID number to use in the certificate.
# The default serial ID is 1000 HEXI-decimal. Format of number are
# stored and handled in hexidecimal format of even number length.
#
# -t, --ca-type
# Specifies the type of CA node that this is going to be:
#
# root - Top-most Root node of CA tree
# intermediate - Middle node of CA tree
# security - Signing CA for security plant
# component - Generic signing CA for network
# network - Generic signing CA for network
# End-nodes are:
# standalone - self-signed test certificate
# server - TLS server: Web server, MTA, VPN, IMAP, POP3, 802.1ar
# client - TLS client:
# ocsp - OCSP
# email - Encryption part of SMTP body
# identity - Signing CA for Microsoft SmartCard identity
# encryption - Microsoft Encrypted File System (msEFS)
# codesign - Signed executable code
# timestamping - ANSI X9.95 TimeStamping (RFC3161)
#
# -T, --traditional
# Indicates the standard OpenSSL directory layout.
# Default is to use the new centralized directory layout.
#
# -v, --verbosity
# Sets the debugging level.
#
# [ --base-dir|-b <ssl-directory-path> ]
# [ --algorithm|-a [rsa|ed25519|ecdsa|poly1305] ]
# [ --message-digest|-m [sha512|sha384|sha256|sha224|sha3-256|
# sha3-224|sha3-512|sha1|md5] ]
# [ --keysize|-k [4096, 2048, 1024, 512, 256] ]
# [ --serial|-s <num> ] # (default: $DEFAULT_SERIAL_ID_HEX)
# [ --group|-g <group-name> ] # (default: $DEFAULT_GROUP_NAME)
# [ --openssl|-o <openssl-binary-filespec> ] # (default: $OPENSSL)
# [ --parent-ca|-p ] [ --traditional|-t ]
# < create | renew | revoke | verify | help >
# <ca-name>
#
# Description:
# tls-ca-manage.sh
#
# Create a top-level or intermediate certificate authority (CA)
#
#
# Makes one assumption: that the openssl.cnf is ALWAYS the filename (never tweaked)
# Just that different directory has different openssl.cnf
#
# Enforces 'ssl-cert' group; and requires all admins to have 'ssl-cert'
# group when using this command
# DO NOT be giving 'ssl-cert' group to server daemons' supplemental
# group ID (or worse, as its group ID);
# for that, you copy the certs over to app-specific directory and use
# THAT app's file permissions.
# This command does not deal with distribution of certificates, just
# creation/renewal/revokation of therein.
# 'ssl-cert' group means 'working with SSL/TLS certificates,
# not just reading certs'.
#
# Inspired by: https://jamielinux.com/docs/openssl-certificate-authority/create-the-root-pair.html
#
# Components:
# Public Key Infrastructure (PKI)
# Security architecture where trust is conveyed through the signature of a trusted CA.
# Certificate Authority (CA)
# Entity issuing certificates and CRLs.
# Registration Authority (RA)
# Entity handling PKI enrollment. May be identical with the CA.
# Certificate
# Public key and ID bound by a CA signature.
# Certificate Signing Request (CSR)
# Request for certification. Contains public key and ID to be certified.
# Certificate Revocation List (CRL)
# List of revoked certificates. Issued by a CA at regular intervals.
# Certification Practice Statement (CPS)
# Document describing structure and processes of a CA.
#
# CA Types:
# Root CA
# CA at the root of a PKI hierarchy. Issues only CA certificates.
# Intermediate CA
# CA below the root CA but not a signing CA. Issues only CA certificates.
# Signing CA
# CA at the bottom of a PKI hierarchy. Issues only user certificates.
#
# Certificate Types:
#
# CA Certificate
# Certificate of a CA. Used to sign certificates and CRLs.
# Root Certificate
# Self-signed CA certificate at the root of a PKI hierarchy. Serves as the
# PKI’s trust anchor.
# Cross Certificate
# CA certificate issued by a CA external to the primary PKI hierarchy.
# Used to connect two PKIs and thus usually comes in pairs.
# User Certificate
# End-user certificate issued for one or more purposes: email-protection, server-auth,
# client-auth, code-signing, etc. A user certificate cannot sign other certificates.
#
# File Format:
# Privacy Enhanced Mail (PEM)
# Text format. Base-64 encoded data with header and footer lines. Preferred
# format in OpenSSL and most software based on it (e.g. Apache mod_ssl, stunnel).
#
# Distinguished Encoding Rules (DER)
# Binary format. Preferred format in Windows environments. Also the official
# format for Internet download of certificates and CRLs. (Not used here)
function cmd_show_syntax_usage {
cat << SYNTAX_EOF | more
Usage:
$0 create [options] <ca-name>
$0 renew [options] <ca-name>
$0 revoke [options] <ca-name>
$0 verify [options] <ca-name>
$0 help
ca-name: Simple name of CA in which to sign certificate against with.
Alphanumeric, dash, and underscore characters supported.
options:
[ --parent-ca|-p ] [-t|--ca-type <ca-type>] \
[ --help|-h ] [ --verbosity|-v ] [ --force-delete|-f ]
[ --base-dir|-b <ssl-directory-path> ]
[ --algorithm|-a [rsa|ed25519|ecdsa|poly1305] ]
[ --message-digest|-m [sha512|sha384|sha256|sha224|sha3-256|
sha3-224|sha3-512|sha1|md5] ]
[ --keysize|-k [4096, 2048, 1024, 512, 256] ]
[ --serial|-s <num> ] # (default: $DEFAULT_SERIAL_ID_HEX)
[ --group|-g <group-name> ] # (default: $DEFAULT_GROUP_NAME)
[ --openssl|-o <openssl-binary-filespec ] # (default: $OPENSSL)
[ --traditional|-T ]
[ --dry-run|-d ]
create | renew | revoke | verify | help
<name_of_your_ca>
<ca-type>: standalone, root, intermediate, network, identity, component,
server, client, email, ocsp, timestamping, security, codesign, proxy
Default settings:
Top-level SSL directory: $DEFAULT_SSL_DIR Cipher: $DEFAULT_PEER_SIGNATURE
Digest: $DEFAULT_MESSAGE_DIGEST Keysize: $DEFAULT_KEYSIZE_BITS
SYNTAX_EOF
exit 1
}
# Create a top-level or intermediate certificate authority (CA)
#
# Complete with all directories and file protections
#
# LFS/FSSTD: Single directory for all CA (or a directory for each CA depth?)
# Default values (tweakable)
# DEFAULT_CIPHER="des-ede3-cbc"
DEFAULT_CIPHER=
DEFAULT_CIPHER_FILE="${DEFAULT_CIPHER_FILE:-/tmp/openssl-pass.tmp}"
DEFAULT_CMD_MODE="verify"
DEFAULT_GROUP_NAME="ssl-cert"
DEFAULT_KEYSIZE_BITS=4096
DEFAULT_MESSAGE_DIGEST="sha256"
# shellcheck disable=SC2230
DEFAULT_OPENSSL=$(which openssl)
DEFAULT_PEER_SIGNATURE="rsa"
DEFAULT_SERIAL_ID_HEX=1000
DEFAULT_SSL_DIR="/etc/ssl"
DEFAULT_VERBOSITY=0
DEFAULT_USER_NAME=${USER} # tells most IDE syntax checker to say that $USER is defined
# No DEFAULT_ROOT_CA_NAME
# DEFAULT_INT_CA_NAME="network"
# DEFAULT_SIGNING_CA_NAME="component"
DEFAULT_NODE_TYPE="standalone"
DEFAULT_CA_EXTEND_DAYS="${DEFAULT_CA_EXTEND_DAYS:-1095}"
DEFAULT_FILETYPE_KEY="key" # sometimes .private
DEFAULT_FILETYPE_CSR="csr" # sometimes .req, .request (PKCS#10)
DEFAULT_FILETYPE_CERT="crt" # sometimes .pem, .cert, .cer (PKCS#7)
DEFAULT_FILETYPE_CRL="crl" # sometimes .revoke
# DEFAULT_FILETYPE_PFX="pfx" # sometimes .p12 (PKCS#12)
DEFAULT_OFSTD_LAYOUT="centralized"
DEFAULT_OFSTD_DIR_TREE_TYPE="flat"
DEF_DOMAIN="example.invalid"
DEFAULT_CA_X509_COUNTRY="US"
DEFAULT_CA_X509_STATE=""
DEFAULT_CA_X509_LOCALITY=""
DEFAULT_CA_X509_COMMON="ACME Internal Root CA A1"
DEFAULT_CA_X509_ORG="ACME Networks"
DEFAULT_CA_X509_OU="Trust Division"
DEFAULT_CA_X509_EMAIL="ca.example@${DEF_DOMAIN}"
# Do not use HTTPS in X509_CRL (Catch-22)
DEFAULT_CA_X509_CRL="http://${DEF_DOMAIN}/ca/example-crl.$DEFAULT_FILETYPE_CERT"
DEFAULT_CA_X509_URL_BASE="http://${DEF_DOMAIN}/ca"
#shellcheck disable=SC2034
DEFAULT_CA_X509_URL_OCSP="${DEFAULT_CA_X509_URL_BASE}:9080/ocsp"
DEFAULT_INTCA_X509_COUNTRY="US"
DEFAULT_INTCA_X509_STATE=""
DEFAULT_INTCA_X509_LOCALITY=""
DEFAULT_INTCA_X509_COMMON="ACME Internal Intermediate CA B2"
DEFAULT_INTCA_X509_ORG="ACME Networks"
DEFAULT_INTCA_X509_OU="Semi-Trust Department"
DEFAULT_INTCA_X509_EMAIL="[email protected]"
DEFAULT_INTCA_X509_URL_BASE="http://${DEF_DOMAIN}/ca"
DEFAULT_INTCA_X509_CRL="http://${DEF_DOMAIN}/ca/${CERT_CRL_FNAME}.$DEFAULT_FILETYPE_CERT"
#shellcheck disable=SC2034
DEFAULT_INTCA_X509_URL_OCSP="${DEFAULT_CA_X509_URL_BASE}:9080/ocsp"
function input_x509_data {
PROMPT="$1"
DEFAULT_VALUE="$2"
echo -n "$PROMPT (default: '$DEFAULT_VALUE'): "
read -r INPUT_DATA
if [[ -z "$INPUT_DATA" ]]; then
if [[ -z "$DEFAULT_VALUE" ]]; then
INPUT_DATA="none"
else
INPUT_DATA="$DEFAULT_VALUE"
fi
fi
return
}
function directory_file_layout {
# directory_file_layout arguments:
# $1 - Single CA directory Layout (traditional or centralized)
# $2 - Multiple CA layout (flat or nested)
# $3 - Starting OpenSSL directory
# $4 - current issuing authority simplified filename
# [ $5 - parent issuing authority simplified filename ]
OFSTD_LAYOUT="$1" # traditional | centralized
OFSTD_DIR_TREE_TYPE="$2" # hierarchy | flat
SSL_DIR="$3"
IA_NAME="$4"
PARENT_IA_NAME="$5"
PRIVATE_DNAME="private"
CERTS_DNAME="certs"
CRL_DNAME="crl"
DB_DNAME="db"
NEWCERTS_DNAME="newcerts"
if [[ "$OFSTD_LAYOUT" == "traditional" ]]; then
# Template filename
SSL_SUBDIR_DNAME=""
DIRNAME_PREFIX="ca-"
DIRNAME_SUFFIX=""
FILENAME_PREFIX="ca."
X509_PREFIX="ca_"
FILENAME_SUFFIX=""
X509_SUFFIX=""
PEM_FILETYPE_SUFFIX=".pem"
SSL_CA_DIR="${SSL_DIR}"
elif [[ "$OFSTD_LAYOUT" == "centralized" ]]; then
# Template filename
SSL_SUBDIR_DNAME="ca"
DIRNAME_PREFIX=""
DIRNAME_SUFFIX="-ca"
FILENAME_PREFIX=""
X509_PREFIX=""
FILENAME_SUFFIX="-ca"
X509_SUFFIX="_ca"
PEM_FILETYPE_SUFFIX=""
SSL_CA_DIR="${SSL_DIR}/${SSL_SUBDIR_DNAME}"
else
echo "Invalid parameter 1 (must be 'traditional' or 'centralized')"
exit 2
fi
# Can reuse 'root' as intermediate name, so we can't peg by-name here
# Create NO_PARENT flag to track top-level CA usage
if [[ -z ${PARENT_IA_NAME} ]]; then
# root CA
NO_PARENT=1
PARENT_TYPE_STR="Parent CA"
PARENT_IA_NAME="$IA_NAME"
else
# intermediate
NO_PARENT=0
PARENT_TYPE_STR="Intermediate CA"
fi
if [[ "$VERBOSITY" -ne 0 ]]; then
echo "NODE_TYPE: $NODE_TYPE"
echo "PARENT_TYPE_STR: $PARENT_TYPE_STR"
echo "PARENT_IA_NAME: $PARENT_IA_NAME"
fi
if [[ "$VERBOSITY" -gt 1 ]]; then
echo "IA_NAME: $IA_NAME"
fi
if [[ "$OFSTD_DIR_TREE_TYPE" == "flat" ]]; then
# Inspired by readthedocs
echo ""
IA_FNAME="${FILENAME_PREFIX}${IA_NAME}${FILENAME_SUFFIX}"
IA_SNAME="${X509_PREFIX}${IA_NAME}${X509_SUFFIX}"
PARENT_IA_FNAME="${FILENAME_PREFIX}${PARENT_IA_NAME}${FILENAME_SUFFIX}"
PARENT_IA_SNAME="${X509_PREFIX}${PARENT_IA_NAME}${X509_SUFFIX}"
IA_PATH_FNAME="${DIRNAME_PREFIX}${IA_NAME}${DIRNAME_SUFFIX}"
PARENT_IA_PATH_FNAME="${DIRNAME_PREFIX}${PARENT_IA_NAME}${DIRNAME_SUFFIX}"
IA_DIR="$SSL_CA_DIR/$IA_PATH_FNAME"
PARENT_IA_DIR="$SSL_CA_DIR/$PARENT_IA_PATH_FNAME"
elif [[ "$OFSTD_DIR_TREE_TYPE" == "hierarchy" ]]; then
# Inspired by traditional OpenSSL
IA_FNAME="${FILENAME_PREFIX}${IA_NAME}${FILENAME_SUFFIX}"
IA_SNAME="${X509_PREFIX}${IA_NAME}${X509_SUFFIX}"
PARENT_IA_FNAME="${FILENAME_PREFIX}${PARENT_IA_NAME}${FILENAME_SUFFIX}"
PARENT_IA_SNAME="${X509_PREFIX}${PARENT_IA_NAME}${X509_SUFFIX}"
IA_PATH_FNAME="${DIRNAME_PREFIX}${IA_NAME}${DIRNAME_SUFFIX}"
PARENT_IA_PATH_FNAME="${DIRNAME_PREFIX}${PARENT_IA_NAME}${DIRNAME_SUFFIX}"
# If the parent and child names are the same, we'll assume
if [[ ${NO_PARENT} -eq 1 ]]; then
# Flatten this CA dir
IA_DIR="$SSL_CA_DIR/$IA_PATH_FNAME"
else
IA_DIR="$SSL_CA_DIR/$PARENT_IA_PATH_FNAME/$IA_PATH_FNAME"
fi
PARENT_IA_DIR="$SSL_CA_DIR/$PARENT_IA_PATH_FNAME"
else
echo "Invalid parameter 2 (must be 'flat' or 'nested')"
exit 1
fi
if [[ "$VERBOSITY" -gt 1 ]]; then
echo "OFSTD_LAYOUT: $OFSTD_LAYOUT"
echo "OFSTD_DIR_TREE_TYPE: $OFSTD_DIR_TREE_TYPE"
echo "SSL_CA_DIR: $SSL_CA_DIR"
echo "IA_FNAME: $IA_FNAME"
echo "PARENT_IA_FNAME: $PARENT_IA_FNAME"
echo "IA_DIR: $IA_DIR"
echo "PARENT_IA_DIR: $PARENT_IA_DIR"
fi
IA_DB_DNAME="$DB_DNAME"
# Define full dirspec paths for all the things associated with this issuing authority (IA)
if [[ "$OFSTD_LAYOUT" == "traditional" ]]; then
IA_SERIAL_FNAME="serial"
IA_INDEX_FNAME="index.txt"
IA_CRLNUMBER_FNAME="crlnumber"
PARENT_IA_KEY_DIR="$PARENT_IA_DIR/$PRIVATE_DNAME"
IA_KEY_DIR="$IA_DIR/$PRIVATE_DNAME"
IA_CERTS_DIR="$IA_DIR/$CERTS_DNAME"
PARENT_IA_CERTS_DIR="$PARENT_IA_DIR/$CERTS_DNAME"
IA_CSR_DIR="$IA_DIR"
IA_CRL_DIR="$IA_DIR/$CRL_DNAME"
IA_CHAIN_DIR="$IA_DIR"
PARENT_IA_CHAIN_DIR="$PARENT_IA_DIR"
IA_EXT_DIR="$IA_DIR"
PARENT_IA_EXT_DIR="$PARENT_IA_DIR"
IA_DB_DIR="$IA_DIR"
PARENT_IA_DB_DIR="$PARENT_IA_DIR"
IA_NEWCERTS_ARCHIVE_DIR="$IA_DIR/$NEWCERTS_DNAME"
PARENT_IA_NEWCERTS_ARCHIVE_DIR="$PARENT_IA_DIR/$NEWCERTS_DNAME"
IA_INDEX_DB_DIR="$IA_DB_DIR"
PARENT_IA_INDEX_DB_DIR="$PARENT_IA_DB_DIR"
IA_SERIAL_DB_DIR="$IA_DB_DIR"
PARENT_IA_SERIAL_DB_DIR="$PARENT_IA_DB_DIR"
IA_CRL_DB_DIR="$IA_DB_DIR"
PARENT_IA_CRL_DB_DIR="$PARENT_IA_DB_DIR"
IA_OPENSSL_CNF_FNAME="openssl.cnf"
PARENT_IA_OPENSSL_CNF_FNAME="$IA_OPENSSL_CNF_FNAME"
IA_OPENSSL_CNF="$IA_EXT_DIR/$IA_OPENSSL_CNF_FNAME"
PARENT_IA_OPENSSL_CNF="$PARENT_IA_EXT_DIR/$PARENT_IA_OPENSSL_CNF_FNAME"
else
PARENT_IA_KEY_DIR="$PARENT_IA_DIR/$PRIVATE_DNAME"
IA_KEY_DIR="$IA_DIR/$PRIVATE_DNAME"
IA_CERTS_DIR="$SSL_CA_DIR"
PARENT_IA_CERTS_DIR="$SSL_CA_DIR"
IA_CSR_DIR="$SSL_CA_DIR"
IA_CRL_DIR="$SSL_DIR/$CRL_DNAME"
IA_CHAIN_DIR="$SSL_CA_DIR"
PARENT_IA_CHAIN_DIR="$SSL_CA_DIR"
IA_EXT_DIR="$SSL_DIR/etc"
PARENT_IA_EXT_DIR="$IA_EXT_DIR"
IA_DB_DIR="$IA_DIR/$IA_DB_DNAME"
PARENT_IA_DB_DIR="$PARENT_IA_DIR/$IA_DB_DNAME"
IA_NEWCERTS_ARCHIVE_DIR="$IA_DIR" # where those 000x.pem files go
PARENT_IA_NEWCERTS_ARCHIVE_DIR="$PARENT_IA_DIR" # where those 000x.pem files go
IA_INDEX_DB_DIR="$IA_DIR/$IA_DB_DNAME"
PARENT_IA_INDEX_DB_DIR="$PARENT_IA_DIR/$IA_DB_DNAME"
IA_SERIAL_DB_DIR="$IA_DIR/$IA_DB_DNAME"
PARENT_IA_SERIAL_DB_DIR="$PARENT_IA_DIR/$IA_DB_DNAME"
IA_CRL_DB_DIR="$IA_DIR/$IA_DB_DNAME"
PARENT_IA_CRL_DB_DIR="$PARENT_IA_DIR/$IA_DB_DNAME"
IA_OPENSSL_CNF_FNAME="$IA_FNAME.cnf"
PARENT_IA_OPENSSL_CNF_FNAME="$PARENT_IA_FNAME.cnf"
IA_OPENSSL_CNF="$IA_EXT_DIR/$IA_OPENSSL_CNF_FNAME"
PARENT_IA_OPENSSL_CNF="$PARENT_IA_EXT_DIR/$PARENT_IA_OPENSSL_CNF_FNAME"
fi
if [[ "$VERBOSITY" -gt 1 ]]; then
echo "IA_SERIAL_FNAME: $IA_SERIAL_FNAME"
echo "IA_INDEX_FNAME: $IA_INDEX_FNAME"
echo "IA_CRLNUMBER_FNAME: $IA_CRLNUMBER_FNAME"
echo "NO_PARENT: $NO_PARENT"
echo "PARENT_IA_KEY_DIR: $PARENT_IA_KEY_DIR"
echo "IA_KEY_DIR: $IA_KEY_DIR"
echo "IA_CERTS_DIR: $IA_CERTS_DIR"
echo "PARENT_IA_CERTS_DIR: $PARENT_IA_CERTS_DIR"
echo "IA_CSR_DIR: $IA_CSR_DIR"
echo "IA_CRL_DIR: $IA_CRL_DIR"
echo "IA_CHAIN_DIR: $IA_CHAIN_DIR"
echo "PARENT_IA_CHAIN_DIR: $PARENT_IA_CHAIN_DIR"
echo "IA_EXT_DIR: $IA_EXT_DIR"
echo "IA_DB_DIR: $IA_DB_DIR"
echo "PARENT_IA_DB_DIR: $IA_DB_DIR"
echo "IA_NEWCERTS_ARCHIVE_DIR: $IA_NEWCERTS_ARCHIVE_DIR"
echo "PARENT_IA_NEWCERTS_ARCHIVE_DIR: $PARENT_IA_NEWCERTS_ARCHIVE_DIR"
echo "IA_INDEX_DB_DIR: $IA_INDEX_DB_DIR"
echo "IA_SERIAL_DB_DIR: $IA_SERIAL_DB_DIR"
echo "IA_CRL_DB_DIR: $IA_CRL_DB_DIR"
echo "IA_OPENSSL_CNF: $IA_OPENSSL_CNF"
echo "PARENT_IA_OPENSSL_CNF: $PARENT_IA_OPENSSL_CNF"
fi
if [[ "$OFSTD_LAYOUT" == "traditional" ]]; then
#PARENT_IA_FNAME_PREFIX="$FILENAME_PREFIX$PARENT_IA_NAME$FILENAME_SUFFIX"
PARENT_IA_FNAME_PREFIX="cakey" # It's in another directory
# IA_FNAME_PREFIX="$FILENAME_PREFIX$IA_NAME$FILENAME_SUFFIX"
IA_FNAME_PREFIX="cakey"
# Traditional CSR is user-defined, we automate it here
CSR_FNAME_PREFIX="ca-csr"
CERT_FNAME_PREFIX="cacert"
IA_SERIAL_FNAME="serial"
IA_INDEX_FNAME="index.txt"
IA_CRLNUMBER_FNAME="crlnumber"
PARENT_IA_SERIAL_FNAME="serial"
PARENT_IA_INDEX_FNAME="index.txt"
PARENT_IA_CRLNUMBER_FNAME="crlnumber"
CRL_FNAME_PREFIX="crl"
CHAIN_FILENAME_MID=".chain"
CHAIN_FILETYPE_SUFFIX=".pem"
# CHAIN_FNAME_PREFIX="$FILENAME_PREFIX$IA_NAME$CHAIN_FILENAME_MID$CHAIN_FILENAME_SUFFIX"
CHAIN_FNAME_PREFIX="$FILENAME_PREFIX$IA_NAME$FILENAME_SUFFIX$CHAIN_FILENAME_MID"
PARENT_CHAIN_FNAME_PREFIX="$FILENAME_PREFIX$PARENT_IA_NAME$FILENAME_SUFFIX$CHAIN_FILENAME_MID"
PARENT_IA_KEY_FNAME="${PARENT_IA_FNAME_PREFIX}${PEM_FILETYPE_SUFFIX}"
IA_KEY_FNAME="${IA_FNAME_PREFIX}${PEM_FILETYPE_SUFFIX}"
else
FFNAME_KEY="$FILENAME_SUFFIX.$DEFAULT_FILETYPE_KEY" # '-ca.key'
FFNAME_CSR="$FILENAME_SUFFIX.$DEFAULT_FILETYPE_CSR" # '-ca.csr'
FFNAME_CERT="$FILENAME_SUFFIX.$DEFAULT_FILETYPE_CERT" # '-ca.crt'
FFNAME_CRL="$FILENAME_SUFFIX.$DEFAULT_FILETYPE_CRL" # '-ca.crl'
PARENT_IA_FNAME_PREFIX="$FILENAME_PREFIX$PARENT_IA_NAME$FFNAME_KEY"
IA_FNAME_PREFIX="$FILENAME_PREFIX$IA_NAME$FFNAME_KEY"
CSR_FNAME_PREFIX="$FILENAME_PREFIX$IA_NAME$FFNAME_CSR"
CRL_FNAME_PREFIX="$FILENAME_PREFIX$IA_NAME$FFNAME_CRL"
CERT_FNAME_PREFIX="$FILENAME_PREFIX$IA_NAME$FFNAME_CERT"
PARENT_CERT_FNAME_PREFIX="$FILENAME_PREFIX$PARENT_IA_NAME$FFNAME_CERT"
IA_KEY_FNAME="${IA_FNAME_PREFIX}${PEM_FILETYPE_SUFFIX}"
IA_SERIAL_FNAME="$FILENAME_PREFIX$IA_NAME$FFNAME_CERT.srl"
IA_INDEX_FNAME="$FILENAME_PREFIX$IA_NAME$FILENAME_SUFFIX.$DB_DNAME"
IA_CRLNUMBER_FNAME="$FILENAME_PREFIX$IA_NAME$FFNAME_CRL.srl"
CHAIN_FILENAME_MID="-chain"
CHAIN_FILETYPE_SUFFIX=".pem"
CHAIN_FNAME_PREFIX="$FILENAME_PREFIX$IA_NAME$FILENAME_SUFFIX$CHAIN_FILENAME_MID"
PARENT_CHAIN_FNAME_PREFIX="$FILENAME_PREFIX$PARENT_IA_NAME$FILENAME_SUFFIX$CHAIN_FILENAME_MID"
PARENT_IA_KEY_FNAME="${PARENT_IA_FNAME_PREFIX}${PEM_FILETYPE_SUFFIX}"
PARENT_IA_SERIAL_FNAME="$FILENAME_PREFIX$PARENT_IA_NAME$FFNAME_CRL.srl"
PARENT_IA_INDEX_FNAME="$FILENAME_PREFIX$PARENT_IA_NAME$FILENAME_SUFFIX.$DB_DNAME"
PARENT_IA_CRLNUMBER_FNAME="$FILENAME_PREFIX$PARENT_IA_NAME$FFNAME_CRL.srl"
fi
IA_CSR_FNAME="${CSR_FNAME_PREFIX}${PEM_FILETYPE_SUFFIX}"
IA_CERT_FNAME="${CERT_FNAME_PREFIX}${PEM_FILETYPE_SUFFIX}"
PARENT_IA_CERT_FNAME="${PARENT_CERT_FNAME_PREFIX}${PEM_FILETYPE_SUFFIX}"
IA_CRL_FNAME="${CRL_FNAME_PREFIX}${PEM_FILETYPE_SUFFIX}"
IA_CHAIN_FNAME="${CHAIN_FNAME_PREFIX}${CHAIN_FILETYPE_SUFFIX}"
PARENT_IA_CHAIN_FNAME="${PARENT_CHAIN_FNAME_PREFIX}${CHAIN_FILETYPE_SUFFIX}"
if [[ "$VERBOSITY" -gt 1 ]]; then
echo "PARENT_IA_KEY_FNAME: $PARENT_IA_KEY_FNAME"
echo "IA_KEY_FNAME: $IA_KEY_FNAME"
echo "IA_CSR_FNAME: $IA_CSR_FNAME"
echo "IA_CERT_FNAME: $IA_CERT_FNAME"
echo "PARENT_IA_CERT_FNAME: $PARENT_IA_CERT_FNAME"
echo "IA_CRL_FNAME: $IA_CRL_FNAME"
echo "IA_CHAIN_FNAME: $IA_CHAIN_FNAME"
echo "PARENT_IA_CHAIN_FNAME: $PARENT_IA_CHAIN_FNAME"
fi
PARENT_IA_KEY_PEM="$PARENT_IA_KEY_DIR/$PARENT_IA_KEY_FNAME"
IA_KEY_PEM="$IA_KEY_DIR/$IA_KEY_FNAME"
IA_CSR_PEM="$IA_CSR_DIR/$IA_CSR_FNAME"
IA_CERT_PEM="$IA_CERTS_DIR/$IA_CERT_FNAME"
PARENT_IA_CERT_PEM="$PARENT_IA_CERTS_DIR/$PARENT_IA_CERT_FNAME"
IA_CRL_PEM="$IA_CRL_DIR/$IA_CRL_FNAME"
IA_CHAIN_PEM="$IA_CHAIN_DIR/$IA_CHAIN_FNAME"
# PARENT_IA_CHAIN_PEM="$PARENT_IA_CHAIN_DIR/$PARENT_IA_CHAIN_FNAME"
IA_INDEX_DB="$IA_INDEX_DB_DIR/$IA_INDEX_FNAME"
PARENT_IA_INDEX_DB="$PARENT_IA_INDEX_DB_DIR/$PARENT_IA_INDEX_FNAME"
IA_SERIAL_DB="$IA_SERIAL_DB_DIR/$IA_SERIAL_FNAME"
PARENT_IA_SERIAL_DB="$PARENT_IA_SERIAL_DB_DIR/$PARENT_IA_SERIAL_FNAME"
IA_CRL_DB="$IA_CRL_DB_DIR/$IA_CRLNUMBER_FNAME"
PARENT_IA_CRL_DB="$PARENT_IA_CRL_DB_DIR/$PARENT_IA_CRLNUMBER_FNAME"
if [[ "$VERBOSITY" -gt 1 ]]; then
echo "IA_KEY_PEM: $IA_KEY_PEM"
echo "IA_CSR_PEM: $IA_CSR_PEM"
echo "IA_CERT_PEM: $IA_CERT_PEM"
echo "IA_CRL_PEM: $IA_CRL_PEM"
echo "IA_CHAIN_PEM: $IA_CHAIN_PEM"
echo "IA_SERIAL_DB: $IA_SERIAL_DB"
echo "IA_INDEX_DB: $IA_INDEX_DB"
echo "IA_CRL_DB: $IA_CRL_DB"
echo "PARENT_IA_KEY_PEM: $PARENT_IA_KEY_PEM"
# We do not care about PARENT_IA_CSR_PEM file here
echo "PARENT_IA_CERT_PEM: $PARENT_IA_CERT_PEM"
# We do not care about PARENT_IA_CRL_PEM file here
# We do not care about PARENT_IA_CHAIN_PEM file here
echo "PARENT_IA_SERIAL_DB: $PARENT_IA_SERIAL_DB"
echo "PARENT_IA_INDEX_DB: $PARENT_IA_INDEX_DB"
echo "PARENT_IA_CRL_DB: $PARENT_IA_CRL_DB"
fi
IA_SERIAL_DB="$IA_SERIAL_DB_DIR/$IA_SERIAL_FNAME"
}
function change_owner_perm {
local CHOP_USER CHOP_GROUP CHOP_PERM CHOP_FILESPEC
CHOP_USER="$1"
CHOP_GROUP="$2"
CHOP_PERM="$3"
CHOP_FILESPEC="$4"
chown "$CHOP_USER:$CHOP_GROUP" "$CHOP_FILESPEC"
RETSTS=$?
if [[ ${RETSTS} -ne 0 ]]; then
echo "Error $RETSTS setting $CHOP_USER:$CHOP_GROUP owner to $CHOP_FILESPEC; aborting..."
exit ${RETSTS}
fi
chmod "$CHOP_PERM" "$CHOP_FILESPEC"
RETSTS=$?
if [[ ${RETSTS} -ne 0 ]]; then
echo "Error $RETSTS setting $CHOP_USER:$CHOP_GROUP owner to $CHOP_FILESPEC; aborting..."
exit ${RETSTS}
fi
}
function create_ca_directory {
if [[ -e $1 ]]; then
if [[ ! -d $1 ]]; then
echo "ERROR: Path $1 is not a directory; aborting."
exit 1
fi
# Else directory already exist, just keep going
else
[[ ${VERBOSITY} -gt 0 ]] && echo "mkdir $1"
mkdir "$1"
fi
change_owner_perm "$SSL_USER_NAME" "$SSL_GROUP_NAME" 0750 "$1"
}
function touch_ca_file {
local TOUCH_THIS_FILE
TOUCH_THIS_FILE="$1"
if [[ -d ${TOUCH_THIS_FILE} ]]; then
# it does wonder to the file system by touching a directory (EXT4 corruption)
echo "File $TOUCH_THIS_FILE is already directory "
echo "(and untouchable); aborting..."
exit 1
fi
[[ ${VERBOSITY} -gt 0 ]] && echo "touch $TOUCH_THIS_FILE"
touch "$1"
change_owner_perm "$SSL_USER_NAME" "$SSL_GROUP_NAME" 0640 "$TOUCH_THIS_FILE"
}
function delete_dir {
local DELETE_DIR
DELETE_DIR="${1:-/tmp/nope}" # emergency undefined $1 protection
if [[ -d "$DELETE_DIR" ]]; then
[[ ${VERBOSITY} -gt 0 ]] && echo "rm -rf $DELETE_DIR"
rm -rf "$DELETE_DIR"
fi
}
function delete_file {
local DELETE_FILE
DELETE_FILE="${1:-/tmp/nope}" # emergency undefined $1 protection
if [[ -f "$DELETE_FILE" ]]; then
[[ ${VERBOSITY} -gt 0 ]] && echo "rm $DELETE_FILE"
rm "$DELETE_FILE"
fi
}
function delete_ca_config {
delete_file "$IA_OPENSSL_CNF" # loses any user-customization(s)
}
function delete_ca_dirfiles {
delete_file "$IA_KEY_PEM"
delete_file "$IA_CSR_PEM"
delete_file "$IA_CERT_PEM"
delete_file "$IA_CRL_PEM"
delete_file "$IA_CHAIN_PEM"
delete_file "$IA_INDEX_DB"
delete_file "$IA_SERIAL_DB"
delete_file "$IA_CRL_DB"
delete_file "$IA_SERIAL_DB"
delete_file "$IA_SERIAL_DB.old"
delete_file "$IA_INDEX_DB"
delete_file "$IA_INDEX_DB.old"
delete_file "$IA_INDEX_DB.attr"
delete_file "$IA_INDEX_DB"
delete_file "$IA_CRL_DB"
if [[ ${FORCE_DELETE_CONFIG} -eq 1 ]]; then
delete_ca_config
fi
delete_dir "$IA_KEY_DIR"
# Last CA standing
if [[ "$OFSTD_LAYOUT" == "centralized" ]]; then
# Make sure it's our matching IA, otherwise bail.
if [[ -d "$IA_DIR" ]]; then
CA_COUNT=$(find "$SSL_CA_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)
if [[ ${CA_COUNT} -lt 2 ]]; then
delete_dir "$IA_INDEX_DB_DIR"
delete_dir "$IA_SERIAL_DB_DIR"
delete_dir "$IA_DB_DIR"
delete_dir "$IA_CRL_DB_DIR"
delete_dir "$IA_CSR_DIR"
delete_dir "$IA_CERTS_DIR"
delete_dir "$IA_CHAIN_DIR"
delete_dir "$IA_EXT_DIR"
delete_dir "$SSL_CA_DIR"
fi
delete_dir "$IA_DIR"
fi
elif [[ "$OFSTD_LAYOUT" == "traditional" ]]; then
# delete_dir $IA_INDEX_DB_DIR
# delete_dir $IA_SERIAL_DB_DIR
# delete_dir $IA_DB_DIR
# delete_dir $IA_CSR_DIR
delete_dir "$IA_CERTS_DIR"
# delete_dir $IA_CRL_DIR
# delete_dir $IA_CHAIN_DIR
# delete_dir $IA_CRL_DB_DIR
delete_dir "$IA_NEWCERTS_ARCHIVE_DIR"
delete_dir "$IA_DIR"
# delete_dir $IA_EXT_DIR
fi
}
function create_ca_dirfiles {
if [[ ! -e "$SSL_CA_DIR" ]]; then
CREATE_IA_DIR=
echo -n "Create $SSL_CA_DIR subdirectory? (Y/n): "
read -r CREATE_IA_DIR
if [[ "$CREATE_IA_DIR" =~ y|yes|Y|YES ]]; then
mkdir "$SSL_CA_DIR"
RETSTS=$?
[[ ${RETSTS} -ne 0 ]] && echo "Unable to create $SSL_CA_DIR subdirectory; aborting..." && exit 13 # EACCESS
[[ ${VERBOSITY} -ne 0 ]] && echo "Created $SSL_CA_DIR directory"
else
echo "Exiting..."
exit 1
fi
else
if [[ ! -d "$SSL_CA_DIR" ]]; then
echo "File '$SSL_CA_DIR' is not a directory."
exit 1
fi
fi
create_ca_directory "$SSL_CA_DIR"
create_ca_directory "$IA_DIR"
create_ca_directory "$IA_EXT_DIR"
create_ca_directory "$IA_KEY_DIR"
create_ca_directory "$IA_CSR_DIR"
create_ca_directory "$IA_CERTS_DIR"
create_ca_directory "$IA_CRL_DIR"
create_ca_directory "$IA_CHAIN_DIR"
create_ca_directory "$IA_DB_DIR"
create_ca_directory "$IA_INDEX_DB_DIR"
create_ca_directory "$IA_SERIAL_DB_DIR"
create_ca_directory "$IA_CRL_DB_DIR"
create_ca_directory "$IA_NEWCERTS_ARCHIVE_DIR"
touch_ca_file "$IA_SERIAL_DB"
touch_ca_file "$IA_INDEX_DB"
touch_ca_file "$IA_CRL_DB"
}
function data_entry_generic {
INPUT_DATA=
input_x509_data "Organization" "$X509_ORG"
X509_ORG="$INPUT_DATA"
input_x509_data "Org. Unit/Section/Division: " "$X509_OU"
X509_OU="$INPUT_DATA"
input_x509_data "Common Name: " "$X509_COMMON"
X509_COMMON="$INPUT_DATA"
input_x509_data "Country (2-char max.): " "$X509_COUNTRY"
X509_COUNTRY="$INPUT_DATA"
input_x509_data "State: " "$X509_STATE"
X509_STATE="$INPUT_DATA"
input_x509_data "Locality/City: " "$X509_LOCALITY"
X509_LOCALITY="$INPUT_DATA"
input_x509_data "Contact email: " "$X509_EMAIL"
X509_EMAIL="$INPUT_DATA"
input_x509_data "Base URL: " "$X509_URL_BASE"
X509_URL_BASE="$INPUT_DATA"
input_x509_data "CRL URL: " "$X509_CRL"
X509_CRL="$INPUT_DATA"
}
# Usage: get_x509v3_extension_by_ca_type <ca_type> <pathlen>
function get_x509v3_extension_by_ca_type {
local GXEBCT_CA_TYPE GXEBCT_PATHLEN_COUNT
GXEBCT_CA_TYPE=$1
GXEBCT_PATHLEN_COUNT=$2
[[ -n ${GXEBCT_PATHLEN_COUNT} ]] || GXEBCT_PATHLEN_COUNT=-1
if [[ ${GXEBCT_PATHLEN_COUNT} -ge 0 ]]; then
#shellcheck disable=SC2034
GXEBCT_PATHLEN_OPTION=",pathlen:$GXEBCT_PATHLEN_COUNT"
else
#shellcheck disable=SC2034
GXEBCT_PATHLEN_OPTION=""
fi
case "$GXEBCT_CA_TYPE" in
standalone)
CNF_REQ_EXT_BC="critical,CA:true,pathlen:0"
# TODO Gonna need those CNF_REQ_ back in here again
CNF_REQ_EXT_KU="critical,digitalSignature,keyCertSign,cRLSign" # keyUsage
CNF_REQ_EXT_SKI="hash" # subjectKeyIdentifier
CNF_CA_EXT_BC="CA:false,pathlen:0" # basicConstraint
CNF_CA_EXT_SKI="hash" # subjectKeyIdentifier
CNF_CA_EXT_KU="critical,digitalSignature,keyCertSign,cRLSign" # keyUsage
CNF_CA_EXT_AKI="" # authorityKeyIdentifier
CNF_CA_EXT_EKU="" # extendedKeyUsage
CNF_CA_EXT_SAN="" # subjectAltName
CNF_CA_EXT_AIA="@issuer_info"
CNF_CA_EXT_CE="none" # copy_extensions
;;
root)
# CNF_REQ_EXT_BC="critical,CA:true" # never use pathLen= on Root CAs
# digitalSignature MUST be added if Root private key for OCSP responses
# CNF_REQ_EXT_KU="critical,keyCertSign,cRLSign,digitalSignature" # keyUsage
# CNF_REQ_EXT_SKI="hash" # subjectKeyIdentifier
# CNF_REQ_EXT_AKI="keyid:always,issuer" # authorityKeyIdentifier
# CNF_REQ_EXT_EKU="" # No extendedKeyUsage for Root CAs
# root-ca.cnf/[root_ca_ext]
CNF_CA_EXT_BC="critical,CA:true" # never use pathLen= on Root CAs
CNF_CA_EXT_KU="critical,keyCertSign,cRLSign,digitalSignature" # keyUsage
# TODO: User-prompt for the total depth of Intermediate CAs in advance?
CNF_CA_EXT_SKI="hash" # subjectKeyIdentifier
CNF_CA_EXT_AKI="keyid:always,issuer" # authorityKeyIdentifier
CNF_CA_EXT_EKU="" # extendedKeyUsage
CNF_CA_EXT_EKU="" # No extendedKeyUsage for Root CAs
CNF_CA_EXT_SAN="" # subjectAltName
# DO NOT INCLUDE authorityInfoAccess in ROOT CA; causes PRQP lookup-loop
CNF_CA_EXT_AIA=""
# Add @ocsp_info to AIA if Root CA is signing OCSP Responder certs
CNF_CA_EXT_AIA="@ocsp_info"
CNF_CA_EXT_CE="none" # copy_extensions
;;
intermediate)
CNF_REQ_EXT_KU="critical,keyCertSign,cRLSign" # keyUsage
CNF_REQ_EXT_BC="critical,CA:true"
# TODO: Auto-retrieve any 'pahtlen=' from its Root CA, then decrement?
# http://www.pkiglobe.org/
#CNF_CA_EXT_BC="critical,CA:true,pathlen:0" # basicConstraint
CNF_REQ_EXT_SKI="hash" # subjectKeyIdentifier
# root-ca.cnf/[root_ca_ext]
# CNF_CA_EXT_KU="critical,keyCertSign,cRLSign" # keyUsage
# CNF_CA_EXT_BC="critical,CA:true" # basicConstraint
# CNF_CA_EXT_SKI="hash" # subjectKeyIdentifier
# CNF_CA_EXT_AKI="keyid:always" # authorityKeyIdentifier
# CNF_CA_EXT_EKU="" # extendedKeyUsage
# CNF_CA_EXT_SAN="" # subjectAltName
# CNF_CA_EXT_AIA="@issuer_info"
# #shellcheck disable=SC2034
# CNF_CA_EXT_CE="copy" # copy_extensions
;;
# end|endnode|signing|network|software|tls)
# CNF_REQ_EXT_KU="critical,keyCertSign,cRLSign" # keyUsage
# CNF_REQ_EXT_BC="critical,CA:true,pathlen:0"
# CNF_REQ_EXT_SKI="hash" # subjectKeyIdentifier
# # root-ca.cnf/[signing_ca_ext]
# CNF_CA_EXT_KU="critical,keyCertSign,cRLSign" # keyUsage
# CNF_CA_EXT_BC="critical,CA:true,pathlen:0" # basicConstraint
# CNF_CA_EXT_SKI="hash" # subjectKeyIdentifier
# CNF_CA_EXT_AKI="keyid:always" # authorityKeyIdentifier
# CNF_CA_EXT_EKU="" # extendedKeyUsage
# CNF_CA_EXT_SAN="" # subjectAltName
# CNF_CA_EXT_AIA="@issuer_info"
# CNF_CA_EXT_CE="copy" # copy_extensions
# ;;
server)
# Missing the following:
# X509v3 Certificate Policies:
# Policy: 2.23.140.1.2.2
# CPS: https://pki.goog/repository/
CNF_REQ_EXT_KU="critical,keyCertSign,cRLSign" # keyUsage
# No need to auto-retrieve parent CA's pathLen=, this is the end of line
CNF_REQ_EXT_BC="critical,CA:true,pathlen:0"
CNF_REQ_EXT_SKI="hash" # subjectKeyIdentifier
# signing-ca.cnf/[server_ext]
# email-ca.cnf/[server_ext]
# component-ca.cnf/[server_ext]
CNF_CA_EXT_KU="critical,digitalSignature,keyCertSign,cRLSign"
CNF_CA_EXT_BC="CA:true,pathlen:0"
CNF_CA_EXT_SKI="hash" # subjectKeyIdentifier
# CNF_CA_EXT_AKI="keyid,issuer:always" # used in 802.1ar iDevID
CNF_CA_EXT_AKI="keyid:always" # authorityKeyIdentifier
# Need to remove 'clientAuth' from server extendedKeyUsage; no citation
# Need to remove 'nsSGC' from extendedKeyUsage, but no citation
# Need to remove 'msSGC' from extendedKeyUsage, but no citation
CNF_CA_EXT_EKU="serverAuth,clientAuth"
# CNF_CA_EXT_SAN="\$ENV::SAN" # subjectAltName
CNF_CA_EXT_SAN="" # subjectAltName
CNF_CA_EXT_AIA="@ocsp_info"
# known_policies = {
# '2.23.140.2.1': 'test certificate',
# '2.23.140.1.2.1': 'DV', Domain-validated
# '2.23.140.1.2.2': 'OV', Organization-validated
# '2.23.140.1.2.3': 'IV', Individual-validated
# '2.23.140.1.3': 'EV', Extended-validated
# '2.23.140.1.31': '.onion' TOR service description OID
#}
CNF_CA_EXT_EXTRA="crlDistributionPoints=URI:${X509_CRL}"
;;
client)
CNF_REQ_EXT_KU="critical,keyCertSign,cRLSign" # keyUsage
# No need to auto-retrieve parent CA's pathLen=, this is the end of line
CNF_REQ_EXT_BC="critical,CA:true,pathlen:0"
CNF_REQ_EXT_SKI="hash" # subjectKeyIdentifier
# email-ca.cnf/[client_ext]
# CNF_CA_EXT_KU="critical,digitalSignature,keyEncipherment" # very old
CNF_CA_EXT_KU="critical,digitalSignature"
CNF_CA_EXT_BC="CA:true,pathlen:0"
CNF_CA_EXT_SKI="hash" # subjectKeyIdentifier
CNF_CA_EXT_AKI="keyid:always" # authorityKeyIdentifier
CNF_CA_EXT_EKU="clientAuth"
CNF_CA_EXT_SAN="email:move" # subjectAltName
CNF_CA_EXT_AIA="@ocsp_info"
;;
timestamping)
CNF_REQ_EXT_KU="critical,keyCertSign,cRLSign" # keyUsage
# No need to auto-retrieve parent CA's pathLen=, this is the end of line
CNF_REQ_EXT_BC="critical,CA:true,pathlen:0"
CNF_REQ_EXT_SKI="hash" # subjectKeyIdentifier
# component-ca.cnf/[timestamp_ext]
CNF_CA_EXT_KU="critical,digitalSignature"
CNF_CA_EXT_BC="CA:true,pathlen:0"
CNF_CA_EXT_SKI="hash" # subjectKeyIdentifier
CNF_CA_EXT_AKI="keyid:always" # authorityKeyIdentifier
CNF_CA_EXT_EKU="critical,timeStamping"
CNF_CA_EXT_SAN="" # subjectAltName
CNF_CA_EXT_AIA="@issuer_info"
;;
ocsp)
CNF_REQ_EXT_KU="critical,keyCertSign,cRLSign" # keyUsage
CNF_REQ_EXT_BC="critical,CA:true,pathlen:0"
CNF_REQ_EXT_SKI="hash" # subjectKeyIdentifier
# component-ca.cnf/[ocspsign_ext]
CNF_CA_EXT_KU="critical,digitalSignature"
CNF_CA_EXT_BC="CA:false"
CNF_CA_EXT_SKI="hash" # subjectKeyIdentifier
CNF_CA_EXT_AKI="keyid:always" # authorityKeyIdentifier
CNF_CA_EXT_EKU="critical,OCSPSigning"
CNF_CA_EXT_SAN="" # subjectAltName
CNF_CA_EXT_AIA="@issuer_info"
CNF_CA_EXT_EXTRA="noCheck = null"
;;