line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::INI::Reader::Encrypted; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22709
|
use 5.006; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
52
|
|
4
|
1
|
|
|
1
|
|
11
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
57
|
|
6
|
1
|
|
|
1
|
|
632
|
use parent qw/ Config::INI::Reader /; |
|
1
|
|
|
|
|
345
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
use Carp; |
8
|
|
|
|
|
|
|
use File::Slurp qw//; |
9
|
|
|
|
|
|
|
use Crypt::CBC; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Config::INI::Reader::Encrypted - Read AES encrypted INI files |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.01 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $filename = 'myconfig.ini.aes'; |
27
|
|
|
|
|
|
|
my $key = 'It$As3cReT'; |
28
|
|
|
|
|
|
|
my $config = |
29
|
|
|
|
|
|
|
eval { Config::INI::Reader::Encrypted->read_file( $filename, $key ); }; |
30
|
|
|
|
|
|
|
if ($@) { |
31
|
|
|
|
|
|
|
croak "Unable to decrypt the file"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This module is a subclass of Config::INI::Reader that can read encrypted INI |
37
|
|
|
|
|
|
|
files. The idea is that a user can place sentitive settings, such as usernames |
38
|
|
|
|
|
|
|
and passwords, in the INI file and encrypt it. This module can then be used to |
39
|
|
|
|
|
|
|
read and unencrypt the file when needed. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 read_file |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Given a filename and decryption key, this method returns a hashref of the |
46
|
|
|
|
|
|
|
contents of that file. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub read_file { |
51
|
|
|
|
|
|
|
my ($self, $filename, $key) = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if ( !defined $key ) { |
54
|
|
|
|
|
|
|
croak "A key was not provided"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $ciphertext = File::Slurp::read_file($filename); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Decrypt file |
60
|
|
|
|
|
|
|
my $cipher = Crypt::CBC->new( |
61
|
|
|
|
|
|
|
-key => $key, |
62
|
|
|
|
|
|
|
-cipher => 'Rijndael', |
63
|
|
|
|
|
|
|
) or croak "Couldn't create CBC object"; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $plaintext = $cipher->decrypt($ciphertext); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Parse unencrypted config file |
68
|
|
|
|
|
|
|
my $cfg = $self->read_string($plaintext); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return $cfg; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 AUTHOR |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Matt Perry, C<< >> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 BUGS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
81
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
82
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SUPPORT |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
perldoc Config::INI::Reader::Encrypted |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
You can also look for information at: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=over 4 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
L |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * CPAN Ratings |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * Search CPAN |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Copyright 2014 Matt Perry |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or |
125
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; # End of Config::INI::Reader::Encrypted |