View | Details | Raw Unified | Return to bug 28998
Collapse All | Expand All

(-)a/Koha/Encryption.pm (+5 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use base qw( Crypt::CBC );
22
use base qw( Crypt::CBC );
23
23
24
use Koha::Exceptions;
25
24
=head1 NAME
26
=head1 NAME
25
27
26
Koha::Encryption - Koha class to encrypt or decrypt strings
28
Koha::Encryption - Koha class to encrypt or decrypt strings
Lines 52-57 It's based on Crypt::CBC Link Here
52
sub new {
54
sub new {
53
    my ( $class ) = @_;
55
    my ( $class ) = @_;
54
    my $key = C4::Context->config('encryption_key');
56
    my $key = C4::Context->config('encryption_key');
57
    if( !$key ) {
58
        Koha::Exceptions::MissingParameter->throw('No encryption_key in koha-conf.xml');
59
    }
55
    return $class->SUPER::new(
60
    return $class->SUPER::new(
56
        -key    => $key,
61
        -key    => $key,
57
        -cipher => 'Cipher::AES'
62
        -cipher => 'Cipher::AES'
(-)a/members/two_factor_auth.pl (+3 lines)
Lines 42-47 unless ( C4::Context->preference('TwoFactorAuthentication') ) { Link Here
42
    exit;
42
    exit;
43
}
43
}
44
44
45
output_and_exit( $cgi, $cookie, $template, 'Entry encryption_key is missing in koha-conf.xml' )
46
    if !C4::Context->config('encryption_key');
47
45
my $logged_in_user = Koha::Patrons->find($loggedinuser);
48
my $logged_in_user = Koha::Patrons->find($loggedinuser);
46
49
47
my $op = $cgi->param('op') // '';
50
my $op = $cgi->param('op') // '';
(-)a/t/db_dependent/Koha/Encryption.t (-3 / +7 lines)
Lines 1-8 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 1;
3
use Test::More tests => 2;
4
use Koha::Encryption;
4
use Test::Exception;
5
use t::lib::Mocks;
5
use t::lib::Mocks;
6
use Koha::Encryption;
6
7
7
t::lib::Mocks::mock_config('encryption_key', 'my secret passphrase');
8
t::lib::Mocks::mock_config('encryption_key', 'my secret passphrase');
8
9
Lines 11-13 my $string = 'a string to encrypt'; Link Here
11
my $crypt = Koha::Encryption->new;
12
my $crypt = Koha::Encryption->new;
12
my $encrypted_string = $crypt->encrypt_hex($string);
13
my $encrypted_string = $crypt->encrypt_hex($string);
13
is( $crypt->decrypt_hex($encrypted_string), $string, 'Decrypted to original text' );
14
is( $crypt->decrypt_hex($encrypted_string), $string, 'Decrypted to original text' );
14
- 
15
16
# Check if exception raised when key is empty or missing
17
t::lib::Mocks::mock_config('encryption_key', '');
18
throws_ok { $crypt = Koha::Encryption->new } 'Koha::Exceptions::MissingParameter', 'Exception raised';

Return to bug 28998