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
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module is a home for “miscellaneous” functions that just aren’t |
17
|
|
|
|
|
|
|
in other modules. Think carefully before expanding this module; it’s |
18
|
|
|
|
|
|
|
probably better, if possible, to put new functionality into more |
19
|
|
|
|
|
|
|
topic-specific modules rather than this “catch-all” one. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
13
|
|
|
13
|
|
53769
|
use strict; |
|
13
|
|
|
|
|
14
|
|
|
13
|
|
|
|
|
271
|
|
24
|
13
|
|
|
13
|
|
39
|
use warnings; |
|
13
|
|
|
|
|
8
|
|
|
13
|
|
|
|
|
228
|
|
25
|
|
|
|
|
|
|
|
26
|
13
|
|
|
13
|
|
1190
|
use MIME::Base64 (); |
|
13
|
|
|
|
|
1402
|
|
|
13
|
|
|
|
|
304
|
|
27
|
|
|
|
|
|
|
*_to_base64url = \&MIME::Base64::encode_base64url; |
28
|
|
|
|
|
|
|
|
29
|
13
|
|
|
13
|
|
963
|
use Net::ACME::Crypt (); |
|
13
|
|
|
|
|
15
|
|
|
13
|
|
|
|
|
140
|
|
30
|
13
|
|
|
13
|
|
40
|
use Net::ACME::X (); |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
2756
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %KEY_OBJ_CACHE; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#Clear out the cache prior to global destruction. |
35
|
|
|
|
|
|
|
END { |
36
|
13
|
|
|
13
|
|
672509
|
%KEY_OBJ_CACHE = (); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub verify_token { |
40
|
9
|
|
|
9
|
0
|
1160
|
my ($token) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#cf. eval_bug.readme |
43
|
9
|
|
|
|
|
12
|
my $eval_err = $@; |
44
|
|
|
|
|
|
|
|
45
|
9
|
|
|
|
|
15
|
eval { |
46
|
|
|
|
|
|
|
|
47
|
9
|
50
|
33
|
|
|
50
|
die Net::ACME::X::create('Empty') if !defined $token || !length $token; |
48
|
9
|
50
|
|
|
|
57
|
die Net::ACME::X::create('Empty') if $token =~ m<\A\s*\z>; |
49
|
|
|
|
|
|
|
|
50
|
9
|
100
|
|
|
|
36
|
if ( $token =~ m<[^0-9a-zA-Z_-]> ) { |
51
|
1
|
|
|
|
|
7
|
die Net::ACME::X::create( 'InvalidCharacters', "“$token” contains invalid Base64-URL characters.", { value => $token } ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
9
|
100
|
|
|
|
56
|
if ($@) { |
57
|
1
|
|
|
|
|
4
|
my $message = $@->to_string(); |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
5
|
die Net::ACME::X::create( 'InvalidParameter', "“$token” is not a valid ACME token. ($message)" ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
8
|
|
|
|
|
13
|
$@ = $eval_err; |
63
|
|
|
|
|
|
|
|
64
|
8
|
|
|
|
|
18
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#Use this to avoid a Try::Tiny dependency. |
68
|
|
|
|
|
|
|
sub thing_isa { |
69
|
8
|
|
|
8
|
0
|
11
|
my ($thing, $class) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#cf. eval_bug.readme |
72
|
8
|
|
|
|
|
12
|
my $eval_err = $@; |
73
|
|
|
|
|
|
|
|
74
|
8
|
|
|
|
|
11
|
my $isa = eval { $thing->isa($class) }; |
|
8
|
|
|
|
|
47
|
|
75
|
|
|
|
|
|
|
|
76
|
8
|
|
|
|
|
13
|
$@ = $eval_err; |
77
|
|
|
|
|
|
|
|
78
|
8
|
|
|
|
|
35
|
return $isa; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |