1011 Commits

Author SHA1 Message Date
Richard T Bonhomme
f05adaf9d7
select_vars: Establish correct hierarchy to assign EASYRSA_VARS_FILE
All candidate vars-files are searched for and EASYRSA_VARS_FILE is set
to the first valid vars-file found. According to Advanced.md

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-24 21:37:35 +01:00
Richard T Bonhomme
632b369cd6
Simplify select_vars(): Use EASYRSA_NO_VARS or EASYRSA_VARS_FILE
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-24 21:11:42 +01:00
Richard T Bonhomme
cc9a19cf28
help, status: Use EASYRSA_VARS_FILE for 'vars-file:' detection
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-24 19:31:00 +01:00
Richard T Bonhomme
1d0ecaf17b
New function: validate_default_vars()
Check that sourcing default pki/vars has NOT changed EASYRSA or EASYRSA_PKI.
This will be resolved in v3.2.0 - See #comment for details.

Refactor select_vars():
To: single if/elif/else/fi.
From: separate if/fi statements.
Always set EASYRSA_VARS_FILE to the used vars-file.
(Required for 'help' status)

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-24 19:20:09 +01:00
Richard T Bonhomme
dd702802c1
Replace vars_setup with select_vars, source_vars and default_vars
vars_setup was trying to do more work than only setting up vars.
These tasks have been broken down as follows:

select_vars:
* Choose only ONE vars file to source by priority specified in Advanced.md
* Apply restrictions to default vars changing EASYRSA or EASYRSA_PKI.

source_vars:
* Verify and source a vars file.

default_vars:
* Set all default values as expected.

Note: Also disable use of vars_setup.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-24 17:02:59 +01:00
Richard T Bonhomme
49ffffc6be
Merge branch 'improve-vars-auto-load' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-improve-vars-auto-load
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-21 23:29:32 +01:00
Richard T Bonhomme
ebbb51def7
vars_setup: Add advice to "Conflicting vars files" error message
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-21 23:25:19 +01:00
Richard T Bonhomme
de3d484c67
Remove EASYRSA and EASYRSA_PKI from built-in vars file generation
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-21 15:22:12 +01:00
Richard T Bonhomme
3b4b5f37c7
Ignore conflicting vars files for commands which do not require vars
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-20 23:37:14 +01:00
Richard T Bonhomme
2720fc103a
Remove useless option --no-safe-ssl
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-20 21:49:09 +01:00
Richard T Bonhomme
057fba01e8
Merge branch 'gen_crl-preserve-permissions' of ssh://github.com/Tabiskabis/easy-rsa into Tabiskabis-gen_crl-preserve-permissions
Amendments:
* Remove trailing space.
* Catch error on update.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-20 21:19:04 +01:00
Richard T Bonhomme
0f1064ef00
Rename option --pki-dir to --pki but continue support for --pki-dir
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-20 10:52:12 +01:00
Richard T Bonhomme
7b38d99b4c
vars: Forbid auto-loaded "$EASYRSA_PKI/vars" from changing the PKI
If a vars file in the PKI tries to change the expected PKI then fail.

Allow vars file in the working directory to change the PKI.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-19 03:21:25 +01:00
Richard T Bonhomme
f47b491346
vars: Remove program directory as a valid "vars auto-load" candidate
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-19 01:59:39 +01:00
Richard T Bonhomme
8d7e017066
vars: Improve auto-load logic
The main changes made are:
* If EASYRSA is set then only allow default vars file. No auto-load
* If EASYRSA_PKI is set then allow also EASYRSA_PKI/vars. Use auto-load.

This is something like "The Three Laws"; vars auto-load is unnecassary
and should be replaced by a single default vars file. However, here is
the latest version:

1. The DEFAULT vars file is in the working directory: ./vars
2. Using --vars=<FILE>, takes priority ALWAYS. NO auto-load!
3. Using --pki-dir=<DIR>, allows "$EASYRSA_PKI/vars". Use auto-load!

Note:
A user set PKI can auto-load a default vars file in the PKI, however,
that can also conflict with a default ./vars file.

4. ERROR, if vars auto-load finds more than one VIABLE vars file.

Viable vars files and conflicts:
1. "$PWD/vars" - Can conflict.
2. "$PWD/pki/vars" - Can conflict.
3. "$EASYRSA/vars" - User defined EASYRSA, no conflict.
4. "$EASYRSA_PKI/vars" - User defined EASYRSA_PKI, can conflict.

This is achieved by making the following changes:

Prioritise user-set EASYRSA to force "$EASYRSA/vars" ONLY.
No auto-load.

Expand assigning EASYRSA_PKI/vars to test for user-set PKI or default PKI.
Use auto-load.

Remove unused code and improve comments.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-19 01:16:12 +01:00
Richard T Bonhomme
e91fc304c4
Ignore shellcheck warning for PATH when used with sourcing vars
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-17 20:52:38 +01:00
Richard T Bonhomme
2243edb3fe
New command: make-vars - Print vars.example (here-doc) to stdout
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-17 20:40:37 +01:00
Richard T Bonhomme
34c4d2489c
Merge branch 'expand-help' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-expand-help
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-17 20:28:38 +01:00
Richard T Bonhomme
84a5b5d9d7
Expand help to include undocumented commands
Usage: 'easyrsa help more'

Allow default-san to find requests in pki/reqs folder.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-17 20:23:16 +01:00
Richard T Bonhomme
fde4454665
show-expire: Calculate certificate expire seconds from Database date
When a certificate CN is not the same as the file-name then show-expire
must calculate the expiry date, in seconds, from the database field.

This is done by functions:
* db_date_to_iso_8601_date()
  Translate from database format to ISO_8601 date format.
* iso_8601_timestamp_to_seconds()
  Translate from ISO_86012 date format to time-stamp in seconds.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-17 17:04:30 +01:00
Richard T Bonhomme
5a24fa7815
vars_setup(): When sourcing 'vars' restrict PATH to './'
If '--vars=vars' is used, without specifying a path to 'vars', then
sourcing 'vars' fails to find './vars'. POSIX '.' searches the PATH
when the file-name does not contain a slash '/'. [man dot(1p)]

Since EasyRSA expects the 'vars' file to be within the current working
directory, setting 'PATH=./' forces '.' to search ONLY './'.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-14 23:16:40 +01:00
Richard T Bonhomme
4095e334cd
vars_setup(): User message severity and verbosity, reduce noise
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-14 20:11:40 +01:00
Richard T Bonhomme
6de343fca3
vars_setup: Prohibit specifying vars as a directory. eg: ./
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-14 12:13:32 +01:00
Richard T Bonhomme
232a28d959
user_error(): Exit with known error directly to cleanup()
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-14 11:51:12 +01:00
Richard T Bonhomme
7684b975ca
init-pki: Remove SECOND confirmation promoting use of option 'soft'
The option 'soft' for 'init-pki' has been found to be flawed, because
keeping the 'vars' file in the PKI is now forbidden. The 'soft' option
will be removed in due course.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-14 11:08:44 +01:00
Richard T Bonhomme
eedb81e0e0
init-pki: Never create a vars.example and vars file in the pki
For 'init-pki, disable creating vars.example, which also disables
creating a vars file in the PKI.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-14 11:04:15 +01:00
Richard T Bonhomme
660895293b
Forbid "default vars in the default PKI" for all commands
The default 'vars' file MUST be "$PWD/vars", no other file can be default.
In order to enforce that, a default 'pki/vars' file MUST be forbidden.

This patch:
* Disables the recommandation for 'vars' to be moved TO the PKI, './pki/vars.
* Forbids the file called './pki/vars'.
* Forbids multiple 'vars' files
* Recommends ONLY the working directory copy of a 'vars' file.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-09-14 00:28:12 +01:00
Tabis Kabis
342b588a3a
gen-crl: preserve existing crl.pem ownership+mode
Signed-off-by: Tabis Kabis <Tabiskabis@users.noreply.github.com>
2023-09-09 12:17:08 +02:00
Richard T Bonhomme
811e8ad593
Merge branch 'revert-1002-expand-help' of ssh://github.com/Openvpn/easy-rsa into revert-1002-expand-help
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-29 12:07:03 +01:00
TinCanTech
b5cc16f910
Revert "Completely Remove Upgrade Functionality" 2023-08-29 11:47:20 +01:00
TinCanTech
d9e0c418c4
Revert "Expand help to include undocumented commands" 2023-08-29 11:46:44 +01:00
Richard T Bonhomme
d15b05d322
Expand help to include undocumented commands
Allow default-san to find requests in pki/reqs folder.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-21 13:00:45 +01:00
Richard T Bonhomme
bb2c90a8f7
Completely Remove Upgrade Functionality
The upgrade function is no longer required.

Easy-RSA version 3.1.6 provides full upgrade path for older PKIs.

For rare PKIs which do not have 'unique_subject = no' set
in the 'index.txt.attr' file, fall back to SSL error.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-20 00:38:49 +01:00
Richard T Bonhomme
489d2238d2
verify_working_env: sanitize_path(), forbid broken values
Forbid any path ending with '/', '\' or ':'

This protects user variables for paths from being set to the root folder.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-16 16:48:52 +01:00
Richard T Bonhomme
2df4ef2016
Merge branch 'force_set_var-v2' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-force_set_var-v2
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-05 17:17:36 +01:00
Richard T Bonhomme
b637e9b695
Move creating 'inline' folder from 'build-ca' to 'init-pki'
This allows a client that has not built a CA to use 'inline'.

The CA and signed client certificate can be sent to the client,
allowing the client to create a complete X509 based inline file,
without creating a redundant CA.

Also, add 'inline' command to the list of commands which do not
require a CA.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-05 15:58:56 +01:00
Richard T Bonhomme
98e9f43be6
renew: Use new ssl_cert_x509v3_eku()
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-05 15:58:25 +01:00
Richard T Bonhomme
77a0534347
New command inline: Inline available data for certificate
Expose 'inline' command to command line.
Inline available data and ignore missing files.

This function prints the available inline data to stdout.
To create inline files the data must be redirected to a file.
Internally, this redirection is taken care of.

Return 'soft' error when any data is missing but always print
available data.

This behaviour allows for incomplete inline files. For example,
when a CA signs a certificate but does not have the private key.
Any combination of missing files is allowed.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-05 15:57:52 +01:00
Richard T Bonhomme
fb3223fd5e
New command x509-eku: Extract X509v3 Extended Key Usage from cert
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-05 15:55:36 +01:00
Richard T Bonhomme
6edffac0e6
set_var and force_set_var: Guard against invalid user input
nix.sh/win.sh/busybox.sh never return error from unset
when an invalid variable name 'a=b' is used with a value
to set, eg. 'c'; This causes EasyRSA to execute:
eval "export a=b=c".

'set_var EASYRSA_PKI=pki' results in $EASYRSA_PKI being
set to 'pki=pki-', without error!

Guard against this possible user error with 'case'.

Minor improvements to other input checks.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-08-04 19:41:29 +01:00
Richard T Bonhomme
669ee43ea1
init-pki: Change notice for x509-types directory to verbose level
Now that easyrsa covers missing x509-types, the 'init-pki' message,
for the status of x509-types, is no longer required.

Improve and correct other messages and comments.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-26 21:51:47 +01:00
Richard T Bonhomme
ada4ccae1b
Remove debugging code
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-26 11:15:05 +01:00
Richard T Bonhomme
a8083fdbf3
Export PKCS: export-p1, use -traditional not -legacy
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-26 11:09:38 +01:00
Richard T Bonhomme
ef793f1629
Export PKCS: Improve user messages, re-arrange p12 command
Re-arranging the p12 command to follow the standard:
- In file
- out file

Followed by
- Conditional: -nokeys
- Unconditional: -inkey file

This is a reminder that '-inkey' is subordinate to '-nokeys' but
is ALWAYS required.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-25 20:06:34 +01:00
Richard T Bonhomme
e60b5e2f5f
Export PKCS: Rename variable $short_name to $file_name_base
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-25 17:10:46 +01:00
Richard T Bonhomme
aaa44558b2
Export PKCS: Expand usage for incomplete PKI
The current export functions only allow use on a complete PKI, with CA.

This change allows the following:
* Server - Export P12/P7 without client key
* Client - Export P12/P7 without CA, P8/P1 without PKI

Due to the relative obscurity of the command options 'noca' and 'nokey',
exporting P12/P7 with incorrect options can be adjusted on-the-fly with
confirmation from the user.

Correct behaviour of export-p1 with OpenSSL v3 by using -legacy option.
Otherwise, OpenSSL v3 outputs a PKCS#8 format file.

Minor improvements to comments.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-25 15:11:26 +01:00
Richard T Bonhomme
cc089ab008
Insert newline separator before confirmations
Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-20 23:58:06 +01:00
Richard T Bonhomme
350c0c6cb8
Remove user warnings for missing X509 types
Minor alignment and wrap long lines

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2023-07-20 20:25:52 +01:00
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