Bug 33934: Add more detail to 'No encryption_key in koha-conf.xml'

If encryption_key is not set in $KOHA_CONF we are raising an exception.

This key was only needed for a couple of feature, but now we are using Koha::Encryption from the update DB process, and so the upgrade fails with no more info than 'No encryption_key in koha-conf.xml'.

We need to provide more detail in this error.

Additionally we reject "__ENCRYPTION_KEY__", in case people will simple
copy/paste that

Test plan:
Apply the patch
Edit $KOHA_CONf, remove the encryption_key entry (or blank)
restart_all
Go to the about page and enable 2FA
=> warning on the about page, and 500 server-side are displaying more
info about how to generate the missing entry
Edit $KOHA_CONF and set the value to __ENCRYPTION_KEY__
restart_all
=> Same messages
Edit $KOHA_CONF and set a correct value
restart_all
=> No error, everything is working correctly

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-06-07 09:30:15 +02:00 committed by Tomas Cohen Arazi
parent 633cb15a63
commit d7288411f0
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 8 additions and 5 deletions

View file

@ -54,12 +54,14 @@ It's based on Crypt::CBC
sub new { sub new {
my ( $class ) = @_; my ( $class ) = @_;
my $key = C4::Context->config('encryption_key'); my $encryption_key = C4::Context->config('encryption_key');
if( !$key ) { if ( !$encryption_key || $encryption_key eq '__ENCRYPTION_KEY__') {
Koha::Exceptions::MissingParameter->throw('No encryption_key in koha-conf.xml'); Koha::Exceptions::MissingParameter->throw(
q{No encryption_key in koha-conf.xml. Please generate a key. We recommend one of at least 32 bytes. (You might use 'pwgen 32' to do so.)}
);
} }
return $class->SUPER::new( return $class->SUPER::new(
-key => $key, -key => $encryption_key,
-cipher => 'Cipher::AES' -cipher => 'Cipher::AES'
); );
} }

View file

@ -281,7 +281,8 @@ if ( ! C4::Context->config('tmp_path') ) {
} }
} }
if( ! C4::Context->config('encryption_key') ) { my $encryption_key = C4::Context->config('encryption_key');
if ( !$encryption_key || $encryption_key eq '__ENCRYPTION_KEY__') {
push @xml_config_warnings, { error => 'encryption_key_missing' }; push @xml_config_warnings, { error => 'encryption_key_missing' };
} }