line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Argon::Encryption; |
2
|
|
|
|
|
|
|
# ABSTRACT: Role providing methods and attributes to encrypt Argon::Message traffic |
3
|
|
|
|
|
|
|
$Argon::Encryption::VERSION = '0.18'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
679340
|
use strict; |
|
4
|
|
|
|
|
22
|
|
|
4
|
|
|
|
|
145
|
|
6
|
4
|
|
|
4
|
|
27
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
151
|
|
7
|
4
|
|
|
4
|
|
26
|
use Carp; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
311
|
|
8
|
4
|
|
|
4
|
|
1423
|
use Moose::Role; |
|
4
|
|
|
|
|
26192
|
|
|
4
|
|
|
|
|
27
|
|
9
|
4
|
|
|
4
|
|
29819
|
use Moose::Util::TypeConstraints; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
32
|
|
10
|
4
|
|
|
4
|
|
14229
|
use Crypt::CBC; |
|
4
|
|
|
|
|
20984
|
|
|
4
|
|
|
|
|
241
|
|
11
|
4
|
|
|
4
|
|
808
|
use Path::Tiny qw(path); |
|
4
|
|
|
|
|
14450
|
|
|
4
|
|
|
|
|
342
|
|
12
|
4
|
|
|
4
|
|
536
|
use Argon::Types; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
1186
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %CIPHER; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has keyfile => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => 'Ar::FilePath', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has key => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
isa => 'Str', |
26
|
|
|
|
|
|
|
lazy => 1, |
27
|
|
|
|
|
|
|
builder => '_build_key', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _build_key { |
31
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
32
|
0
|
0
|
|
|
|
0
|
croak 'keyfile required if key is not specified' |
33
|
|
|
|
|
|
|
unless $self->keyfile; |
34
|
0
|
|
|
|
|
0
|
path($self->keyfile)->slurp_raw; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has cipher => ( |
38
|
|
|
|
|
|
|
is => 'ro', |
39
|
|
|
|
|
|
|
isa => 'Crypt::CBC', |
40
|
|
|
|
|
|
|
lazy => 1, |
41
|
|
|
|
|
|
|
builder => '_build_cipher', |
42
|
|
|
|
|
|
|
handles => { |
43
|
|
|
|
|
|
|
encrypt => 'encrypt_hex', |
44
|
|
|
|
|
|
|
decrypt => 'decrypt_hex', |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _build_cipher { |
49
|
11
|
|
|
11
|
|
26
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
11
|
|
66
|
|
|
378
|
$CIPHER{$self->key} ||= Crypt::CBC->new( |
52
|
|
|
|
|
|
|
-key => $self->key, |
53
|
|
|
|
|
|
|
-cipher => 'Rijndael', |
54
|
|
|
|
|
|
|
-salt => 1, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
11
|
|
|
|
|
4065
|
$CIPHER{$self->key}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has token => ( |
62
|
|
|
|
|
|
|
is => 'ro', |
63
|
|
|
|
|
|
|
isa => 'Str', |
64
|
|
|
|
|
|
|
lazy => 1, |
65
|
|
|
|
|
|
|
builder => 'create_token', |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub create_token { |
69
|
8
|
|
|
8
|
0
|
20
|
my $self = shift; |
70
|
8
|
|
|
|
|
230
|
unpack 'H*', $self->cipher->random_bytes(8); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=pod |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=encoding UTF-8 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Argon::Encryption - Role providing methods and attributes to encrypt Argon::Message traffic |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 VERSION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
version 0.18 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Role that provides for encrypting messages in the Argon system. Notably |
92
|
|
|
|
|
|
|
provides the C<keyfile>, C<key>, and C<token> attributes. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 keyfile |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The path to a file containing the encryption pass phrase. Either L</key> or |
99
|
|
|
|
|
|
|
C<keyfile> must be provided when instantiating a class implementing |
100
|
|
|
|
|
|
|
C<Argon::Encryption>. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 key |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The encryption pass phrase. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 token |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
A string of random bytes used as a channel or service identifier. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Jeff Ober <sysread@fastmail.fm> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Jeff Ober. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
119
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |