Commit Graph
963 Commits
Author SHA1 Message Date
Richard T Bonhomme 82a52d1a9f Always configure OPENSSL_CONF=/dev/null when there is no SSL config
This applies to all direct calls using EASYRSA_OPENSSL (Default: 'openssl'),
which bypass using easyrsa_openssl() wrapper function.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-19 21:51:45 +01:00
Richard T Bonhomme e207f855eb openeasy_easyrsa: Remove unused variable 'has_config'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-19 03:02:55 +01:00
Richard T Bonhomme d4fa9bdb6d easyrsa_openssl: Replace variable 'has_config' with OPENSSL_CONF
Variable 'has_config' was a way to minimize the need to fully expand the
SSL config file (ENV:OPENSSL_CONF) for use by LibreSSL. IE. Only expand
the SSL config file when the SSL command requires a config file.

LibreSSL Always requires the config file to be expanded, even when it
is Not used.

OpenSSL Never requires the config file to be expanded.

Changes follow.

The first part:
* Disable expanding the SSL config file for OpenSSL.
* Require expanding the SSL config file for LibreSSL.

LibreSSL will use the run-once mechanism to expand the SSL config file.

The second part:
Replace the use of SSL option '-config', by Always configuring the SSL
environment variable OPENSSL_CONF to point to the Easy-RSA generated
config file. This is supported by LibreSSL and OpenSSL.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-19 02:17:20 +01:00
Richard T Bonhomme affb1e712b Only verify working environment for recognised commands
Otherwise, unrecognised commands trigger missing PKI and CA errors,
instead of the correct 'unrecognised command' error.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-17 22:35:58 +01:00
Richard T Bonhomme 2dd1077a10 Rename 'conf_tmp' temp-file to 'raw_ssl_cnf_tmp'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-17 17:56:33 +01:00
Richard T Bonhomme 1f65bb2386 easyrsa_mktemp: Make verbose msg shorter, remove text 'temp-file'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-17 03:26:49 +01:00
Richard T Bonhomme f05fdccd76 escape_hazard: Rename temp-file vars_org_tmp -> escape_hazard_tmp
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-17 03:21:41 +01:00
Richard T Bonhomme d80040ba09 Integrate '$has_config' into expand_ssl_config() and escape_hazard()
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-17 03:02:26 +01:00
Richard T Bonhomme f352b6f40f Set run-once correctly, for expand_ssl_config() and escape_hazard()
Set run-once after if condition, otherwise Forced execution does not
set run-once.

Use "local" variable 'makesafeconf' to force a new safe ssl config.

Remove variable require_safe_ssl_conf, partially replaced by makesafeconf.

Add 'make-safe-ssl' command to the list which does not require a CA.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 23:56:44 +01:00
Richard T Bonhomme 22ff0eae39 Rename variable easyrsa_safe_ssl_conf -> safe_ssl_cnf_tmp
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 21:57:11 +01:00
Richard T Bonhomme 4bde4824b7 Rename function easyrsa_rewrite_ssl_config() -> expand_ssl_config()
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 21:51:37 +01:00
Richard T Bonhomme 352d0fa8bf escape_hazard(): Rename temp-file easyrsa_vars_org -> vars_org_tmp
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 21:42:48 +01:00
Richard T Bonhomme 6edd8ce13c easyrsa_openssl(): Refactor expand SSL conf and escaping hazard
easyrsa_openssl(): Move run-control to functions easyrsa_rewrite_ssl_config()
and escape_hazard().  Replaces complex control code in easyrsa_openssl().

Run-control supports:
* EASYRSA_FORCE_SAFE_SSL: --force-safe-ssl, ALWAYS run.
* EASYRSA_NO_SAFE_SSL: --no-safe-ssl, NEVER run.
* Run-once: Default, run-once only.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 21:22:12 +01:00
Richard T Bonhomme 6e585eda19 build-ca: Use create_x509_type() correctly; Remove errant characters
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 13:56:20 +01:00
Richard T Bonhomme 6f806d9577 sign-req: Remove useless use of cat
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 03:01:39 +01:00
Richard T Bonhomme a1c9b016b2 sign-req: Confirm Netscape extension use immediately
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 02:46:30 +01:00
Richard T Bonhomme c03e1eef84 check_serial_unique(): Reduction
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 01:50:27 +01:00
Richard T Bonhomme 8ca55cfff0 sign-req: Unique serial, check input serial is hexadecimal only
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-16 00:27:56 +01:00
Richard T Bonhomme a78babf835 sign-req: Use correct x509-type COMMON temp-file name
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-15 22:06:56 +01:00
Richard T Bonhomme 93a8980c5e sign-req: Error check creation of x509-type temp-files
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-15 21:43:47 +01:00
Richard T Bonhomme 7039d02952 Add vars.example here-doc and move here-docs code to lower section
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-15 21:13:13 +01:00
Richard T Bonhomme 8cdfbb2ffe Minor cleanup of Unique random serial number control
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-14 21:43:29 +01:00
Richard T Bonhomme 3789aff3f5 Unset initial variables: Remove 'user_san_true', no longer used
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-14 15:56:03 +01:00
Richard T Bonhomme fdb8e0e8df Add show-req to the list of commands which do not require a CA
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-14 13:53:37 +01:00
Richard T Bonhomme e5f3551710 sign-req: Major refactor
Move extension data preparation to before printing extension temp-file.
This allows the { extensions output command group } to always complete,
without error.

Consolidate create_x509_type_*() functions in one single function.
create_x509_type_easyrsa() remains as a separate function.
This file does not exist in x509-types directory. It is similar to the
COMMON x509-type; The details are the common extensions shared by x509
types: serverClient, server and client. Not suitable for x509-type ca.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-14 13:51:18 +01:00
Richard T Bonhomme b0a3ec9caf check_serial_unique(): In batch mode, exit-with-error for non-unique
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-13 16:41:16 +01:00
Richard T Bonhomme aa38037570 Expose display_dn, display_san and default_server_san to command line
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-13 12:44:39 +01:00
Richard T Bonhomme cdad3a7844 Expose 'sign-req' unique, random serial number check to command line
Problem:

EasyRSA uses SSL CA command parameter '-serial $serial_number',
to check if a serial-number exists within the database.

The primary function of the SSL CA command parameter '-serial'
is to check if a certificate is Valid or has been Revoked.

EasyRSA abuses the SSL output to infer that a serial-number must
be unique because that output contains the text 'not present in db'.

SSL CA command parameter '-serial' ALWAYS returns an error,
reagrdless of what-ever check it does. Likely, an SSL bug.

As a step-in-the-right direction:

To ease this needless-headache, expose the unique, random
serial-number check to the command line.

This helps to understand what is going on under-the-hood.

The command 'sign-req' remains the same; except the unique, random
serial-number check is moved to a separate, stand-alone function,
which is also exposed to the command line for validation.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-12 23:15:35 +01:00
Richard T Bonhomme 3cb911ef2a Very minor changes to comments, help/msg text, wrap lines, code
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-08 19:04:10 +01:00
Richard T Bonhomme b16596f9ec cleanup: Rename $easyrsa_error_exit to $easyrsa_exit_with_error
This reduces a tiny, unnecessary complexity for exiting with an error.

Functions which use the new variable to exit with error:
* verify_cert() and confirm().

Also, allow verify-cert to support --silent-ssl.

Add more verbose messages.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-08 16:13:08 +01:00
Richard T Bonhomme 91bb2cf8e9 verify_ssl_lib(): Minor style improvements
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-05 22:26:40 +01:00
Richard T Bonhomme ac0d826272 Add command show-host to command list that does not require a PKI
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-04 22:59:39 +01:00
Richard T Bonhomme 268e8f59fd vars_setup() and init-pki() 'vars' management improvements
The actual changes made are:

* Remove $old_vars_true, no longer required.

* Change a test of $found_vars from any-string to specific number 1.
  Which then tests for only one vars file is found.

* If vars-file is created during init-pki then also set $vars to file-name.
  The change here is that $vars is now ALWAYS set for this condition.

* Always print the names of conflicting vars files.
  Helps debugging for users.

* Expand short-circuits to full 'if; then; else; fi'.

* Add more verbose messages
  Help for debugging.

The combined effect is to show the correct messages regarding vars file,
during default status, help, init-pki and standard further commands.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-04 20:39:23 +01:00
Richard T Bonhomme 5350d50e03 Format: Correct indentation
See: git diff -w

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-04 02:35:19 +01:00
Richard T Bonhomme 9f752bde7a vars_setup(): For EASYRSA_NO_VARS set found_vars to zero
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-04 02:14:08 +01:00
Richard T Bonhomme 7ec58cd64c Status: Use variable for ca.crt name and correct found_vars value
'ca.crt' was hard-coded to 'pki/ca.crt', instead use '$EASYRSA_PKI/ca.crt'

Status incorrectly warns that there are multiple, conflicting vars files,
when vars is user-defined. Set '$found_vars' to 1, when vars is user-defined.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-04 01:56:18 +01:00
Richard T Bonhomme e2e2d1bfa1 Expand default status to include vars-file and CA status
For default command 'easyrsa', show the following:
* Show the location of vars-file.
* Show the status of the CA.
* If vars is not in the PKI then show the "Prefer pki/vars" warning.

Also, show the "Prefer pki/vars" warning for all commands except help.

Move the logic to show the "Prefer pki/vars" warning to the function.

Extensively, manually tested.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-03 23:32:28 +01:00
Richard T Bonhomme 97b9a4c665 vars-file: Warn about EASYRSA_NO_VARS disabling vars-file use
Also, minor improvement to checking vars-file for 'export' and 'unset'.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-03 13:13:30 +01:00
Richard T Bonhomme 8e62fa28d7 set_var(): Allow empty input to return without error
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-03 02:04:18 +01:00
Richard T Bonhomme 002c84fff1 verify_working_env(): Simple improvements, no functional changes
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-03 01:32:27 +01:00
Richard T Bonhomme 3db8c50782 Prefer test for '-z' over '!'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-02 22:13:18 +01:00
Richard T Bonhomme a8567ba80d Merge branch 'post-315-refactor' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-post-315-refactor
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-02 21:38:27 +01:00
Richard T Bonhomme 444444595e Simplify requirements for PKI, CA and vars file
Prioritise $EASYRSA_NO_VARS above other vars file detection.

Rename $pki_is_required to $require_pki

Re-establish; Do not require PKI, CA or vars for command 'upgrade'.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-02 21:10:10 +01:00
Richard T Bonhomme 232f9f6b8d verify_working_env(): Verify PKI and CA are initialised as required
This moves all PKI and CA initialisation requirements into verify_working_env().

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-02 19:03:18 +01:00
Richard T Bonhomme 49fda49e25 cleanup(): Change die() to warn(), cleanup cannot use die()
Minor improvements to help and comments

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-01 22:05:45 +01:00
Richard T Bonhomme d29183721f sign-req: Allow the CSR DN-field order to be preserved
When signing a request, EasyRSA ALWAYS defaults to the CA defined
Distinguished Name field order, as defined by openssl-easyrsa.cnf
configuration file.

In the unlikely event that a CSR is received with a different DN-
field order, that order can be preserved for the signed certificate.

Command 'sign-req', now has a command option 'preserve' for this.

Additional:

Use of 'preserve = yes' in openssl-easyrsa.cnf has no effect for
EasyRSA.

Testing OpenSSL directly indicates that this option may have no effect
when used in OpenSSL default configuration file openssl.cnf

Also, OpenSSL documentation for command 'ca', option '-preserveDN'
does NOT infer that this option can be used in the configuration file.

None of which is important to EasyRSA because only foreign CSRs can
have a different DN-field order, so default behavior can remain.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-30 21:28:41 +01:00
Richard T Bonhomme dfd12562dc Introduce Easy-RSA error log-file - Used by easyrsa_mktemp
When commands executed in a subshell fail the error message is lost.

Easy-RSA error log provides a permanent temp-file to write those
error messages to and be displayed on completion of the script.

This first use of the log-file by easyrsa_mktemp(), will log errors
caused by requiring more than three (3) subshell temp-files.

Temp-files created during a subshell command do not update the
temp-file counter, so their name relies on a second, built-in
extension to the temp-file name. If this second extension exceeds
three (3) then a non-fatal warning is logged to the error log-file.

Other functions, which are executed in subshells, will use the error
log-file in follow up patches, as required.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-26 12:47:53 +01:00
Richard T Bonhomme f0aa171373 Introduce and use 'user_error()'
Replace use of die(), which is very noisy, with user_error(),
which simply outputs the error message and EasyRSA Version.

Use of user_error() is specific to input and file errors,
caused by invalid user input.

Internal errors continue to use die().

Other associated improvements to output.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-20 14:19:53 +01:00
Richard T Bonhomme a4fb7f0528 sign-req: Minor improvements; Remove function-end 'return 0'
Remove fucntion-end 'retrun 0' because it masks unexpected errors.

'if; then; else; fi;' wrap SSL call.

Minor improvements.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-20 00:21:47 +01:00
Richard T Bonhomme 71bedfd554 Brace '{}' delimit variable names in long assignment strings
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-19 20:48:37 +01:00