Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options: Introduce --keep-tmp=NAME; Keep the temporary session data #667

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions easyrsa3/easyrsa
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ non-empty values to options are mandatory.

General options:

--version : prints EasyRSA version and build information, then exits
--batch : set automatic (no-prompts when possible) mode
-s|--silent : Disable all Warnings and Notices
--sbatch : Combined --silent and --batch operating mode
Expand All @@ -442,7 +443,9 @@ General options:
--pki-dir=DIR : declare the PKI directory

--tmp-dir=DIR : declare the temporary directory
--version : prints EasyRSA version and build information, then exits
--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)

Expand Down Expand Up @@ -629,9 +632,20 @@ easyrsa_mktemp() {

# remove temp files and do terminal cleanups
cleanup() {
if [ "${EASYRSA_TEMP_DIR_session%/*}" ] && [ -d "$EASYRSA_TEMP_DIR_session" ]
if [ "${EASYRSA_TEMP_DIR_session%/*}" ] && \
[ -d "$EASYRSA_TEMP_DIR_session" ]
then
rm -rf "$EASYRSA_TEMP_DIR_session"
if [ "$EASYRSA_KEEP_TEMP" ]; then
keep_tmp="$EASYRSA_TEMP_DIR/$EASYRSA_KEEP_TEMP"
# Remove previous keep dir, created by --keep-temp
[ -d "$keep_tmp" ] && rm -rf "$keep_tmp"

mv -f "$EASYRSA_TEMP_DIR_session" "$keep_tmp"
information \
"Temp session preserved: $keep_tmp"
else
rm -rf "$EASYRSA_TEMP_DIR_session"
fi
fi

if [ "${EASYRSA_EC_DIR%/*}" ] && [ -d "$EASYRSA_EC_DIR" ]
Expand Down Expand Up @@ -3742,7 +3756,7 @@ show_host() {
print
print_version
print "$host_out | ${ssl_version:-ssl_version not currently set}"
[ ! "$EASYRSA_DEBUG" ] && return
[ "$EASYRSA_DEBUG" ] || return 0
case "$easyrsa_host_os" in
win) set ;;
nix) env ;;
Expand Down Expand Up @@ -4033,7 +4047,7 @@ Sourcing the vars file and building certificates will probably fail ..'

else
# If the directory does not exist then we have not run init-pki
# The temp-dir is Always created by 'install_data_to_pki'
# The temp-dir is ALWAYS verified by secure_session()
die "Temporary directory does not exist: $EASYRSA_TEMP_DIR"
fi
fi
Expand Down Expand Up @@ -4740,6 +4754,8 @@ while :; do
export EASYRSA_TEMP_DIR="$val" ;;
--ssl-conf)
export EASYRSA_SSL_CONF="$val" ;;
--keep-temp)
export EASYRSA_KEEP_TEMP="$val" ;;
--use-algo)
export EASYRSA_ALGO="$val" ;;
--keysize)
Expand Down