Skip to content

Commit

Permalink
New Command 'rand': 'Expose easyrsa_random() to the command line
Browse files Browse the repository at this point in the history
Usage: 'easyrsa rand <decimal_number>'

Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Dec 8, 2023
1 parent ce435be commit 4f66e6d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions easyrsa3/easyrsa
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ cmd_help() {
default-san <file_name_base>

Display EKU of certificate:
show-eku <file_name_base>"
show-eku <file_name_base>

Generate random hex:
rand <decimal_number>"
;;
opts|options)
opt_usage
Expand Down Expand Up @@ -669,16 +672,18 @@ easyrsa_random() {
die "easyrsa_random - input"
esac

unset -v rand_hex
if rand_hex="$(
OPENSSL_CONF=/dev/null \
"$EASYRSA_OPENSSL" rand -hex "$1"
)"
then
if [ "$2" ]; then
force_set_var "$2" "$rand_hex"
else
print "$rand_hex"
fi
return
unset -v rand_hex
return 0
fi

die "easyrsa_random failed"
Expand Down Expand Up @@ -6057,20 +6062,21 @@ cmd="$1"

# Establish PKI and CA initialisation requirements
# This avoids unnecessary warnings and notices
unset -v require_pki require_ca ignore_vars
case "$cmd" in
''|help|-h|--help|--usage|version|show-host)
unset -v require_pki require_ca
''|help|-h|--help|--usage| \
version|show-host|rand|random)
ignore_vars=1
;;
init-pki|clean-all)
unset -v require_pki require_ca
: # No change
;;
*)
require_pki=1
case "$cmd" in
gen-req|gen-dh|build-ca|show-req| \
make-safe-ssl|export-p*|inline)
unset -v require_ca
: # No change
;;
*)
require_ca=1
Expand Down Expand Up @@ -6275,6 +6281,10 @@ case "$cmd" in
ssl_cert_x509v3_eku "$@" || \
easyrsa_exit_with_error=1
;;
rand|random)
easyrsa_random "$1"
cleanup ok
;;
""|help|-h|--help|--usage)
verify_working_env
cmd_help "$1"
Expand Down

0 comments on commit 4f66e6d

Please sign in to comment.