Skip to content

Commit 52551e7

Browse files
committed
Merge branch 'TinCanTech-ca-via-raw'
Signed-off-by: Richard T Bonhomme <[email protected]>
2 parents a7284a1 + f4b48ee commit 52551e7

File tree

2 files changed

+69
-63
lines changed

2 files changed

+69
-63
lines changed

ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
Easy-RSA 3 ChangeLog
22

3+
3.1.5 (2023-06-12)
4+
* build-ca: New command option 'raw-ca', abbrevation: 'raw' (#963)
5+
6+
This 'raw' method, is the most reliable way to build a CA,
7+
with a password, without writing the CA password to a temp-file.
8+
9+
This option completely replaces both methods below:
10+
11+
* build-ca: New option --ca-via-stdin, use SSL -pass* argument 'stdin' (#959)
12+
Option '--ca-via-stdin' offers no more security than standard method.
13+
Easy-RSA version 3.1.4 ONLY.
14+
15+
* build-ca: Replace password temp-files with file-descriptors (#955)
16+
Using file-descriptors does not work in Windows.
17+
Easy-RSA version 3.1.3 ONLY.
18+
319
3.1.4 (2023-05-23)
420
* build-ca: New option --ca-via-stdin, use SSL -pass* argument 'stdin' (#959)
521
* build-ca: Revert manual CA password method to temp-files (#959)

easyrsa3/easyrsa

Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ cmd_help() {
9898
Creates a new CA"
9999

100100
opts="
101+
* raw-ca - ONLY use SSL binary to input CA password
102+
raw (Equivalent to global option '--raw-ca')
103+
101104
* nopass - Do not encrypt the private key (default is encrypted)
102105
(Equivalent to global option '--nopass|--no-pass')
106+
103107
* subca - Create an intermediate CA keypair and request
104-
(default is a root CA)
105-
* intca - Alias to the above"
108+
intca (default is a root CA)"
106109
;;
107110
gen-dh)
108111
text="
@@ -470,7 +473,7 @@ General options:
470473
Can not be used with --passin or --passout
471474
--passin=ARG : Set -passin ARG for openssl (eg: pass:xEasyRSAy)
472475
--passout=ARG : Set -passout ARG for openssl (eg: pass:xEasyRSAy)
473-
--ca-via-stdin : Build CA with password via 'stdin' (New method)
476+
--raw-ca : Build CA with password via RAW SSL input
474477

475478
--vars=FILE : Define a specific 'vars' file to use for Easy-RSA config
476479
(Default vars file is in the EasyRSA PKI directory)
@@ -1356,7 +1359,7 @@ install_data_to_pki() {
13561359

13571360
# Short circuit for x509-types-only
13581361
if [ "$context" = x509-types-only ]; then
1359-
verbose "install_data_to_pki x509-types-only COMPLETED"
1362+
verbose "install_data_to_pki: x509-types-only COMPLETED"
13601363
return
13611364
fi
13621365

@@ -1461,6 +1464,7 @@ build_ca() {
14611464
nopass)
14621465
[ "$prohibit_no_pass" ] || EASYRSA_NO_PASS=1
14631466
;;
1467+
raw-ca|raw) EASYRSA_RAW_CA=1 ;;
14641468
*) warn "Ignoring unknown command option: '$1'"
14651469
esac
14661470
shift
@@ -1481,11 +1485,17 @@ build_ca() {
14811485
x509=1
14821486
fi
14831487

1484-
# If encrypted then create the CA key with AES256 cipher
1485-
if [ "$EASYRSA_NO_PASS" ]; then
1486-
unset -v cipher
1488+
# RAW mode must take priority
1489+
if [ "$EASYRSA_RAW_CA" ]; then
1490+
unset -v EASYRSA_NO_PASS EASYRSA_PASSOUT EASYRSA_PASSIN
1491+
verbose "build-ca: CA password RAW method"
14871492
else
1488-
unset -v no_password
1493+
# If encrypted then create the CA key with AES256 cipher
1494+
if [ "$EASYRSA_NO_PASS" ]; then
1495+
unset -v cipher
1496+
else
1497+
unset -v no_password
1498+
fi
14891499
fi
14901500

14911501
# Test for existing CA, and complain if already present
@@ -1573,9 +1583,21 @@ to the latest Easy-RSA release."
15731583
die "build_ca - easyrsa_mktemp out_file_tmp"
15741584

15751585
# Get passphrase from user if necessary
1576-
unset -v CA_key_pass
1586+
if [ "$EASYRSA_RAW_CA" ]
1587+
then
1588+
# Passphrase will be provided
1589+
confirm "
1590+
Accept ? " yes "\
1591+
Raw CA mode
1592+
===========
1593+
1594+
CA password must be input THREE times:
15771595

1578-
if [ "$EASYRSA_NO_PASS" ]
1596+
1. Set the password.
1597+
2. Confirm the password.
1598+
3. Use the password. (Create the Root CA)"
1599+
1600+
elif [ "$EASYRSA_NO_PASS" ]
15791601
then
15801602
: # No passphrase required
15811603

@@ -1601,32 +1623,17 @@ to the latest Easy-RSA release."
16011623

16021624
# Validate passphrase
16031625
if [ "$p" ] && [ "$p" = "$q" ]; then
1604-
if [ "$EASYRSA_CA_PASS_NEW" ]; then
1605-
# CA password via stdin
1606-
CA_key_pass="$p"
1607-
1608-
# To use stdin for -passin and -passout
1609-
# MUST use -batch
1610-
ssl_batch=1
1611-
1612-
# Helpful info, in case of failure
1613-
error_info="\
1614-
EasyRSA 'build-ca' has failed due to use of OpenSSL password
1615-
argument 'stdin'. Please report this error to EasyRSA."
1616-
1617-
else
1618-
# CA password via temp-files
1619-
in_key_pass_tmp=""
1620-
easyrsa_mktemp in_key_pass_tmp || \
1621-
die "build_ca - in_key_pass_tmp"
1622-
out_key_pass_tmp=""
1623-
easyrsa_mktemp out_key_pass_tmp || \
1624-
die "build_ca - out_key_pass_tmp"
1625-
printf "%s" "$p" > "$in_key_pass_tmp" || \
1626-
die "in_key_pass_tmp: write"
1627-
printf "%s" "$p" > "$out_key_pass_tmp" || \
1628-
die "out_key_pass_tmp: write"
1629-
fi
1626+
# CA password via temp-files
1627+
in_key_pass_tmp=""
1628+
easyrsa_mktemp in_key_pass_tmp || \
1629+
die "build_ca - in_key_pass_tmp"
1630+
out_key_pass_tmp=""
1631+
easyrsa_mktemp out_key_pass_tmp || \
1632+
die "build_ca - out_key_pass_tmp"
1633+
printf "%s" "$p" > "$in_key_pass_tmp" || \
1634+
die "in_key_pass_tmp: write"
1635+
printf "%s" "$p" > "$out_key_pass_tmp" || \
1636+
die "out_key_pass_tmp: write"
16301637
unset -v p q
16311638
else
16321639
unset -v p q
@@ -1659,19 +1666,15 @@ to the latest Easy-RSA release."
16591666
EASYRSA_SSL_CONF="$conf_tmp"
16601667

16611668
# Generate CA Key
1662-
if [ "$EASYRSA_CA_PASS_NEW" ]; then
1669+
if [ "$EASYRSA_RAW_CA" ]; then
16631670
case "$EASYRSA_ALGO" in
16641671
rsa)
16651672
if easyrsa_openssl genpkey \
16661673
-algorithm "$EASYRSA_ALGO" \
16671674
-pkeyopt \
16681675
rsa_keygen_bits:"$EASYRSA_ALGO_PARAMS" \
16691676
-out "$out_key_tmp" \
1670-
${cipher:+ "$cipher"} \
1671-
-pass stdin \
1672-
<<-EOF
1673-
${CA_key_pass}
1674-
EOF
1677+
${cipher:+ "$cipher"}
16751678
then
16761679
: # ok
16771680
else
@@ -1682,11 +1685,7 @@ to the latest Easy-RSA release."
16821685
if easyrsa_openssl genpkey \
16831686
-paramfile "$EASYRSA_ALGO_PARAMS" \
16841687
-out "$out_key_tmp" \
1685-
${cipher:+ "$cipher"} \
1686-
-pass stdin \
1687-
<<-EOF
1688-
${CA_key_pass}
1689-
EOF
1688+
${cipher:+ "$cipher"}
16901689
then
16911690
: # ok
16921691
else
@@ -1697,11 +1696,7 @@ to the latest Easy-RSA release."
16971696
if easyrsa_openssl genpkey \
16981697
-algorithm "$EASYRSA_CURVE" \
16991698
-out "$out_key_tmp" \
1700-
${cipher:+ "$cipher"} \
1701-
-pass stdin \
1702-
<<-EOF
1703-
${CA_key_pass}
1704-
EOF
1699+
${cipher:+ "$cipher"}
17051700
then
17061701
: # ok
17071702
else
@@ -1712,7 +1707,7 @@ to the latest Easy-RSA release."
17121707
esac
17131708

17141709
verbose "\
1715-
build_ca: CA key password created via stdin"
1710+
build_ca: CA key password created via RAW"
17161711

17171712
else
17181713
case "$EASYRSA_ALGO" in
@@ -1751,18 +1746,13 @@ build_ca: CA key password created via temp-files"
17511746
fi
17521747

17531748
# Generate the CA keypair:
1754-
if [ "$EASYRSA_CA_PASS_NEW" ]; then
1749+
if [ "$EASYRSA_RAW_CA" ]; then
17551750
if easyrsa_openssl req -utf8 -new \
17561751
-key "$out_key_tmp" \
17571752
-out "$out_file_tmp" \
1758-
${ssl_batch:+ -batch} \
17591753
${x509:+ -x509} \
17601754
${date_stamp:+ -days "$EASYRSA_CA_EXPIRE"} \
1761-
${EASYRSA_DIGEST:+ -"$EASYRSA_DIGEST"} \
1762-
-passin stdin \
1763-
<<-EOF
1764-
${CA_key_pass}
1765-
EOF
1755+
${EASYRSA_DIGEST:+ -"$EASYRSA_DIGEST"}
17661756
then
17671757
: # ok
17681758
unset -v error_info
@@ -1771,7 +1761,7 @@ build_ca: CA key password created via temp-files"
17711761
fi
17721762

17731763
verbose "\
1774-
build_ca: CA certificate password created via stdin"
1764+
build_ca: CA certificate password created via RAW"
17751765

17761766
else
17771767
easyrsa_openssl req -utf8 -new \
@@ -6220,9 +6210,9 @@ while :; do
62206210
--passout)
62216211
export EASYRSA_PASSOUT="$val"
62226212
;;
6223-
--ca-via-stdin)
6213+
--raw-ca)
62246214
empty_ok=1
6225-
export EASYRSA_CA_PASS_NEW=1
6215+
export EASYRSA_RAW_CA=1
62266216
;;
62276217
--notext|--no-text)
62286218
empty_ok=1

0 commit comments

Comments
 (0)