line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::ACME::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=encoding utf-8 |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Net::ACME::Utils - utilities for C |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Net::ACME::Utils::verify_token('blah/blah'); #dies |
12
|
|
|
|
|
|
|
Net::ACME::Utils::verify_token('blah-blah'); #succeeds |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $jwk_hr = Net::ACME::Utils::get_jwk_data($rsa_key_pem); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This module is a home for “miscellaneous” functions that just aren’t |
19
|
|
|
|
|
|
|
in other modules. Think carefully before expanding this module; it’s |
20
|
|
|
|
|
|
|
probably better, if possible, to put new functionality into more |
21
|
|
|
|
|
|
|
topic-specific modules rather than this “catch-all” one. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
6
|
|
|
6
|
|
55849
|
use strict; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
150
|
|
26
|
6
|
|
|
6
|
|
18
|
use warnings; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
110
|
|
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
6
|
|
1989
|
use MIME::Base64 (); |
|
6
|
|
|
|
|
2285
|
|
|
6
|
|
|
|
|
170
|
|
29
|
|
|
|
|
|
|
*_to_base64url = \&MIME::Base64::encode_base64url; |
30
|
|
|
|
|
|
|
|
31
|
6
|
|
|
6
|
|
1953
|
use Net::ACME::Crypt (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Net::ACME::X (); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %KEY_OBJ_CACHE; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#Clear out the cache prior to global destruction. |
37
|
|
|
|
|
|
|
END { |
38
|
|
|
|
|
|
|
%KEY_OBJ_CACHE = (); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub verify_token { |
42
|
|
|
|
|
|
|
my ($token) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#cf. eval_bug.readme |
45
|
|
|
|
|
|
|
my $eval_err = $@; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
eval { |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
die Net::ACME::X::create('Empty') if !defined $token || !length $token; |
50
|
|
|
|
|
|
|
die Net::ACME::X::create('Empty') if $token =~ m<\A\s*\z>; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if ( $token =~ m<[^0-9a-zA-Z_-]> ) { |
53
|
|
|
|
|
|
|
die Net::ACME::X::create( 'InvalidCharacters', "“$token” contains invalid Base64-URL characters.", { value => $token } ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ($@) { |
59
|
|
|
|
|
|
|
my $message = $@->to_string(); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
die Net::ACME::X::create( 'InvalidParameter', "“$token” is not a valid ACME token. ($message)" ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$@ = $eval_err; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub thing_isa { |
70
|
|
|
|
|
|
|
my ($thing, $class) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#cf. eval_bug.readme |
73
|
|
|
|
|
|
|
my $eval_err = $@; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $isa = eval { $thing->isa($class) }; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$@ = $eval_err; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return $isa; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub get_jwk_data { |
83
|
|
|
|
|
|
|
my ($key_pem_or_der) = @_; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return Net::ACME::Crypt::get_rsa_public_jwk($key_pem_or_der); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get_jwk_thumbprint { |
89
|
|
|
|
|
|
|
my ($key_jwk) = @_; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
return Net::ACME::Crypt::get_rsa_jwk_thumbprint( $key_jwk ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |