Skip to content

Commit 5ac76e5

Browse files
committed
Merge branch 'remove-init-pki-soft' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-remove-init-pki-soft
Signed-off-by: Richard T Bonhomme <[email protected]>
2 parents b8aacb7 + a26310a commit 5ac76e5

File tree

2 files changed

+10
-159
lines changed

2 files changed

+10
-159
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Easy-RSA 3 ChangeLog
22

33
3.2.3 (TBD)
44

5+
* build-ca: Remove TLS Key processing (c1c2a06) (#1351)
6+
* init-pki: Remove option 'soft' and TLS Key processing (976f864) (#1351)
57
* peer-fingerprint mode: Make CA mode mutually exclusive to PFP mode (8c1c435) (#1347)
68
* TLS key generation: Allow 'gen-tls-auth/crypt-key' without a CA Cert (2580dc2) (#1345)
79
* Inline_file(): Improvements self-signed integration (bc72a21) (#1345)

easyrsa3/easyrsa

Lines changed: 8 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ For a list of utility commands, use:
2828
./easyrsa help util
2929

3030
A list of commands is shown below:
31-
init-pki [ cmd-opts ]
31+
init-pki
3232
self-sign-server <file_name_base> [ cmd-opts ]
3333
self-sign-client <file_name_base> [ cmd-opts ]
3434
build-ca [ cmd-opts ]
@@ -123,12 +123,6 @@ Usage: easyrsa [ OPTIONS.. ] <COMMAND> <TARGET> [ cmd-opts.. ]"
123123
* init-pki [ cmd-opts ]
124124

125125
Removes & re-initializes the PKI directory for a new PKI"
126-
127-
opts="
128-
* hard - Recursively delete the ENTIRE PKI directory (default).
129-
* soft - Keep the named PKI directory and PKI 'vars' file intact.
130-
Also keep the current Request files,
131-
to be signed by a new CA (Partial CA renewal)."
132126
;;
133127
self-sign*)
134128
text="
@@ -1398,23 +1392,6 @@ $verify_ca_help_note"
13981392

13991393
# init-pki backend:
14001394
init_pki() {
1401-
# Process command options
1402-
reset="hard"
1403-
while [ "$1" ]; do
1404-
case "$1" in
1405-
hard-reset|hard)
1406-
reset="hard"
1407-
confirm_msg=
1408-
;;
1409-
soft-reset|soft)
1410-
reset="soft"
1411-
confirm_msg='PARTIALLY '
1412-
;;
1413-
*) warn "Ignoring unknown command option: '$1'"
1414-
esac
1415-
shift
1416-
done
1417-
14181395
# EasyRSA will NOT do 'rm -rf /'
14191396
case "$EASYRSA_PKI" in
14201397
.|..|./|../|.//*|..//*|/|//*|\\|?:|'')
@@ -1426,116 +1403,22 @@ init_pki() {
14261403
confirm "Confirm removal: " "yes" "
14271404
WARNING!!!
14281405

1429-
You are about to ${confirm_msg}remove the EASYRSA_PKI at:
1406+
You are about to remove the EASYRSA_PKI at:
14301407
* $EASYRSA_PKI
14311408

14321409
and initialize a fresh PKI here."
1433-
1434-
# now remove it:
1435-
case "$reset" in
1436-
hard)
1437-
# Promote use of 'init-pki soft':
1438-
confirm "
1439-
WARNING: COMPLETELY DESTROY current PKI (NOT recommended) ?
1440-
1441-
[yes/NO]: " yes "\
1442-
******************************************
1443-
* SECOND WARNING - STOP - SECOND WARNING *
1444-
******************************************
1445-
1446-
To keep your current 'pki/vars' settings use 'init-pki soft'.
1447-
To keep your current Request files use 'init-pki soft'
1448-
The Requests can then be signed by a new CA (Partial CA renewal)
1449-
To keep your current Easy-RSA TLS Key use 'init-pki soft'
1450-
This private key file is in use by your current VPN.
1451-
1452-
** USE OF 'init-pki soft' IS RECOMMENDED **${NL}"
1453-
1454-
# # # shellcheck disable=SC2115 # Use "${var:?}"
1455-
rm -rf "$EASYRSA_PKI" || \
1456-
die "init-pki hard reset failed."
1457-
;;
1458-
soft)
1459-
# There is no unit test for a soft reset
1460-
# Save existing TLS key
1461-
tls_key_file="$EASYRSA_PKI"/private/easyrsa-tls.key
1462-
old_tls_key_file="$EASYRSA_PKI"/easyrsa-keepsafe-tls.key
1463-
1464-
# If both keys exist then they must be the same
1465-
if [ -f "$old_tls_key_file" ]; then
1466-
if [ -f "$tls_key_file" ]; then
1467-
# Match by hash
1468-
tls_key_hash="$(
1469-
"$EASYRSA_OPENSSL" dgst -sha256 \
1470-
"$tls_key_file")"
1471-
tls_key_hash="${tls_key_hash##* }"
1472-
old_tls_key_hash="$(
1473-
"$EASYRSA_OPENSSL" dgst -sha256 \
1474-
"$old_tls_key_file")"
1475-
old_tls_key_hash="${old_tls_key_hash##* }"
1476-
[ "$tls_key_hash" = "$old_tls_key_hash" ] || \
1477-
user_error "\
1478-
Easy-RSA TLS Keys do not match, only ONE of these files is valid:
1479-
* $tls_key_file
1480-
* $old_tls_key_file
1481-
1482-
Please delete the key above that is no longer in use."
1483-
fi
1484-
fi
1485-
1486-
# Save existing TLS key
1487-
if [ -f "$tls_key_file" ]; then
1488-
tls_key_data="$(cat "$tls_key_file")"
1489-
else
1490-
tls_key_data=
1491-
fi
1492-
1493-
# Do NOT remove pki/reqs sub-dir, for "renew ca"
1494-
for i in ca.crt crl.pem \
1495-
issued private inline revoked renewed expired \
1496-
serial serial.old index.txt index.txt.old \
1497-
index.txt.attr index.txt.attr.old certs_by_serial
1498-
do
1499-
# # # shellcheck disable=SC2115 # Use "${var:?}"
1500-
target="$EASYRSA_PKI/$i"
1501-
if [ "${target%/*}" ]; then
1502-
rm -rf "$target" || \
1503-
die "init-pki soft reset(1) failed!"
1504-
else
1505-
die "init-pki soft reset(2) failed!"
1506-
fi
1507-
done
1508-
;;
1509-
*)
1510-
user_error "Unknown reset type: $reset"
1511-
esac
15121410
fi
15131411

1412+
# # # shellcheck disable=SC2115 # Use "${var:?}"
1413+
rm -rf "$EASYRSA_PKI" || \
1414+
die "init-pki hard reset failed."
1415+
15141416
# new dirs:
15151417
easyrsa_mkdir "$EASYRSA_PKI"
15161418
for i in issued private reqs; do
15171419
easyrsa_mkdir "${EASYRSA_PKI}/$i"
15181420
done
15191421

1520-
# If one existed then recreate old TLS key backup file
1521-
if [ "$tls_key_data" ]; then
1522-
header="# Easy-RSA TLS Key: $(date)${NL}# DO NOT DELETE"
1523-
printf '%s\n\n%s\n' "$header" "$tls_key_data" \
1524-
> "$old_tls_key_file"
1525-
tls_msg="${NL}
1526-
Previous Easy-RSA TLS key saved to:
1527-
* $old_tls_key_file${NL}"
1528-
else
1529-
# if an OLD TLS key still exists then notify user
1530-
if [ -f "$old_tls_key_file" ]; then
1531-
tls_msg="${NL}
1532-
Existing Easy-RSA TLS key preserved:
1533-
* $old_tls_key_file${NL}"
1534-
else
1535-
tls_msg=
1536-
fi
1537-
fi
1538-
15391422
# write pki/vars.example - no temp-file because no session
15401423
write_legacy_file_v2 \
15411424
vars "$EASYRSA_PKI"/vars.example overwrite || \
@@ -1553,7 +1436,7 @@ Your newly created PKI dir is:
15531436
select_vars
15541437
information "\
15551438
Using Easy-RSA configuration:
1556-
* ${EASYRSA_VARS_FILE:-undefined}${tls_msg}"
1439+
* ${EASYRSA_VARS_FILE:-undefined}"
15571440
} # => init_pki()
15581441

15591442
# Find support files from various sources
@@ -1733,40 +1616,6 @@ Unable to create necessary PKI files (permissions?)"
17331616
> "$EASYRSA_PKI/serial" || die "$err_msg"
17341617
unset -v err_msg
17351618

1736-
# If one exists then recreate TLS Key
1737-
tls_key_file="$EASYRSA_PKI"/private/easyrsa-tls.key
1738-
old_tls_key_file="$EASYRSA_PKI"/easyrsa-keepsafe-tls.key
1739-
if [ -f "$old_tls_key_file" ]; then
1740-
confirm "Re-install existing Easy-RSA TLS Key ? " yes "
1741-
An Easy-RSA TLS Key, saved by 'init-pki soft', has been found.
1742-
This TLS Key is in use by your VPN, it is recommended that you
1743-
re-install this TLS Key.
1744-
1745-
Note:
1746-
This is a private key and will NOT be added to new inline files.
1747-
1748-
To create a new Easy-RSA TLS Key, delete this old TLS Key above."
1749-
cp "$old_tls_key_file" "$tls_key_file" || \
1750-
warn "Failed to install TLS Key!"
1751-
tls_key_msg="${NL}
1752-
NOTICE: The previous Easy-RSA TLS Key has been installed:
1753-
* $tls_key_file
1754-
1755-
This TLS Key will NOT be added to new inline files. These new
1756-
inline files can then be easily distributed to your servers and
1757-
clients. The TLS Key that your servers and clients have previously
1758-
received, can be added to the inline file manually.
1759-
1760-
To re-enable automatically adding this TLS Key to inline files,
1761-
simply delete the backup TLS Key at:
1762-
* $old_tls_key_file
1763-
1764-
To create a new Easy-RSA TLS Key, delete both TLS Keys above."
1765-
else
1766-
tls_key_msg="${NL}
1767-
Create an OpenVPN TLS-AUTH|TLS-CRYPT-V1 key now: See 'help gen-tls'"
1768-
fi
1769-
17701619
# Set ssl batch mode, as required
17711620
[ "$EASYRSA_BATCH" ] && ssl_batch=1
17721621

@@ -2002,7 +1851,7 @@ Prior to signing operations, place your resulting Sub-CA cert at:
20021851
else
20031852
notice "\
20041853
CA creation complete. Your new CA certificate is at:
2005-
* $out_file${tls_key_msg}
1854+
* $out_file
20061855

20071856
Build-ca completed successfully."
20081857
fi

0 commit comments

Comments
 (0)