Commit Graph
930 Commits
Author SHA1 Message Date
Richard T Bonhomme ceb9a2093c Refactor show_ca() - Quote all expansions (#494)
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-22 17:07:11 +01:00
Richard T Bonhomme bf19e794d3 Correction to: 59dc15ac51
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-21 01:46:10 +01:00
Richard T Bonhomme 59dc15ac51 vars_setup(): Remove $vars_in_pki, unused.
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-21 01:42:30 +01:00
Richard T Bonhomme 8d82501fd0 Minor improvements to vars_setup() and build_ca()
These changes are only for readabilty and simplicity.
No functional changes.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-20 22:33:21 +01:00
Richard T Bonhomme 9a8e77e043 install_data_to_pki(): Use 'cp --no-clobber' to install a blank vars
In the context of 'vars-setup', install_data_to_pki() will only copy
the example vars file to a live vars file in the event that no other
vars file exists.   This final check will never over-write vars file
which is in the PKI.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-20 22:18:41 +01:00
Richard T Bonhomme df526695d8 Prioritise detecting host OS over setting defaults
This allows EasyRSA to detect and use OpenSSL shipped with
Git-for-Windows.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-20 22:14:11 +01:00
Richard T Bonhomme a0ed1203f2 Priorise trap above vars_setup()
vars_setup() has become more complex, therefore, trap should be set earlier.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-20 22:06:25 +01:00
Richard T Bonhomme 59ff47420c Merge branch 'TinCanTech-build-ca-v2'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-20 20:57:10 +01:00
Richard T Bonhomme e80c229559 Make build-ca() almost completely SSL library version independent
The only option which is not SSL version independent is:
  -nodes (version 1)
  -noenc (version 3)
This is managed via $no_password, which is set by verify_ssl_lib().

* Use SSL 'genpkey' to create All CA private keys.
  'genpkey' options are SSL version independent.

* Use SSL 'req' to create All CA certificate/key pairs.
  'req' options are SSL version independent.

* Replace $opts, $crypto and $crypto_opts with individual variables
  for each purpose.

* '$opts' usage:
  -x509 - Replaced by $x509
  -date - Replaced by $date_stamp ($date would be too common)
  -batch - Replaced by $ssl_batch

* '$crypto' usage:
  -aes256 - Replaced by $cipher

* '$crypto_opts' usage:
  -aes256 - Replaced by $cipher (2nd layer of unnecessary complexity)
  -nodes/-noenc - Replaced by $no_password

* Additional variable $digest for SSL 'req' - Defaults to '-sha256'

Insert $EASYRSA_EXTRA_EXTS into the config file along with x509-types
files 'ca' and COMMON.  Replaces the previous method of passing SSL
option '-addext foo:bar' directly to SSL command.

Create new EasyRSA option '--verbose'.  This prints the command passed
to the SSL library by easyrsa_openssl().

Add a shellcheck directive to install_data_to_pki().

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-20 15:52:20 +01:00
Richard T Bonhomme 0cf547feab Add placeholder for CA $X509_TYPES and $EXTRA_EXTS
Placeholder: %CA_X509_TYPES_EXTRA_EXTS%

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-20 14:37:32 +01:00
Richard T Bonhomme adc2cbed58 Check status of command, not exit-code, in default_server_san()
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-19 15:27:20 +01:00
Richard T Bonhomme 60f3fc2728 Quote $cert_ext_key_usage in renew()
'case' is "immune" to standard word splitting and globbing but
code-style now demands that 'case' does not get treated differently.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-19 15:20:54 +01:00
Richard T Bonhomme 993c378dac Improve shellcheck usage by adding descriptive comments
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-19 15:18:12 +01:00
Richard T Bonhomme 2fe73a5040 Disable shellcheck 2086 when building CA cert/key pair
SC2086 - Double quote to prevent globbing and word splitting.

It is not suitable to quote $opts and $EASYRSA_EXTRA_EXTS
because then they are passed to SSL as a single option
with spaces, which is not the intended use.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-19 13:17:45 +01:00
Richard T Bonhomme 1b8a1122d3 Remove CA specific EASYRSA_CA_EXTRA_EXTS, not required.
* EASYRSA_CA_EXTRA_EXTS: Created to avoid clash with EASYRSA_EXTRA_EXTS

EASYRSA_CA_EXTRA_EXTS was an interim hack to avoid triggering a code
injection buried deep inside easyrsa_openssl(), when building a CA.
Fixed by Commit: 057be57825

Remove EASYRSA_CA_EXTRA_EXTS:
Created by Commit: 6f138abb5b

The result is for all extra extensions to be subject to the same code.
The CA no longer has to dodge the code injection.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-18 23:58:56 +01:00
Richard T Bonhomme 7c2dd54214 Terminate if temporary directory does not exist + typ0 [shellcheck]
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-18 22:07:47 +01:00
Richard T Bonhomme f503a22cc7 Include option '--tmp-dir' to define the temporary directory
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-18 20:50:09 +01:00
Richard T Bonhomme c42364ab32 Create temporary session directory for 'init-pki' as required
'init-pki' is run in two different states:

* Without a pre-existing PKI
* With a pre-existing PKI

This causes 'init-pki' temporary session directory status to be undefined.

If a PKI does exist then a "session" directory will exist.
If a PKI does not exist then a "session" will not be defined and a directory
will not exist.

Additionally, a 'soft' init-pki leaves the current "session" directory
completely intact.

Resolve this by Always deleting the old "session" and creating a new "session".
* Only 'init-pki' is allowed to do this.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-18 01:13:29 +01:00
Richard T Bonhomme a289da60cf Add hosts OS details to fatal error messages
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-17 13:55:07 +01:00
Richard T Bonhomme 01faf60e80 Merge branch 'TinCanTech-secure-session'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-17 13:39:11 +01:00
Richard T Bonhomme 368db7fc5c Replace non-POSIX mktemp with POSIX mkdir and mv
mktemp was used to create temp-files but it is not POSIX and
the version shipped for Windows has known bugs.

Replace mktemp with atomic directory and file creation using mkdir
and mv, both of which are atomic.

The temporary directory "session" directory is created using mkdir
with a 32bit random number for the name.

eg: /tmp/easyrsa-temp/b01dface

The temporary file is created by moving another file into the place
of the temp-file, with a 32bit random number for the name.

eg: /tmp/easyrsa-temp/b01dface/c01dface

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-16 16:57:27 +01:00
Richard T Bonhomme d827747600 Use easyrsa_openssl() wrapper for +verify_curve_ec()
Plus some minor formatting tweaks.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-16 16:46:37 +01:00
Richard T Bonhomme 4fc2696a67 Minor improvement to verify_curve_ec()
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 15:13:53 +01:00
Richard T Bonhomme d7b5c98d69 Fix version information and avoid warnings for version and help
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 15:09:41 +01:00
Richard T Bonhomme f4af868cbc Minor improvement to verify_curve_ed()
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 12:47:18 +01:00
Richard T Bonhomme 7e73368a28 Flip short-circuit to avoid having to capture unnecessary error
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 12:36:02 +01:00
Richard T Bonhomme d29aee3e1b Output only - Standardise message use of notice(), warn() and die
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 12:28:56 +01:00
Richard T Bonhomme 8c606c532c Merge branch 'TinCanTech-build-ca-quote-temp-pass-file-name'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 12:10:12 +01:00
Richard T Bonhomme 41c0248de6 Merge branch 'build-ca-quote-temp-pass-file-name' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-build-ca-quote-temp-pass-file-name
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 11:06:06 +01:00
Richard T Bonhomme b68ffc28d7 ChangeLog: Announce new maintenance
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 03:22:45 +01:00
Richard T Bonhomme 1d6a5f803e Set default EASYRSA_PKI to $EASYRSA/pki and some minor improvements
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 02:37:50 +01:00
Richard T Bonhomme 29a8a48638 build_ca() - Quote temporary password file "$out_key_pass_tmp"
The problem:

* crypto_opts="$crypto_opts -pass file:$out_key_pass_tmp"

This cannot be reliably expanded and passed as an unquoted option.
This is due to the unquoted file name $out_key_pass_tmp.

The solution:

* Do not polute $crypto_opts with password related options.
* Specifiy the correct '-pass/-passin/-passout file:xx' for each command.

This allows "$out_key_pass_tmp" to be corrrectly quoted.

Also, apply the same quoting technique to $crypto_opts.

Minor alterations to OpenSSL command line layout, readability.

Comment out the replaced code, not removed. For comparison.
(Follow-up patch will remove the comments)

Full unit-tests completed throughout development.
Manually tested multiple password protected PKIs.
OpenSSL 1.1.1 and 3.0.2

Not tested:
* OpenSSL options: -pass/-passin-/passout file:"$out_key_pass_tmp"

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-13 01:00:08 +01:00
Richard T Bonhomme c18d7f2bf0 Improve informational output: 'init-pki' completed
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-12 20:50:55 +01:00
Richard T Bonhomme 079aedda73 Merge branch 'TinCanTech-easyrsa_openssl-style'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-12 19:21:50 +01:00
Richard T Bonhomme e1dfacef6b Merge branch 'easyrsa_openssl-style' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-easyrsa_openssl-style
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-12 19:18:18 +01:00
Richard T Bonhomme 3dfd57b760 Optimize 'vars_in_pki' - Allow further checks on PKI/vars
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-12 19:09:48 +01:00
Richard T Bonhomme 6e2d139177 Add helpful Warnings to promote preferred use of PKI/vars
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-12 18:35:47 +01:00
Richard T Bonhomme 17ebec2a3e Merge branch 'TinCanTech-vars-single-quote'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-12 15:40:20 +01:00
Richard T Bonhomme bff4a486e2 Merge branch 'vars-single-quote' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-vars-single-quote
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-12 15:37:41 +01:00
Richard T Bonhomme 7d5185f52c easyrsa_openssl() - Minor syle changes
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-12 14:01:42 +01:00
Richard T Bonhomme de7735115c Only warn if 'vars' is in PKI
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-11 23:32:17 +01:00
Richard T Bonhomme 4c4efbd6ae Change Error to Warning: Make (') in vars-file non-fatal
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-11 23:08:36 +01:00
Richard T Bonhomme e30bfd3773 Unit test: Improve output
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-11 21:58:11 +01:00
Richard T Bonhomme 3160cac48f Merge branch 'TinCanTech-easyrsa_openssl'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-11 21:54:19 +01:00
Richard T Bonhomme 7b4272f34d Merge branch 'easyrsa_openssl' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-easyrsa_openssl 2022-04-11 21:52:28 +01:00
Richard T Bonhomme 6745e0e58a Merge branch 'TinCanTech-win-git-bash'
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-11 21:21:42 +01:00
Richard T Bonhomme f0a3047cec Merge branch 'win-git-bash' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-win-git-bash 2022-04-11 21:19:50 +01:00
Richard T Bonhomme 540c6ff5af Unit test: shellcheck easyrsa-unit-tests.sh
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-11 21:16:25 +01:00
Richard T Bonhomme 3e24a76d7e Allow saving test data and improve log output
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-11 19:38:44 +01:00
Richard T Bonhomme 1aeddd9fcf Unit tests: Enable shellcheck and OpenSSL v3 (*nix only)
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-11 16:13:04 +01:00