-
Notifications
You must be signed in to change notification settings - Fork 8
/
easyrsa-unit-tests.sh-orig
executable file
·1126 lines (969 loc) · 23.9 KB
/
easyrsa-unit-tests.sh-orig
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
#
# Runs operational testing
# Easy-RSA 3 -- A Shell-based CA Utility
#
# Copyright (C) 2020 by the Open-Source OpenVPN development community.
# A full list of contributors can be found in the ChangeLog.
#
# This code released under version 2 of the GNU GPL; see COPYING and the
# Licensing/ directory of this project for full licensing details.
#
# easyrsa-unit-tests.sh (2020)
usage ()
{
cat << __EOF__
Tests run:
* standard ca [penelope]
* standard server + renew [s01]
* standard server with SAN [s02]
* standard serverClient [s03]
* standard serverClient with SAN [s04]
* standard client + renew [c01]
* standard sign imported server [specter]
* standard sign imported serverClient [heartbleed]
* standard sign imported serverClient with SAN [VORACLE]
* standard sign imported client [meltdown]
* standard sign imported ca [maximilian]
* subca to origin
* subca sign server [specter]
* subca sign serverClient [heartbleed]
* subca sign serverClient with SAN [VORACLE]
* subca sign client [meltdown]
* delete all keys and revoke all certs on the fly
* generate various CRLs
__EOF__
success 0
}
init ()
{
DIE="${DIE:-1}"
ROOT_DIR="$PWD"
WORK_DIR="${ROOT_DIR}/easyrsa3"
TEMP_DIR="${WORK_DIR}/unit tests"
S_ERRORS=0
T_ERRORS=0
WAIT_DELAY="${WAIT_DELAY:-0}"
LOG_INDENT_1=" - "
LOG_INDENT_2=" - "
if [ -d "$TEMP_DIR" ]; then
if [ -z "$IGNORE_TEMP" ]; then
SAVE_PKI=1
die "Aborted! Temporary directory exists: $TEMP_DIR"
fi
rm -rf "$TEMP_DIR" || {
SAVE_PKI=1
die "Failed to clean Temporary directory: $TEMP_DIR"
}
mkdir "$TEMP_DIR" || {
die "Failed to create Temporary directory: $TEMP_DIR"
}
fi
SHOW_CERT="${SHOW_CERT:-0}"
#SAVE_PKI="${SAVE_PKI:-0}"
ERSA_OUT="${ERSA_OUT:-0}"
ACT_OUT="$TEMP_DIR/.act.out"
ACT_ERR="$TEMP_DIR/.act.err"
# Setup the 'easyrsa' executable to use
if [ -f "$WORK_DIR/easyrsa" ]; then
# Either './easyrsa'
ERSA_BIN="$WORK_DIR/easyrsa"
else
# Or 'easyrsa' in PATH
ERSA_BIN="easyrsa"
fi
TEST_ALGOS="rsa ec ed"
[ "$LIBRESSL_LIMIT" ] && TEST_ALGOS="rsa ec"
CUSTOM_VARS="${CUSTOM_VARS:-1}"
UNSIGNED_PKI="${UNSIGNED_PKI:-1}"
# Don't change this
SYS_SSL_ENABLE="${SYS_SSL_ENABLE:-1}"
SYS_SSL_LIBB="${SYS_SSL_LIBB:-openssl}"
# Change this
# Use any custom command line SSL lib for this
OSSL_LIBB="${OSSL_LIBB:-"$SYS_SSL_LIBB"}"
export EASYRSA_KEY_SIZE="${EASYRSA_KEY_SIZE:-1024}"
export EASYRSA_CA_EXPIRE="${EASYRSA_CA_EXPIRE:-1}"
export EASYRSA_CERT_EXPIRE="${EASYRSA_CERT_EXPIRE:-365}"
export EASYRSA_CERT_RENEW="${EASYRSA_CERT_RENEW:-529}"
export EASYRSA_FIX_OFFSET="${EASYRSA_FIX_OFFSET:-163}"
# Not worth this dev effort
#BROKEN_PKI="${BROKEN_PKI:-0}"
#CUSTOM_OPTS="${CUSTOM_OPTS:-0}"
#EASYRSA_SP="${EASYRSA_SP:-private}"
#ERSA_UTEST_CURL_TARGET="${ERSA_UTEST_CURL_TARGET:-default}"
#export DEPS_DIR="$ROOT_DIR/testdeps"
#export OPENSSL_ENABLE="${OPENSSL_ENABLE:-0}"
#export OPENSSL_BUILD="${OPENSSL_BUILD:-0}"
#export OPENSSL_VERSION="${OPENSSL_VERSION:-git}"
#export OSSL_LIBB="${OSSL_LIBB:-"$DEPS_DIR/openssl-dev/bin/openssl"}"
#export CUST_SSL_ENABLE="${CUST_SSL_ENABLE:-0}"
#export CUST_SSL_LIBB="${CUST_SSL_LIBB:-"$DEPS_DIR/cust-ssl-inst/bin/openssl"}"
#export LIBRESSL_ENABLE="${LIBRESSL_ENABLE:-0}"
#export LIBRESSL_BUILD="${LIBRESSL_BUILD:-0}"
#export LIBRESSL_VERSION="${LIBRESSL_VERSION:-2.8.3}"
#export LSSL_LIBB="${LSSL_LIBB:-"$DEPS_DIR/libressl/usr/local/bin/openssl"}"
}
success ()
{
vverbose "EXIT: exit 0"
exit 0
}
failed ()
{
ERROR_COUNT="$((ERROR_COUNT+1))"
ERROR_CODE="$1"
cleanup || print "cleanup failed!"
print
print "ERROR: exit $ERROR_CODE"
exit "$ERROR_CODE"
}
# Wrapper around printf - clobber print since it's not POSIX anyway
print() { printf "%s\n" "$1"; }
warn ()
{
[ "$SILENCE_WARN" ] && return
print "$1"
}
die ()
{
print
print "FATAL ERROR! Command failed -> ${1:-unknown error}"
[ -f "$ACT_OUT" ] && print && print "EasyRSA log:" && cat "$ACT_OUT"
[ -f "$ACT_ERR" ] && print && print "Error message:" && cat "$ACT_ERR"
[ $((DIE)) -eq 1 ] && failed 1
warn "Ignored"
S_ERRORS=$((S_ERRORS + 1))
T_ERRORS=$((T_ERRORS + 1))
warn "$STAGE_NAME Errors: $S_ERRORS"
return 0
}
newline ()
{
[ $((VVERBOSE + SHOW_CERT_ONLY)) -eq 0 ] && return 0
case "$1" in
3)
print \
"|| ###########################################################################"
;;
2)
print \
"|| ==========================================================================="
;;
1)
print \
"|| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
;;
'')
[ $((ERSA_OUT)) -ne 1 ] || print "||"
;;
*)
die "Unrecognised newline type: $1"
esac
}
notice ()
{
[ $((VERBOSE)) -eq 1 ] || return 0
print "$1"
}
# shellcheck disable=SC2016
filter_msg ()
{
MSG="$(
print "$1" | \
sed \
-e 's/--subject-alt-name=[[:alnum:][:punct:]]*[[:blank:]]//' \
-e 's`/.*/``' \
-e 's/ nopass//' \
-e 's/ inline//' \
-e 's/^ //' \
-e 's/ $//' \
-e 's/ / /' \
)"
}
# verbose and completed work together
verbose ()
{
[ $((VERBOSE)) -eq 1 ] || return 0
filter_msg "$1"
printf "%s" "$LOG_INDENT" "$MSG .."
}
verbose_update ()
{
# verb is turned off when this is used
[ "$VVERBOSE" ] && return 0
printf '%s' "."
}
completed ()
{
[ $((VERBOSE)) -eq 1 ] || return 0
print " ok"
}
vverbose ()
{
[ $((VVERBOSE)) -eq 1 ] || return 0
filter_msg "$1"
print "|| :: $MSG"
}
vdisabled ()
{
[ $((VVERBOSE)) -eq 1 ] || return 0
print "|| -- DISABLED OPTION: $1"
}
vcompleted ()
{
[ $((VVERBOSE)) -eq 1 ] || return 0
filter_msg "$1"
print "|| ++ $MSG .. ok"
}
vvverbose ()
{
[ $((VVERBOSE)) -eq 1 ] || return 0
print "|| :: $1"
}
verb_on ()
{
unset SILENCE_WARN
VERBOSE="$SAVE_VERB"
VVERBOSE="$SAVE_VVERB"
ERSA_OUT="$SAVE_EOUT"
}
verb_off ()
{
SILENCE_WARN=1
SAVE_VERB="$VERBOSE"
unset VERBOSE
SAVE_VVERB="$VVERBOSE"
unset VVERBOSE
SAVE_EOUT="$ERSA_OUT"
unset ERSA_OUT
}
easyrsa_unit_test_version ()
{
newline 3
print "easyrsa-unit-tests.sh version: $ERSA_UTEST_VERSION"
print "easyrsa-unit-tests.sh source: $ERSA_UTEST_CURL_TARGET"
print "easyrsa source: $ERSA_BIN"
#print "SYS_SSL_LIBB: $SYS_SSL_LIBB"
#SYS_LIB_VERSION="$("$SYS_SSL_LIBB" version)"
#print "SYS_SSL_LIBB version: $SYS_LIB_VERSION"
#print "EASYRSA_OPENSSL: $EASYRSA_OPENSSL"
#ERSA_LIB_VERSION="$("$EASYRSA_OPENSSL" version)"
#print "EASYRSA_OPENSSL version: $ERSA_LIB_VERSION"
ssl_version="$("$EASYRSA_OPENSSL" version)"
printf '%s\n' "" "* EASYRSA_OPENSSL:" \
" $EASYRSA_OPENSSL (env)" " ${ssl_version}"
}
# Identify host OS
detect_host() {
unset -v easyrsa_host_os easyrsa_host_test easyrsa_win_git_bash
# Detect Windows
[ "${OS}" ] && easyrsa_host_test="${OS}"
# shellcheck disable=SC2016 # expansion inside '' blah
easyrsa_ksh='@(#)MIRBSD KSH R39-w32-beta14 $Date: 2013/06/28 21:28:57 $'
[ "${KSH_VERSION}" = "${easyrsa_ksh}" ] && easyrsa_host_test="${easyrsa_ksh}"
unset -v easyrsa_ksh
# If not Windows then nix
if [ "${easyrsa_host_test}" ]; then
easyrsa_host_os=win
easyrsa_uname="${easyrsa_host_test}"
easyrsa_shell="$SHELL"
# Detect Windows git/bash
if [ "${EXEPATH}" ]; then
easyrsa_shell="$SHELL (Git)"
easyrsa_win_git_bash="${EXEPATH}"
# If found then set openssl NOW!
[ -e /usr/bin/openssl ] && set_var EASYRSA_OPENSSL /usr/bin/openssl
fi
else
easyrsa_host_os=nix
easyrsa_uname="$(uname 2>/dev/null)"
easyrsa_shell="$SHELL"
# Test the Unit Test SSL Library version, not EasyRSA SSL Lib
val="$("$OSSL_LIBB" version)"
case "${val%% *}" in
# OpenSSL does not require a safe config-file
OpenSSL)
#unset -v require_safe_ssl_conf
:
;;
LibreSSL)
#require_safe_ssl_conf=1
#export LIBRESSL_LIMIT=1
TEST_ALGOS="rsa ec"
;;
*) die "\
Missing or invalid OpenSSL
Expected to find openssl command at: $EASYRSA_OPENSSL"
esac
fi
host_out="$easyrsa_host_os | $easyrsa_uname | $easyrsa_shell"
host_out="${host_out}${easyrsa_win_git_bash+ | "$easyrsa_win_git_bash"}"
unset -v easyrsa_host_test
} # => detect_host()
wait_sec ()
{
[ $((WAIT_DELAY)) -eq 0 ] && return 0
verbose "Wait"
vverbose "Wait"
{ sleep "$WAIT_DELAY" 2>/dev/null; } || echo "* Windows is slow enough *"
completed
}
setup ()
{
newline 3
verbose "Setup"
vverbose "Setup"
# dir: ./easyrsa3
mkdir -p "$WORK_DIR" || die "mkdir $WORK_DIR"
cd "$WORK_DIR" || die "cd $WORK_DIR"
verbose_update
vvverbose "Working dir: $WORK_DIR"
# dir: ./easyrsa3/unit test
mkdir -p "$TEMP_DIR" || die "Cannot mkdir: -p $TEMP_DIR"
verbose_update
vvverbose "Temp dir: $TEMP_DIR"
STEP_NAME="vars"
if [ $((CUSTOM_VARS)) -eq 1 ]
then
# TODO: MUST Find a usable vars.example because of the live code in vars
# FOUND_VARS=`where is vars.example`
#[ -f "$FOUND_VARS/vars.example" ] || dir "File missing: $FOUND_VARS/vars.example"
#cp "$FOUND_VARS/vars.example" "$WORK_DIR/vars" || die "cp vars.example vars"
create_vars > "$TEMP_DIR/vars.utest" || die "create_vars"
verbose_update
vcompleted "$STEP_NAME"
else
vdisabled "$STEP_NAME"
fi
STEP_NAME="Custom opts"
if [ $((CUSTOM_OPTS)) -eq 1 ]
then
# https://github.com/OpenVPN/easy-rsa/pull/278
export CUSTOM_EASYRSA_REQ_ORG2="Custom Option"
export LIBRESSL_ENABLE=0
YACF="$WORK_DIR/openssl-easyrsa.cnf"
[ -f "$YACF" ] || die "File missing: $YACF"
[ -f "$YACF.orig" ] && die "Aborted! Temporary file exists: $YACF.orig"
mv "$YACF" "$YACF.orig"
create_custom_opts > "$YACF"
verbose_update
vcompleted "$STEP_NAME"
else
vdisabled "$STEP_NAME"
fi
STAGE_NAME="Sample requests"
if [ $((UNSIGNED_PKI)) -eq 1 ] && [ $((SYS_SSL_ENABLE + CUST_SSL_ENABLE + OPENSSL_ENABLE + LIBRESSL_ENABLE)) -ne 0 ]
then
vverbose "$STAGE_NAME"
[ "$VVERBOSE" ] || verb_off
for i in $TEST_ALGOS
do
export EASYRSA_ALGO="$i"
NEW_PKI="pki-req-$EASYRSA_ALGO"
[ "$EASYRSA_ALGO" = "ed" ] && export EASYRSA_CURVE="ed25519"
create_req
mv "$TEMP_DIR/$NEW_PKI" "$TEMP_DIR/pki-bkp-$EASYRSA_ALGO" || \
die "$STAGE_NAME mv $TEMP_DIR/$NEW_PKI"
unset EASYRSA_ALGO EASYRSA_CURVE
unset NEW_PKI
done
[ "$VVERBOSE" ] || verb_on
verbose_update
vcompleted "$STAGE_NAME"
else
vdisabled "$STAGE_NAME"
fi
completed
}
secure_key ()
{
rm -f "$EASYRSA_PKI/$EASYRSA_SP/$REQ_name.key"
rm -f "$EASYRSA_PKI/$EASYRSA_SP/$EASYRSA_REQ_CN.key"
[ $((LIVE_PKI)) -eq 1 ] || rm -f "$EASYRSA_PKI/$EASYRSA_SP/ca.key"
rm -f "$EASYRSA_PKI/$REQ_name.creds"
}
cleanup ()
{
print "Unit-test: cleanup"
if [ -z "$SAVE_PKI" ]; then
print "Remove temp dir: $TEMP_DIR"
rm -rf "$TEMP_DIR"
else
print "Saving temp dir: SAVE_PKI=$SAVE_PKI"
fi
cd ..
}
create_vars ()
{
#print ' set_var EASYRSA_FIX_OFFSET 163'
print ' set_var EASYRSA_DN "org"'
print '# Unsupported characters:'
print '# `'
print '# $'
print '# "'
print '# single-quote'
print '# #'
print '# & (Win)'
print ' set_var EASYRSA_REQ_COUNTRY "00"'
print ' set_var EASYRSA_REQ_PROVINCE "test"'
print ' set_var EASYRSA_REQ_CITY "TEST ,./<> ?;:@~ []!%^ *()-= _+| (23) TEST"'
print ' set_var EASYRSA_REQ_ORG "example.org Skåne Eslöv"'
print ' set_var EASYRSA_REQ_EMAIL "[email protected]"'
print ' set_var EASYRSA_REQ_OU "TEST esc \{ \} \£ \¬ (4) TEST"'
}
create_custom_opts ()
{
head -n 91 "$YACF.orig"
print "1.organizationName = Second Organization Name"
print "1.organizationName_default = \$ENV::CUSTOM_EASYRSA_REQ_ORG2"
tail -n +91 "$YACF.orig"
}
create_req ()
{
export EASYRSA_PKI="$TEMP_DIR/$NEW_PKI"
init_pki
verbose_update
cp "$TEMP_DIR/vars.utest" "$EASYRSA_PKI/vars" || die "New vars"
export EASYRSA_BATCH=1
export EASYRSA_REQ_CN="maximilian"
LIVE_PKI=1
build_sub_ca
verbose_update
[ -f "$EASYRSA_PKI/reqs/ca.req" ] && \
mv "$EASYRSA_PKI/reqs/ca.req" "$EASYRSA_PKI/reqs/$EASYRSA_REQ_CN.req"
export EASYRSA_REQ_CN="specter"
gen_req
verbose_update
export EASYRSA_REQ_CN="meltdown"
gen_req
verbose_update
export EASYRSA_REQ_CN="heartbleed"
gen_req
verbose_update
export EASYRSA_REQ_CN="VORACLE"
gen_req "--subject-alt-name=DNS:www.example.org,IP:0.0.0.0"
verbose_update
unset LIVE_PKI
unset EASYRSA_REQ_CN
unset EASYRSA_BATCH
unset EASYRSA_PKI
}
restore_req ()
{
[ "$EASYRSA_ALGO" ] || die "restore_req - missing algo"
STEP_NAME="Restore sample requests for ALGO: $EASYRSA_ALGO"
rm -rf "$TEMP_DIR/pki-req-$EASYRSA_ALGO"
mkdir -p "$TEMP_DIR/pki-req-$EASYRSA_ALGO"
# ubuntu: cp -R, -r, --recursive (copy directories recursively)
# Windows: cp.exe -R --recursive (-r copy recursively, non-directories as files)
# xcode10.1: cp -R only, does not support --recursive
cp -f -R \
"${TEMP_DIR}/pki-bkp-${EASYRSA_ALGO}/"* \
"$TEMP_DIR/pki-req-$EASYRSA_ALGO" \
2>"$ACT_ERR" 1>"$ACT_OUT" || die "$STEP_NAME"
rm -f "$ACT_ERR" "$ACT_OUT"
vcompleted "$STEP_NAME"
}
move_ca ()
{
newline 3
STEP_NAME="Send $EASYRSA_ALGO sub-ca maximilian to origin"
verbose "$STEP_NAME"
mv "$EASYRSA_PKI/issued/$REQ_name.crt" "$TEMP_DIR/pki-req-$EASYRSA_ALGO/ca.crt" 2>"$ACT_ERR" 1>"$ACT_OUT" || die "$STEP_NAME"
rm -f "$ACT_ERR" "$ACT_OUT"
completed
vcompleted "$STEP_NAME"
STEP_NAME="Change PKI to $EASYRSA_ALGO sub-ca maximilian"
verbose "$STEP_NAME"
export EASYRSA_PKI="$TEMP_DIR/pki-req-$EASYRSA_ALGO"
completed
vcompleted "$STEP_NAME"
}
action ()
{
# Required to support $PATH with spaces (import-req)
ACT_FILE_NAME="$1"
ACT_OPTS="$2"
if [ "$EASYRSA_USE_PASS" ]; then
PASSIN_OPT=--passin=pass:EasyRSA
PASSOUT_OPT=--passout=pass:EasyRSA
else
unset -v PASSIN_OPT PASSOUT_OPT
fi
verbose "$EASYRSA_ALGO: \
${ACT_GLOBAL_OPTS:+"${ACT_GLOBAL_OPTS}" }$STEP_NAME${ACT_OPTS+ "$ACT_OPTS"}"
vverbose "$EASYRSA_ALGO: \
${ACT_GLOBAL_OPTS:+"${ACT_GLOBAL_OPTS}" }$STEP_NAME${ACT_OPTS+ "$ACT_OPTS"}"
newline
vvverbose "EASYRSA_OPENSSL: ${EASYRSA_OPENSSL}"
newline
# shellcheck disable=SC2086
if [ $((ERSA_OUT + SHOW_CERT_ONLY)) -eq 0 ]
then
vvverbose "\
***** $ERSA_BIN \
${PASSIN_OPT+"$PASSIN_OPT" }${PASSOUT_OPT+"$PASSOUT_OPT" }\
${ACT_GLOBAL_OPTS+"$ACT_GLOBAL_OPTS" }\
${STEP_NAME}${ACT_FILE_NAME+ "$ACT_FILE_NAME"}${ACT_OPTS+ "$ACT_OPTS"}"
"$ERSA_BIN" ${PASSIN_OPT+"$PASSIN_OPT" }${PASSOUT_OPT+"$PASSOUT_OPT" }\
${ACT_GLOBAL_OPTS+"${ACT_GLOBAL_OPTS} "}\
${STEP_NAME} \
"$ACT_FILE_NAME" "$ACT_OPTS" \
2>"$ACT_ERR" 1>"$ACT_OUT" \
|| die "<<<<< easyrsa <<<<< $STEP_NAME"
rm -f "$ACT_ERR" "$ACT_OUT"
else
vvverbose "\
***** $ERSA_BIN \
${PASSIN_OPT+"$PASSIN_OPT" }${PASSOUT_OPT+"$PASSOUT_OPT" }\
${ACT_GLOBAL_OPTS+"$ACT_GLOBAL_OPTS" }\
${STEP_NAME}${ACT_FILE_NAME+ "$ACT_FILE_NAME"}${ACT_OPTS+ "$ACT_OPTS"}"
"$ERSA_BIN" \
${PASSIN_OPT+"$PASSIN_OPT" }${PASSOUT_OPT+"$PASSOUT_OPT" }\
${ACT_GLOBAL_OPTS+"${ACT_GLOBAL_OPTS} "}\
${STEP_NAME} \
"$ACT_FILE_NAME" "$ACT_OPTS" \
|| die "<<<<< easyrsa <<<<< $STEP_NAME"
fi
completed
newline
}
execute_node ()
{
[ $LIVE_PKI ] || return 0
show_cert
renew_cert
show_cert
revoke_renewed_cert
# This revokes the renewed (2nd) cert
revoke_cert
}
init_pki ()
{
newline 3
STEP_NAME="init-pki"
action
}
build_ca ()
{
newline 1
STEP_NAME="build-ca nopass"
[ "$EASYRSA_USE_PASS" ] && STEP_NAME="build-ca"
action
}
build_sub_ca ()
{
newline 1
STEP_NAME="build-ca subca nopass"
[ "$EASYRSA_USE_PASS" ] && STEP_NAME="build-ca subca"
action
}
show_ca ()
{
newline 1
STEP_NAME="show-ca"
[ $((SHOW_CERT)) -eq 1 ] && SHOW_CERT_ONLY=1
action
unset SHOW_CERT_ONLY
}
pkcs_all() {
#PKCS#12
if [ "$EASYRSA_USE_PASS" ]; then
pkcs_export p12 nokey
else
pkcs_export p12 nokey nopass
fi
# PKCS#7
pkcs_export p7 noca
# PKCS#8
if [ -f "${EASYRSA_PKI}/private/${REQ_name}.key" ]
then
if [ "$EASYRSA_USE_PASS" ]; then
pkcs_export p8
else
pkcs_export p8 nopass
fi
fi
# PKCS#1
if [ "$EASYRSA_ALGO" = rsa ] && [ -f "${EASYRSA_PKI}/private/${REQ_name}.key" ]
then
if [ "$EASYRSA_USE_PASS" ]; then
pkcs_export p1
else
pkcs_export p1 nopass
fi
fi
}
pkcs_export ()
{
newline 1
pkcs_type="$1"
shift
opt_1="$1"
opt_2="$2"
STEP_NAME="export-$pkcs_type ${REQ_name}${opt_1:+ "$opt_1"}${opt_2:+ "$opt_2"}"
action
vcompleted "$STEP_NAME"
newline
}
build_full ()
{
newline 2
STEP_NAME="build-$REQ_type-full $REQ_name nopass inline"
[ "$EASYRSA_USE_PASS" ] && STEP_NAME="build-$REQ_type-full $REQ_name inline"
action
verify_cert
pkcs_all
secure_key
execute_node
}
build_san_full ()
{
newline 2
user_SAN="--subject-alt-name=DNS:primary.example.net,DNS:alternate.example.net,IP:0.0.0.0,IP:255.255.255.255"
STEP_NAME="$user_SAN build-$REQ_type-full $REQ_name nopass inline"
[ "$EASYRSA_USE_PASS" ] && STEP_NAME="$user_SAN build-$REQ_type-full $REQ_name inline"
action
verify_cert
pkcs_all
secure_key
execute_node
}
gen_req ()
{
newline 1
STEP_NAME="$1 gen-req $REQ_type $EASYRSA_REQ_CN nopass"
[ "$EASYRSA_USE_PASS" ] && STEP_NAME="$1 gen-req $REQ_type $EASYRSA_REQ_CN"
action
secure_key
}
sign_req ()
{
newline 1
STEP_NAME="sign-req $REQ_type $REQ_name nopass"
[ "$EASYRSA_USE_PASS" ] && STEP_NAME="sign-req $REQ_type $REQ_name"
action
verify_cert
pkcs_all
secure_key
execute_node
}
import_req ()
{
newline 2
REQ_file="${TEMP_DIR}/pki-req-${EASYRSA_ALGO}/reqs/${REQ_name}.req"
# Note: easyrsa still appears to work in batch mode for this action ?
unset EASYRSA_BATCH
STEP_NAME="import-req"
action "$REQ_file" "$REQ_name"
export EASYRSA_BATCH=1
}
show_req ()
{
newline 1
STEP_NAME="show-req $REQ_name"
[ $((SHOW_CERT)) -eq 1 ] && SHOW_CERT_ONLY=1
action
unset SHOW_CERT_ONLY
}
verify_cert ()
{
newline 1
STEP_NAME="verify $REQ_name"
[ $((SHOW_CERT)) -eq 1 ] && SHOW_CERT_ONLY=1
action
unset SHOW_CERT_ONLY
}
show_cert ()
{
newline 1
STEP_NAME="show-cert $REQ_name"
[ $((SHOW_CERT)) -eq 1 ] && SHOW_CERT_ONLY=1
action
unset SHOW_CERT_ONLY
}
show_crl ()
{
newline 2
STEP_NAME="show-crl"
[ $((SHOW_CERT)) -eq 1 ] && SHOW_CERT_ONLY=1
action
unset SHOW_CERT_ONLY
}
renew_cert ()
{
newline 1
wait_sec
# This will probably need an inline option
STEP_NAME="renew $REQ_name nopass"
[ "$EASYRSA_USE_PASS" ] && STEP_NAME="renew $REQ_name"
action
verify_cert
pkcs_all
secure_key
}
revoke_renewed_cert ()
{
newline 1
wait_sec
# This will probably need an inline option
STEP_NAME="revoke-renewed $REQ_name superseded"
action
secure_key
}
revoke_cert ()
{
newline 1
STEP_NAME="revoke $REQ_name cessationOfOperation"
CAT_THIS="$EASYRSA_PKI/index.txt"
action
secure_key
}
status_reports ()
{
newline 1
STEP_NAME="show-expire"
action
newline 1
STEP_NAME="show-revoke"
action
newline 1
STEP_NAME="show-renew"
action
}
gen_crl ()
{
newline 2
STEP_NAME="gen-crl"
action
CAT_THIS="$EASYRSA_PKI/crl.pem"
cat_file
}
cat_file ()
{
[ $((ERSA_OUT)) -eq 1 ] || return 0
#newline
#vverbose "cat $CAT_THIS"
newline
[ -f "$CAT_THIS" ] || die "cat $CAT_THIS"
[ $((VVERBOSE)) -eq 1 ] && cat "$CAT_THIS"
newline
}
create_pki ()
{
newline 3
vvverbose "$STAGE_NAME"
restore_req || die "restore_req failed"
ssl_version="$("$EASYRSA_OPENSSL" version)"
printf '%s\n' "" "* EASYRSA_OPENSSL:" \
" $EASYRSA_OPENSSL (env)" " ${ssl_version}" ""
[ "$EASYRSA_USE_PASS" ] && print "* Use Passwords!" && print
export EASYRSA_PKI="$TEMP_DIR/$NEW_PKI"
vvverbose "* EASYRSA_PKI: $EASYRSA_PKI"
if [ "$EASYRSA_PKI" = "$TEMP_DIR/pki-empty" ] || [ "$EASYRSA_PKI" = "$TEMP_DIR/pki-error" ]
then
vverbose "OMITTING init-pki"
else
init_pki
cp "$TEMP_DIR/vars.utest" "$EASYRSA_PKI/vars" || die "New vars"
fi
export EASYRSA_BATCH=1
LIVE_PKI=1
LOG_INDENT="$LOG_INDENT_1"
export EASYRSA_REQ_CN="penelope"
build_ca
show_ca
REQ_type="server"
REQ_name="s01"
build_full
REQ_type="server"
REQ_name="s02"
build_san_full
REQ_type="serverClient"
REQ_name="s03"
build_full
status_reports
REQ_type="serverClient"
REQ_name="s04"
build_san_full
REQ_type="client"
REQ_name="c01"
build_full
REQ_type="server"
REQ_name="specter"
import_req
sign_req
REQ_type="serverClient"
REQ_name="heartbleed"
import_req
sign_req
REQ_type="serverClient"
REQ_name="VORACLE"
import_req
sign_req
REQ_type="client"
REQ_name="meltdown"
import_req
sign_req
gen_crl
show_crl
unset LIVE_PKI
REQ_type="ca"
REQ_name="maximilian"
import_req
sign_req
secure_key
# goto sub-ca maximilian
LOG_INDENT=""
move_ca
LOG_INDENT="$LOG_INDENT_2"
LIVE_PKI=1
show_ca
REQ_type="server"
REQ_name="specter"
sign_req
REQ_type="serverClient"
REQ_name="heartbleed"
sign_req
REQ_type="serverClient"
REQ_name="VORACLE"
sign_req
REQ_type="client"
REQ_name="meltdown"
sign_req
gen_crl
show_crl
unset LIVE_PKI
secure_key
unset EASYRSA_BATCH
unset EASYRSA_PKI
unset LOG_INDENT
newline 2
vcompleted "$STAGE_NAME (Errors: $S_ERRORS)"
S_ERRORS=0
newline 3
}
######################################
# This is badly copied from easyrsa and not fixed, yet..
# Register cleanup on EXIT
#trap "exited 0" 0
# When SIGHUP, SIGINT, SIGQUIT, SIGABRT and SIGTERM,
# explicitly exit to signal EXIT (non-bash shells)
trap "failed 1" 1
trap "failed 2" 2
trap "failed 3" 3
trap "failed 6" 6
trap "failed 15" 15
ERSA_UTEST_VERSION="2.3.0"
# Options
while [ "$1" ]
do