Commit Graph
917 Commits
Author SHA1 Message Date
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
Richard T Bonhomme c004c89034 Rename variable: duplicate_cert_by_serial -> dup_cert_by_serial
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-19 20:28:17 +01:00
Richard T Bonhomme d7aa07bc7f User level output, general improvements
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-18 00:42:13 +01:00
Richard T Bonhomme 4a18ed5e3a sign-req: Do not show "foreign request" warning during build-full
Only show the "foreign request" warning when sign-req is called for
an imported request. Do not show the warning when the request has
been created by build-full-*.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-17 21:29:13 +01:00
Richard T Bonhomme 0c95a37f08 Wrap long lines, improve comments and very minor changes
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-15 00:00:23 +01:00
Richard T Bonhomme db9507626b Auto-create x509-types: Corrections to buld-ca and sign-req
build-ca:
* Replace 'print foo' with function create_x509_types_ca()
* Replace 'ignore' with function create_x509_type_COMMON()

sign-req:
* Replace 'ignore' with function create_x509_type_COMMON()

Note: x509-types/COMMON only has comments, no code.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-14 21:24:51 +01:00
Richard T Bonhomme 9a70a50a0c sign-req: Correct variable assignment
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-09 22:04:37 +01:00
Richard T Bonhomme 1f39fce75c Automate support-file creation (Free packaging)
Create default files for openssl-easyrsa.cnf, vars.example and x509-types files.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-09 00:09:37 +01:00
Richard T Bonhomme c8ae6e3e6b build-ca: If specified, prioritise 'raw' method over all others
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-05 22:37:38 +01:00
Richard T Bonhomme 05b4fad370 build-ca: New command option 'raw-ca', abbrevation: 'raw'
This option bypasses the Easy-RSA code to manage the CA password.
The result is that the User MUST enter the CA password THREE times.
These three inputs are made directly to the SSL binary.
Easy-RSA will remain unaware of the CA password.

This is the most reliable way for Easy-RSA to create a CA, with a
password, without writing that password to a temp-file.

Equivalent to global option: '--raw-ca'

Usage:
* Command option: 'easyrsa build-ca raw-ca'
* Global option: 'easyrsa --raw-ca build-ca'

When specified, in ANY form, 'raw' method ALWAYS takes pririoty.

This change COMPLETELY removes the '--ca-via-stdin' method (v3.1.4),
which did not offer any more secuity than the standard method.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-06-05 20:56:57 +01:00
Richard T Bonhomme c1bf6a43d7 build-ca: Remove obsolete unit-test CA password variant
If this code s left in then the unit test always falls through to
testing a CA without a password.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-23 13:24:00 +01:00
Richard T Bonhomme 5d7ad1306d build-ca: Revert manual CA password method to temp-files
Change the integration of the following:
* build-ca: Replace password temp-file method with file-descriptors
* commit 27870d695a

Instead of 'replacing' the standard temp-file method, the new 'stdin'
method is offered as an alternative by using option '--ca-via-stdin'

Discussion:

Using EasyRSA temp-files means that these files can be written to
specific places. In the case of the CA password, it is recommended
to use a RAM-Disk to write CA password temp-files to.

Using heredocs to pass data via file-descriptors, in all probability,
will write the heredoc data to a temp-file managed by the shell in use.

Thus, there are temp-files written in both methods.

The difference being that, the EasyRSA managed temp-files can be written to
specific places, while the shell managed temp-files are out of EasyRSA scope.

In conclusion, both methods are offered, however, the default remains
as EasyRSA temp-files for the CA password method.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-22 23:08:42 +01:00
Richard T Bonhomme 51cb520887 build-ca: Force the unit-test to build CA with pass via 'stdin' method
ERSA_UTEST_VERSION and EASYRSA_USE_PASS are only defined when the unit-tests are run.
When they are detected, force use of CA password via 'stdin'.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-22 18:16:32 +01:00
Richard T Bonhomme c11135d19b build-ca: Use OpenSSL password I/O argument 'stdin'
When OpenSSL is built "for Windows", it does not support
password input/output via argument 'fd:N', file-descriptors.

However, OpenSSL built "for Windows" does allow use of 'stdin'.
eg: -pass:stdin (-passin/-passout)

There is one drawback; When using 'stdin' openssl cannot allow
further user input to customise the 'commonName', or any other
organisational fields used by '--dn-mode=org'. OpenSSL enforces
'-batch' when 'stdin' is used. Therefore, EasyRSA must set batch
mode, to correctly use 'stdin' to pass the CA password.

Creating CA key pair this way also requires that SSL option
'-keyout' be dropped from the create CA request command.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-21 21:31:57 +01:00
Richard T Bonhomme 60b5c03541 Squashed commit of the following:
commit d3592f1b6ea69bb93559108ac78c869308a8e2f3
Merge: ec1d428 05d0213
Author: Richard T Bonhomme <tincantech@protonmail.com>
Date:   Thu May 11 23:06:20 2023 +0100

    Merge branch 'verify-cert-direct-openssl-call' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-verify-cert-direct-openssl-call

    Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>

commit 05d0213d6dff4706d058442b6e9cddcad1124fbc
Author: Richard T Bonhomme <tincantech@protonmail.com>
Date:   Thu May 11 13:35:12 2023 +0100

    verify-cert: Call 'openssl' directly to capture error

    Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-11 23:07:07 +01:00
Richard T Bonhomme c2afcb6b45 Remove stray space characters and correct comment about OpenSSL
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-10 21:47:21 +01:00
Richard T Bonhomme 4eb6cd6b5f build-ca: Correct 'CA_key_pass' parameter expansion expression
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-10 01:14:34 +01:00
Richard T Bonhomme ead015aab1 build-ca: Remove unnecessary 'shellcheck' directive
shellcheck is a great tool but it must still be used with respect.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-10 01:07:50 +01:00
Richard T Bonhomme e5643386b8 build-ca: Rename 'out_key_pass' to 'CA_key_pass' (Disambiguation)
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-10 00:51:05 +01:00
Richard T Bonhomme 35def135be build-ca: Clear password variables in a 'shellcheck' friendly manner
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-10 00:39:37 +01:00
Richard T Bonhomme 385b7b279d build-ca: Unset crucial password variables
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-09 23:45:55 +01:00
Richard T Bonhomme a6129e3416 upgrade: Do not create second secure_session and format output
Command 'upgrade' was configured to create a second secure_session,
this is not allowed, so remove.

Minor format changes for 'show-expire' and --verbose output.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-09 12:30:50 +01:00
Richard T Bonhomme 0244306956 build-ca: 'if/then/else' wrap file-descriptor commands
Aesthetics, no functional change.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-09 02:27:12 +01:00
Richard T Bonhomme 3d14095384 build-ca: Remove new key if moving new certificate fails
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-08 22:51:38 +01:00
Richard T Bonhomme 57b91bed56 build-ca: Add option --ca-via-tf, use temp-files for CA password
This allows a fallback to use temp-files for CA password, in the event
that file-descriptor method fails.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-07 13:03:26 +01:00
Richard T Bonhomme 27870d695a build-ca: Replace password temp-file method with file-descriptors
Until now, EasyRSA has used temp-files to store the CA password and
passed those temp-files to SSL to build a CA keypair, when building
a CA manually, with a password.

From now, EasyRSA will use an internal variable to contain the CA
password and pass the value of that variable via file-descriptors
to SSL, when building a CA keypair.

This file-descriptor method is only used when building a CA with a
password manually, when the user enters the password via keyboard.
All other build-ca methods remain unchanged.

Also, move keypair temp-files to output files or error out.

Also, minor improvements to comments and verbose messages.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-06 20:49:10 +01:00
Richard T Bonhomme 9316a37417 easyrsa_openssl(): Move escape_hazaard() usage call
Move escape_hazard() to use the same control as easyrsa_rewrite_ssl_config().

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-06 20:04:53 +01:00
Richard T Bonhomme 7d6810ebb9 easyrsa_openssl(): Move saving SAFE SSL config name to correct place
Saving the name of the fully expanded Safe SSL config means that this
config file only has to be built once.

The assignment of working_safe_ssl_conf, which signifies that a Safe
SSL config has already been created, was set too late, which caused
it to be set even if the Safe SSL config had not been created.

Also, include a final check in verify_working_env() to ensure that
working_safe_ssl_conf has not been set prior to executing the issued
command, eg. build-ca.

Also, improve verbose messages and comments.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-06 15:50:26 +01:00
Richard T Bonhomme 601766bdaf verify_algo_params(): Call SSL lib via EASYRSA_OPENSSL
verify_algo_params() expects errors when settings are not corrrect.
Therefore, is must not use easyrsa_openssl() meta-wrapper, which would
error out with a misleading error message.

Fixing this also ensures that the SAFE SSL config is not built prior
to EASYRSA_REQ_CN being set.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-06 15:44:38 +01:00
Richard T Bonhomme e68a41c50f vars_setup(): Always assign EASYRSA_KEY_SIZE
EASYRSA_KEY_SIZE is present in the SSL config file, therefore,
it MUST always be set, regardless of EASYRSA_ALGO in use.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-06 15:39:45 +01:00
Richard T Bonhomme ba1b61f53c mutual_exclusions(): Use of --silent and --verbose is unresolvable
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-02 22:13:48 +01:00
Richard T Bonhomme 906df2dcec easyrsa_openssl(): makesafecnf - Copy temp-file do NOT move it
Command 'easyrsa_openssl makesafecnf' is used internally to create a safe
SSL config file. (By status reports, read_db())

Once the safe SSL config file has been named as a temp-file and created,
the script continues to use that temp-file as the master copy, it does not
recreate a safe SSL config file for subsequent calls to easyrsa_openssl().

Therefore, the temp-file MUST be copied to the standard safe SSL file not
moved. Otherwise, the named temp-file is removed.

Also, move the assignment of the safe SSL temp-file to the correct place.
This means that a new temp-file wiill only be assigned once.

Also, verify that the safe SSL temp-file exists when it is expected to.

Also, change use of '--no--safe-ssl' with LibreSSL to a FATAL error.

Other changes are for error and verbose messages.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-02 20:40:44 +01:00
Richard T Bonhomme e254ee4451 gen-req: Standardise error message for old easyrsa-openssl.cnf
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 22:30:40 +01:00
Richard T Bonhomme 625dae2339 vars.example: Rename EASYRSA_CERT_EXPIRE to EASYRSA_PRE_EXPIRE_WINDOW
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 22:05:09 +01:00
Richard T Bonhomme 55ee5fcfde X509-types insert markers: Move and improve
X509-types insert markers are used by 'awk' to insert data at specific
points in the easyrsa-openssl.cnf file in use.

The checks are moved to below more important imput checks

For build-ca, the check is ONLY done if EASYRSA_EXTRA_EXTS is defined.
This is exceedingly unlikely, because EASYRSA_EXTRA_EXTS is not documented.

For sign-req, the check is only done if --copy-ext isused.

Also, remove an over-indent in "Confirm use of NS extestions"

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 21:38:35 +01:00
Richard T Bonhomme a724ca91d1 sign-req: Require confirm use of deprecated Netscape extensions
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 21:17:48 +01:00
Richard T Bonhomme 4f1c16aa9f sign_req(): Move generte-random-serial-number below input checks
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 20:59:19 +01:00
Richard T Bonhomme f92fa738a9 gen-req, sign-req, build-full: Verify requirements correctly
* gen-req: Use verify_pki_init().
* sign-req: Use verify_ca_init().
* build-full: Defer requirements to functions above.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 20:32:49 +01:00
Richard T Bonhomme ddc87e9c0d Merge branch 'remove_secure_session-ROS' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-remove_secure_session-ROS
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 20:17:14 +01:00
Richard T Bonhomme b8455ad392 import-req: Check input file exists
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 19:58:40 +01:00
Richard T Bonhomme a9192c1866 remove_secure_session(): Add missing 'fi' statement
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 14:04:30 +01:00
Richard T Bonhomme a9bc2ee576 remove_secure_session(): Return-On-Success Only
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-05-01 13:59:31 +01:00
Richard T Bonhomme 15299444a4 Status reports: Use verbose(), remove easyrsa_debug()
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-04-20 14:22:23 +01:00
Richard T Bonhomme 68fa3342a1 Status reports: Additional check, Use SSL to determine expiration
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-04-15 15:08:56 +01:00
Richard T Bonhomme 8c1971eaaa easyrsa_mktemp(): Rename 'target' -> 'want_tmp_file' - Avoid conflicts
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-04-15 14:35:57 +01:00
Richard T Bonhomme cee79481b3 Merge branch 'prohibit-export-in-vars' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-prohibit-export-in-vars
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-04-13 23:34:04 +01:00
Richard T Bonhomme 7be58ded91 vars: WARN use of 'export' and 'unset' in vars file
Use 'set_var' (Supported) or 'force_set_var' (User discretion)

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-04-13 23:22:13 +01:00