line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::ACME::Key; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
146397
|
use Mojo::Base -base; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
11
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
503
|
use Mojo::File; |
|
2
|
|
|
|
|
17194
|
|
|
2
|
|
|
|
|
74
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
558
|
use Crypt::OpenSSL::RSA; |
|
2
|
|
|
|
|
5920
|
|
|
2
|
|
|
|
|
54
|
|
8
|
2
|
|
|
2
|
|
12
|
use Crypt::OpenSSL::Bignum; # get_key_parameters |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
39
|
|
9
|
2
|
|
|
2
|
|
7
|
use Digest::SHA 'sha256'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
82
|
|
10
|
2
|
|
|
2
|
|
9
|
use MIME::Base64 'encode_base64url'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
755
|
|
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
|
518
|
my ($self, $content) = @_; |
54
|
2
|
|
|
|
|
12
|
my $key = $self->key; |
55
|
2
|
|
|
|
|
16
|
$key->use_sha256_hash; |
56
|
2
|
|
|
|
|
25905
|
return $key->sign($content); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|