forked from OpenVPN/easy-rsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasyrsa
executable file
·7276 lines (6271 loc) · 184 KB
/
easyrsa
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/sh
# Easy-RSA 3 -- A Shell-based CA Utility
#
# Copyright (C) 2024 - The Open-Source OpenVPN development community.
# A full list of contributors can be found on Github at:
# https://github.com/OpenVPN/easy-rsa/graphs/contributors
#
# This code released under version 2 of the GNU GPL; see COPYING
# and the Licensing/ directory of this project for full licensing
# details.
# Help/usage output to stdout
usage() {
# command help:
information "
Easy-RSA 3 usage and overview
$easyrsa_help_title
To get detailed usage and help for a command, use:
./easyrsa help COMMAND
For a list of global-options, use:
./easyrsa help options
For a list of utility commands, use:
./easyrsa help util
A list of commands is shown below:
init-pki [ cmd-opts ]
self-sign-server <file_name_base> [ cmd-opts ]
self-sign-client <file_name_base> [ cmd-opts ]
build-ca [ cmd-opts ]
gen-dh
gen-req <file_name_base> [ cmd-opts ]
sign-req <type> <file_name_base> [ cmd-opts ]
build-client-full <file_name_base> [ cmd-opts ]
build-server-full <file_name_base> [ cmd-opts ]
build-serverClient-full <file_name_base> [ cmd-opts ]
inline <file_name_base>
expire <file_name_base>
renew-ca
renew <file_name_base>
revoke <file_name_base> [ cmd-opts ] #(DEPRECATED)
revoke-issued <file_name_base> [ cmd-opts ] #(REPLACEMENT)
revoke-expired <file_name_base> [ cmd-opts ]
revoke-renewed <file_name_base> [ cmd-opts ]
gen-crl
update-db
show-req <file_name_base> [ cmd-opts ]
show-cert <file_name_base> [ cmd-opts ]
show-ca [ cmd-opts ]
show-crl
verify-cert <file_name_base>
import-req <request_file_path> <short_name_base>
export-p1 <file_name_base> [ cmd-opts ]
export-p7 <file_name_base> [ cmd-opts ]
export-p8 <file_name_base> [ cmd-opts ]
export-p12 <file_name_base> [ cmd-opts ]
set-pass <file_name_base> [ cmd-opts ]
gen-tls-auth-key / gen-tls-crypt-key
write <type> [ cmd-opts ]"
# collect/show dir status:
text_only=1
work_dir="${EASYRSA:-undefined}"
pki_dir="${EASYRSA_PKI:-undefined}"
# check for vars changing PKI unexpectedly!
if [ "$invalid_vars" ]; then
ivmsg="
*WARNING*: \
Invalid vars setting for EASYRSA and/or EASYRSA_PKI${NL}"
else
unset -v ivmsg
fi
# Print details
information "
DIRECTORY STATUS (commands would take effect on these locations)
EASYRSA: $work_dir
PKI: $pki_dir
vars-file: ${EASYRSA_VARS_FILE:-Missing or undefined}${ivmsg}"
# CA Status
if verify_ca_init test; then
if [ -z "$EASYRSA_SILENT" ]; then
# Show SSL output directly, with easyrsa header
printf '%s' " CA status: OK${NL}${NL} "
"$EASYRSA_OPENSSL" x509 -in "$EASYRSA_PKI/ca.crt" \
-noout -subject -nameopt utf8,multiline
print "" # for a clean line
fi
else
information " CA status: CA has not been built${NL}"
fi
# verbose info
verbose "ssl-cnf: ${EASYRSA_SSL_CONF:-built-in}"
verbose "x509-types: ${EASYRSA_EXT_DIR:-built-in}"
if [ -d "$EASYRSA_TEMP_DIR" ]; then
verbose "temp-dir: Found: $EASYRSA_TEMP_DIR"
else
verbose "temp-dir: Missing: ${EASYRSA_TEMP_DIR:-undefined}"
fi
} # => usage()
# Detailed command help
# When called with no args, calls usage(),
# otherwise shows help for a command
# Please maintain strict indentation rules.
# Commands are TAB indented, while text is SPACE indented.
# 'case' indentation is minimalistic.
cmd_help() {
easyrsa_help_title="\
Usage: easyrsa [ OPTIONS.. ] <COMMAND> <TARGET> [ cmd-opts.. ]"
unset -v text err_text opts text_only
case "$1" in
init-pki|clean-all)
text="
* init-pki [ cmd-opts ]
Removes & re-initializes the PKI directory for a new PKI"
opts="
* hard - Recursively delete the ENTIRE PKI directory (default).
* soft - Keep the named PKI directory and PKI 'vars' file intact.
Also keep the current Request files,
to be signed by a new CA (Partial CA renewal)."
;;
self-sign*)
text="
* self-sign-server|self-sign-client <file_name_base> [ cmd-opts ]
Creates a new self-signed server|client key pair"
opts="
* nopass - Do not encrypt the private key (Default: encrypted)
(Equivalent to global option '--nopass|--no-pass')"
;;
build-ca)
text="
* build-ca [ cmd-opts ]
Creates a new CA"
opts="
* raw-ca - ONLY use SSL binary to input CA password
raw (Equivalent to global option '--raw-ca')
* nopass - Do not encrypt the private key (Default: encrypted)
(Equivalent to global option '--nopass|--no-pass')
* subca - Create an intermediate CA keypair and request
intca (default is a root CA)"
;;
gen-dh)
text="
* gen-dh
Generates DH (Diffie-Hellman) parameters file"
;;
gen-req)
text="
* gen-req <file_name_base> [ cmd-opts ]
Generate a standalone-private-key and certificate-signing-request
This request is suitable for sending to a remote CA for signing."
opts="
* nopass - Do not encrypt the private key (Default: encrypted)
(Equivalent to global option '--nopass|--no-pass')
* text - Include certificate text in request"
;;
sign|sign-req)
text="
* sign-req <type> <file_name_base> [ cmd-opts ]
Sign a certificate request of the defined type.
<type> must be a known type.
eg: 'client', 'server', 'serverClient', 'ca' or a user-added type.
All supported types are listed in the x509-types directory.
This request file must exist in the reqs/ dir and have a .req file
extension. See 'import-req' for importing from other sources."
opts="
* newsubj - Replace subject. See 'help subject'.
* preserve - Use the DN-field order of the CSR not the CA."
;;
build|build-client-full|build-server-full|build-serverClient-full)
text="
* build-client-full <file_name_base> [ cmd-opts ]
* build-server-full <file_name_base> [ cmd-opts ]
* build-serverClient-full <file_name_base> [ cmd-opts ]
Generate a keypair and sign locally.
This mode uses the <file_name_base> as the X509 commonName."
opts="
* nopass - Do not encrypt the private key (Default: encrypted)
(Equivalent to global option '--nopass|--no-pass')"
;;
inline)
text="
* inline <file_name_base>
Create inline file for <file_name_base>."
;;
revoke*)
text="
* revoke <file_name_base> [ reason ]
Commmand 'revoke' is DEPRECATED and can ONLY be used in batch mode.
Commmand 'revoke-issued' REPLACES command 'revoke'.
Revoke a certificate specified by the <file_name_base>,
with an optional revocation [ reason ].
Values accepted for option [ reason ]:
us | uns* | unspecified
kc | key* | keyCompromise
cc | ca* | CACompromise
ac | aff* | affiliationChanged
ss | sup* | superseded
co | ces* | cessationOfOperation
ch | cer* | certificateHold
Commands 'revoke-expired' and 'revoke-renewed' are functionally
equivalent to 'revoke-issued', however, they are used to revoke
certificates which have been either 'expired' or 'renewed' by
other EasyRSA commands.
Commmand 'revoke' is DEPRECATED and can ONLY be used in batch mode.
Commmand 'revoke-issued' REPLACES command 'revoke'.
REQUIRED COMMANDS:
* 'revoke-issued' <file_name_base> [ reason ]
Revoke a current, issued certificate.
* 'revoke-expired' <file_name_base> [ reason ]
Revoke an old, expired certificate.
* 'revoke-renewed' <file_name_base> [ reason ]
Revoke an old, renewed certificate."
opts="
* [ reason ]${NL}
Values accepted for option [ reason ]: Details above."
;;
expire)
text="
* expire <file_name_base>
Move a certificate specified by <file_name_base>
to the 'pki/expired' directory.
Allows an existing request to be signed again."
;;
renew-ca)
text="
* renew-ca
Renew CA certificate.
This will build a new CA certificate and archive the old one.
Before changes are made to the current PKI, user confirmation
is required."
;;
renew)
text="
* renew <file_name_base>
Renew a certificate specified by <file_name_base>"
;;
gen-crl)
text="
* gen-crl
Generate a certificate revocation list [CRL]"
;;
update-db)
text="
* update-db
Update the index.txt database
This command will use the system time to update the status of
issued certificates."
;;
show-req|show-cert)
text="
* show-req <file_name_base> [ cmd-opts ]
* show-cert <file_name_base> [ cmd-opts ]
Shows details of the req or cert referenced by <file_name_base>
Human-readable output is shown, including any requested cert
options when showing a request."
opts="
* full - show full req/cert info, including pubkey/sig data"
;;
show-ca)
text="
* show-ca [ cmd-opts ]
Shows details of the Certificate Authority [CA] certificate
Human-readable output is shown."
opts="
* full - show full CA info, including pubkey/sig data"
;;
show-crl)
text="
* show-crl
Shows details of the current certificate revocation list (CRL)
Human-readable output is shown."
;;
verify|verify-cert)
text="
* verify-cert <file_name_base> [ cmd-opts ]
Verify certificate against CA
Returns the current validity of the certificate."
opts="
* batch - On failure to verify, return error (1) to caller"
;;
import-req)
text="
* import-req <request_file_path> <short_name_base>
Import a certificate request from a file
This will copy the specified file into the reqs/ dir in
preparation for signing.
The <short_name_base> is the <file_name_base> to create.
Example usage:
import-req /some/where/bob_request.req bob"
;;
export-p12)
text="
* export-p12 <file_name_base> [ cmd-opts ]
Export a PKCS#12 file with the keypair,
specified by <file_name_base>"
opts="
* nopass - Do not encrypt the private key (Default: encrypted)
(Equivalent to global option '--nopass|--no-pass')
* noca - Do not include the ca.crt file in the PKCS12 output
* nokey - Do not include the private key in the PKCS12 output
* nofn - Do not set 'friendlyName'
For more, see: 'easyrsa help friendly'
* legacy - Use legacy algorithm: RC2_CBC or 3DES_CBC + MAC: SHA1
(Default algorithm: AES-256-CBC + MAC: SHA256)"
;;
friendly)
text_only=1
text="
* export-p12: Internal file label 'friendlyName'
The 'friendlyname' is always set to the file-name-base.
An alternate friendlyName can be configured by using:
* Global option '--usefn=<friendlyName>'
Fallback to previous behavior can be configured by using:
* Command option 'nofn' ('friendlyname' will not be set)"
;;
export-p7)
text="
* export-p7 <file_name_base> [ cmd-opts ]
Export a PKCS#7 file with the pubkey,
specified by <file_name_base>"
opts="
* noca - Do not include the ca.crt file in the PKCS7 output"
;;
export-p8)
text="
* export-p8 <file_name_base> [ cmd-opts ]
Export a PKCS#8 file with the private key,
specified by <file_name_base>"
opts="
* nopass - Do not encrypt the private key (Default: encrypted)
(Equivalent to global option '--nopass|--no-pass')"
;;
export-p1)
text="
* export-p1 <file_name_base> [ cmd-opts ]
Export a PKCS#1 (RSA format) file with the pubkey,
specified by <file_name_base>"
opts="
* nopass - Do not encrypt the private key (Default: encrypted)
(Equivalent to global option '--nopass|--no-pass')"
;;
set-pass|set-ed-pass|set-rsa-pass|set-ec-pass)
text="
* set-pass <file_name_base> [ cmd-opts ]
Set a new passphrase for the private key specified by <file_name_base>
DEPRECATED: 'set-rsa-pass' and 'set-ec-pass'"
opts="
* nopass - Do not encrypt the private key (Default: encrypted)
(Equivalent to global option '--nopass|--no-pass')
* file - (Advanced) Treat the file as a raw path, not a short-name"
;;
write)
text="
* write <type> [<filename>] ['overwrite']
Write <type> data to stdout or <filename>
Types:
* ssl-cnf - Write EasyRSA SSL config file.
* safe-cnf - Write expanded EasyRSA SSL config file for LibreSSL.
* COMMON|ca|server|serverClient|client|codeSigning|email|kdc
- Write x509-type <type> file.
* legacy - Write ALL support files (above) to the PKI directory.
Will create '\$EASYRSA_PKI/x509-types' directory.
* legacy-hard
- Same as 'legacy' plus OVER-WRITE files.
* vars - Write vars.example file."
opts="
* filename - If <filename> is specified then it is the output
is directed to the named file.
Otherwise, the data is sent to stdout
* overwrite - Overwrite the <filename>.
<filename> is always preserved without 'overwrite'."
;;
--san|--subject-alt-name|altname|subjectaltname|san)
text_only=1
text="
* Global Option: --subject-alt-name=SAN_FORMAT_STRING
This global option adds a subjectAltName to the request or issued
certificate. It MUST be in a valid format accepted by openssl or
req/cert generation will fail. NOTE: --san can be specified more
than once on the command line.
The following two command line examples are equivalent:
1. --san=DNS:server1,DNS:serverA,IP:10.0.0.1
2. --san=DNS:server1 --san=DNS:serverA --san=IP:10.0.0.1
Examples of the SAN_FORMAT_STRING shown below:
* DNS:alternate.example.net
* DNS:primary.example.net,DNS:alternate.example.net
* IP:203.0.113.29
* email:[email protected]"
;;
--copy-ext|copy-ext|copyext)
text_only=1
text="
* Global Option: How to use --copy-ext and --san=<SAN>
These are the only commands that support --copy-ext and/or --san.
Command 'gen-req':
--san: Add SAN extension to the request file.
Command 'sign-req':
--copy-ext: Copy all request extensions to the signed certificate.
--san: Over write the request SAN with option SAN.
Command 'build-*-full':
--copy-ext: Always enabled.
--san: Add SAN extension to the request and signed certificate.
See 'help san' for option --san full syntax."
;;
--days|days)
text_only=1
text="
* Global Option: --days=DAYS
This global option is an alias for one of the following:
* Expiry days for a new CA.
eg: '--days=3650 build-ca'
* Expiry days for new/renewed certificate.
eg: '--days=1095 renew server'
* Expiry days for certificate revocation list.
eg: '--days=180 gen-crl'
* Cutoff days for command: show-expire.
eg: '--days=90 show-expire'"
;;
--new-subj*|new-subj*|newsubj*|subject)
text_only=1
text="
* Global Option: --new-subject=<SUBJECT>
This global option is used to set the new certificate subject,
when signing a new certificate
* REQUIRES Command option: 'newsubj', for command 'sign-req'
Using command 'sign-req', add command option 'newsubj',
to FORCE the --new-subject to be used.
Example:
--new-subject='/CN=foo' sign-req client bar newsubj
See OpenSSL command 'ca', option -subj, for full details."
;;
tool*|util*|more)
# Test features
text_only=1
text="
NOTE:
These commands are safe to test and will NOT effect your PKI.
Check <SERIAL> number is unique:
serial|check-serial <SERIAL>
Display DN of request or certificate: <form> = req|x509
display-dn <form> <DIR/FILE_NAME>
Display EKU of certificate:
show-eku <file_name_base>|<DIR/FILE_NAME>
Generate random hex:
rand <decimal_number>
Reporting tools:
show-expire <file_name_base> (Optional)
show-revoke <file_name_base> (Optional)
show-renew <file_name_base> (Optional)"
;;
gen-tls*)
text_only=1
text="
Generate TLS keys for use with OpenVPN:
gen-tls-auth-key : Generate OpenVPN TLS-AUTH key
gen-tls-crypt-key : Generate OpenVPN TLS-CRYPT-V1 key (Preferred)
Only ONE TLS key is allowed to exist. (pki/private/easyrsa-tls.key)
This TLS key will be automatically added to inline files."
;;
opts|options)
opt_usage
cleanup ok
;;
"")
usage
cleanup ok
;;
*)
err_text="
Unknown command: '$1' \
(try without commands for a list of commands)"
easyrsa_exit_with_error=1
esac
if [ "$err_text" ]; then
print "$easyrsa_help_title"
print "${err_text}"
else
# display the help text
print "$easyrsa_help_title"
[ "$text" ] && print "$text"
if [ "$text_only" ]; then
: # ok - No opts message required
else
print "
Available command options [ cmd-opts ]:
${opts:-
* No supported command options}"
fi
fi
print
} # => cmd_help()
# Options usage
opt_usage() {
text_only=1
information "
Easy-RSA Global Option Flags
The following global-options may be provided before the command.
Options specified at runtime override env-vars and any 'vars'
file in use.
Unless noted, non-empty values to options are mandatory.
General options:
--version : Prints EasyRSA version and build information
--batch : Set automatic (no-prompts when possible) mode
--silent|-s : Disable all warnings, notices and information
--sbatch : Combined --silent and --batch operating mode
--silent-ssl|-S : Silence SSL output (Requires batch mode)
--nopass|no-pass: Do not use passwords
Can NOT be used with --passin or --passout
--passin=ARG : Set -passin ARG for openssl (eg: pass:xEasyRSAy)
--passout=ARG : Set -passout ARG for openssl (eg: pass:xEasyRSAy)
--raw-ca : Build CA with password via RAW SSL input
--vars=FILE : Define a specific 'vars' file to use for Easy-RSA config
(Default vars file is in the current working directory)
--pki=DIR : Declare the PKI directory
(Default PKI directory is sub-directory 'pki')
See Advanced.md for in depth usage.
--ssl-cnf=FILE : Define a specific OpenSSL config file for Easy-RSA to use
(Default config file is in the EasyRSA PKI directory)
--force-safe-ssl: Always generate a safe SSL config file
(Default: Generate Safe SSL config once per instance)
--tmp-dir=DIR : Declare the temporary directory
(Default temporary directory is the EasyRSA PKI directory)
--keep-tmp=NAME : Keep the original temporary session by name: NAME
NAME is a sub-directory of the dir declared by --tmp-dir
This option ALWAYS over-writes a sub-dir of the same name.
Certificate & Request options: (these impact cert/req field values)
--notext|no-text: Create certificates without human readable text
--days=# : Sets the signing validity to the specified number of days
Applies to other commands. For details, see: 'help days'
--startdate=DATE: Sets the SSL option '-startdate' (Format 'YYYYMMDDhhmmssZ')
--enddate=DATE : Sets the SSL option '-enddate' (Format 'YYYYMMDDhhmmssZ')
--digest=ALG : Digest to use in the requests & certificates
--keysize=# : Size in bits of keypair to generate (RSA Only)
--use-algo=ALG : Crypto alg to use: choose rsa (default), ec or ed
--curve=NAME : For elliptic curve, sets the named curve
(Default: algo ec: secp384r1, algo ed: ed25519)
--subca-len=# : Path length of signed intermediate CA certificates
--copy-ext : Copy included request X509 extensions (namely subjAltName)
For more info, see: 'easyrsa help copyext'
--san|--subject-alt-name=SUBJECT_ALT_NAME
: Add a subjectAltName. Can be used multiple times.
For more info and syntax, see: 'easyrsa help altname'
--auto-san : Use commonName as subjectAltName: 'DNS:commonName'
If commonName is 'n.n.n.n' then set 'IP:commonName'
--san-crit : Mark X509v3 subjectAltName as critical
--bc-crit : Add X509 'basicContraints = critical' attribute.
--ku-crit : Add X509 'keyUsage = critical' attribute.
--eku-crit : Add X509 'extendedKeyUsage = critical' attribute.
--new-subject='SUBJECT'
: Specify a new subject field to sign a request with.
For more info and syntax, see: 'easyrsa help subject'
--usefn=NAME : export-p12, set 'friendlyName' to NAME
For more, see: 'easyrsa help friendly'
Distinguished Name mode:
--dn-mode=MODE : Distinguished Name mode to use 'cn_only' (Default) or 'org'
--req-cn=NAME : Request commonName
Distinguished Name Organizational options: (only used with '--dn-mode=org')
--req-c=CC : Country code (2-letters)
--req-st=NAME : State/Province
--req-city=NAME : City/Locality
--req-org=NAME : Organization
--req-email=NAME : Email addresses
--req-ou=NAME : Organizational Unit
--req-serial=VALUE : Entity serial number (Only used when declared)
Deprecated features:
--ns-cert : Include deprecated Netscape extensions
--ns-comment=COMMENT : Include deprecated Netscape comment (may be blank)"
} # => opt_usage()
# Wrapper around printf - clobber print since it's not POSIX anyway
# print() is used internally, so MUST NOT be silenced.
# shellcheck disable=SC1117 # printf format - print()
print() {
printf '%s\n' "$*"
} # => print()
# Exit fatally with a message to stderr
# present even with EASYRSA_BATCH as these are fatal problems
die() {
print "
Easy-RSA error:
$*${NL}"
# error_info is for hard-to-spot errors!
if [ "$error_info" ]; then
print " * $cmd: ${error_info}${NL}"
fi
# show host info
show_host
# exit to cleanup()
exit "${2:-1}"
} # => die()
# User errors, less noise than die()
user_error() {
print "
EasyRSA version $EASYRSA_version
Error
-----
$*${NL}"
easyrsa_exit_with_error=1
cleanup
} # => user_error()
# verbose information
verbose() {
[ "$EASYRSA_VERBOSE" ] || return 0
print " # $*"
} # => verbose()
# non-fatal warning output
warn() {
[ "$EASYRSA_SILENT" ] && return
print "
WARNING
=======
$*${NL}"
} # => warn()
# informational notices to stdout
notice() {
[ "$EASYRSA_SILENT" ] && return
print "
Notice
------
$*${NL}"
} # => notice()
# Helpful information
information() {
[ "$EASYRSA_SILENT" ] && return
print "$*"
} # => information()
# intent confirmation helper func
# returns without prompting in EASYRSA_BATCH
confirm() {
[ "$EASYRSA_BATCH" ] && return
prompt="$1"
value="$2"
msg="$3"
input=""
print "\
$msg
Type the word '$value' to continue, or any other input to abort."
printf %s " $prompt"
# shellcheck disable=SC2162 # read without -r - confirm()
read input
printf '\n'
[ "$input" = "$value" ] && return
easyrsa_exit_with_error=1
unset -v EASYRSA_SILENT
notice "Aborting without confirmation."
cleanup
} # => confirm()
# Generate random hex
easyrsa_random() {
case "$1" in
*[!1234567890]*|0*|"")
die "easyrsa_random - input"
esac
if rand_hex="$(
"$EASYRSA_OPENSSL" rand -hex "$1" 2>/dev/null
)"
then
if [ "$2" ]; then
force_set_var "$2" "$rand_hex"
else
print "$rand_hex"
fi
unset -v rand_hex
return 0
fi
die "easyrsa_random failed"
} # => easyrsa_random()
# Create session directory atomically or fail
secure_session() {
# Session must not be defined
[ -z "$secured_session" ] || die "session overload"
# Temporary directory must exist
[ -d "$EASYRSA_TEMP_DIR" ] || die "\
secure_session - Missing temporary directory:
* $EASYRSA_TEMP_DIR"
for i in 1 2 3; do
session=
easyrsa_random 4 session
secured_session="${EASYRSA_TEMP_DIR}/${session}"
# atomic:
# ONLY effects Windows 11 "broken" mkdir.exe
# The procedure now is a "poor man's" version
# of an atomic directory creation call.
# The "race condition" still exists but is minimized.
# What remains is equivalent to 32bit hash collision.
[ -d "$secured_session" ] && continue
if mkdir "$secured_session"; then
# Check mkdir.exe has created the directory
[ -d "$secured_session" ] || \
die "secure_session - mkdir FAILED"
[ -f "$secured_session"/temp.0.1 ] && \
die "secure_session - temp-file EXISTS"
# New session requires safe-ssl conf
unset -v session OPENSSL_CONF \
working_safe_ssl_conf working_safe_org_conf
easyrsa_err_log="$secured_session/error.log"
verbose "\
secure_session: CREATED: $secured_session"
return
fi
done
die "secure_session failed"
} # => secure_session()
# Remove secure session
remove_secure_session() {
[ -d "$secured_session" ] || return 0
if rm -rf "$secured_session"; then
verbose "\
remove_secure_session: DELETED: $secured_session"
# Restore original EASYRSA_SSL_CONF
EASYRSA_SSL_CONF="$original_ssl_cnf"
unset -v secured_session OPENSSL_CONF \
working_safe_ssl_conf working_safe_org_conf
return
fi
die "remove_secure_session Failed: $secured_session"
} # => remove_secure_session()
# 'mkdir' wrapper, broken by win11, which fails without error
easyrsa_mkdir() {
[ "$2" ] && die "easyrsa_mkdir - excess input"
[ "$1" ] || die "easyrsa_mkdir - input"
[ -d "$1" ] && return
mkdir "$1" 2>/dev/null # win11 never errors here
[ -d "$1" ] && return
die "easyrsa_mkdir - FAIL: $1"
} # => easyrsa_mkdir()
# Create temp-file atomically or fail
# WARNING: Running easyrsa_openssl in a subshell
# will hide error message and verbose messages
# from easyrsa_mktemp()
easyrsa_mktemp() {
if [ -z "$1" ] || [ "$2" ]; then
die "easyrsa_mktemp - input error"
fi
# session directory must exist
[ -d "$secured_session" ] || die "\
easyrsa_mktemp - Temporary session undefined (--tmp-dir)"
# Force noclobber
if [ "$easyrsa_host_os" = win ]; then
set -o noclobber
else
set -C
fi
# Assign internal temp-file name
tmp_fname="${secured_session}/temp.${mktemp_counter}"
# Create shotfile
for shot_try in x y z; do
shotfile="${tmp_fname}.${shot_try}"
if [ -f "$shotfile" ]; then
verbose "\
easyrsa_mktemp: shotfile EXISTS: $shotfile"
continue
else
printf "" > "$shotfile" || die "\
easyrsa_mktemp: create shotfile failed (1) $1"
# Create temp-file or die
# subshells do not update mktemp_counter,
# which is why this extension is required.
# Current max required is 1 attempt
for ext_try in 1 2 3 4 5 6 7 8 9; do
want_tmp_file="${tmp_fname}.${ext_try}"
# Warn to error log file for max reached
if [ "$EASYRSA_MAX_TEMP" -lt "$ext_try" ]; then
print "\
Max temp-file limit $ext_try, hit for: $1" > "$easyrsa_err_log"
die "EASYRSA_MAX_TEMP exceeded"
fi
if [ -f "$want_tmp_file" ]; then
verbose "\
easyrsa_mktemp: temp-file EXISTS: $want_tmp_file"
continue
else
# atomic:
if mv "$shotfile" "$want_tmp_file"; then
# Assign external temp-file name
if force_set_var "$1" "$want_tmp_file"
then
verbose "\
: easyrsa_mktemp: $1 OK: $want_tmp_file"
# unset noclobber
if [ "$easyrsa_host_os" = win ]; then
set +o noclobber
else
set +C
fi
# Update counter
mktemp_counter="$((mktemp_counter+1))"
unset -v tmp_fname \
shotfile shot_try \
want_tmp_file ext_try
return
else
die "\
easyrsa_mktemp - force_set_var $1 failed"
fi
fi
fi
done
fi
done
# unset noclobber
if [ "$easyrsa_host_os" = win ]; then
set +o noclobber
else
set +C
fi
# In case of subshell abuse, report to error log
err_msg="\
easyrsa_mktemp - failed for: $1 @ attempt=$ext_try
want_tmp_file: $want_tmp_file"
print "$err_msg" > "$easyrsa_err_log"
die "$err_msg"
} # => easyrsa_mktemp()
# remove temp files and do terminal cleanups
cleanup() {
# In case of subshell abuse, display error log file
if [ -f "$easyrsa_err_log" ]; then
print; cat "$easyrsa_err_log"; print
fi
# undo changes BEFORE delete temp-dir
# Remove files when build_full()->sign_req() is interrupted
[ "$error_build_full_cleanup" ] && \
rm -f "$crt_out" "$req_out" "$key_out"
# Restore files when renew is interrupted
[ "$error_undo_renew_move" ] && renew_restore_move
# Remove temp-session or create temp-snapshot
if [ -d "$secured_session" ]; then
if [ "$EASYRSA_KEEP_TEMP" ]; then
# skip on black-listed directory names, with a warning
# Use '-e' for directory or file name
if [ -e "$EASYRSA_TEMP_DIR/$EASYRSA_KEEP_TEMP" ]