line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::ACME::Key; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
213287
|
use Mojo::Base -base; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
14
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
886
|
use Mojo::File; |
|
2
|
|
|
|
|
26734
|
|
|
2
|
|
|
|
|
105
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
979
|
use Crypt::OpenSSL::RSA; |
|
2
|
|
|
|
|
9084
|
|
|
2
|
|
|
|
|
70
|
|
8
|
2
|
|
|
2
|
|
20
|
use Crypt::OpenSSL::Bignum; # get_key_parameters |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
52
|
|
9
|
2
|
|
|
2
|
|
9
|
use Digest::SHA 'sha256'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
120
|
|
10
|
2
|
|
|
2
|
|
16
|
use MIME::Base64 'encode_base64url'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1234
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'generated'; |
13
|
|
|
|
|
|
|
has string => sub { shift->key->get_private_key_string }; |
14
|
|
|
|
|
|
|
has key => sub { |
15
|
|
|
|
|
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
my $path = $self->path; |
17
|
|
|
|
|
|
|
my $rsa; |
18
|
|
|
|
|
|
|
if ($path && -e $path) { |
19
|
|
|
|
|
|
|
my $string = Mojo::File->new($path)->slurp; |
20
|
|
|
|
|
|
|
$rsa = Crypt::OpenSSL::RSA->new_private_key($string); |
21
|
|
|
|
|
|
|
$self->generated(0); |
22
|
|
|
|
|
|
|
} else { |
23
|
|
|
|
|
|
|
$rsa = Crypt::OpenSSL::RSA->generate_key(4096); |
24
|
|
|
|
|
|
|
$self->generated(1); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
return $rsa; |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
has 'path'; |
29
|
|
|
|
|
|
|
has pub => sub { Crypt::OpenSSL::RSA->new_public_key(shift->key->get_public_key_string) }; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has jwk => sub { |
32
|
|
|
|
|
|
|
my ($n, $e) = shift->pub->get_key_parameters; |
33
|
|
|
|
|
|
|
return { |
34
|
|
|
|
|
|
|
kty => 'RSA', |
35
|
|
|
|
|
|
|
e => encode_base64url($e->to_bin), |
36
|
|
|
|
|
|
|
n => encode_base64url($n->to_bin), |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has thumbprint => sub { |
41
|
|
|
|
|
|
|
my $jwk = shift->jwk; |
42
|
|
|
|
|
|
|
# manually format json for sorted keys |
43
|
|
|
|
|
|
|
my $fmt = '{"e":"%s","kty":"%s","n":"%s"}'; |
44
|
|
|
|
|
|
|
my $json = sprintf $fmt, @{$jwk}{qw/e kty n/}; |
45
|
|
|
|
|
|
|
return encode_base64url( sha256($json) ); |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# TODO remove this once https://rt.cpan.org/Ticket/Display.html?id=111829&results=dcfe848f59fceab0efed819d62b70447 |
49
|
|
|
|
|
|
|
# is resolved and dependency on PKCS10 is bumped |
50
|
2
|
|
|
2
|
0
|
15
|
sub key_clone { Crypt::OpenSSL::RSA->new_private_key(shift->string) } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub sign { |
53
|
2
|
|
|
2
|
0
|
666
|
my ($self, $content) = @_; |
54
|
2
|
|
|
|
|
14
|
my $key = $self->key; |
55
|
2
|
|
|
|
|
21
|
$key->use_sha256_hash; |
56
|
2
|
|
|
|
|
31548
|
return $key->sign($content); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|