line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HSTS::Preloaded; |
2
|
|
|
|
|
|
|
$HSTS::Preloaded::VERSION = '1.0.1'; |
3
|
|
|
|
|
|
|
# ABSTRACT: inspect Chrome's HSTS preloaded list |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
21246
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
52
|
|
9
|
1
|
|
|
1
|
|
701
|
use utf8; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
608
|
use open qw(:std :utf8); |
|
1
|
|
|
|
|
1325
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
129
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
104
|
|
13
|
1
|
|
|
1
|
|
837
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
37487
|
|
|
1
|
|
|
|
|
38
|
|
14
|
1
|
|
|
1
|
|
632
|
use JSON::PP; |
|
1
|
|
|
|
|
10777
|
|
|
1
|
|
|
|
|
72
|
|
15
|
1
|
|
|
1
|
|
486
|
use MIME::Base64; |
|
1
|
|
|
|
|
513
|
|
|
1
|
|
|
|
|
417
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
0
|
|
|
0
|
1
|
0
|
my ($class, @params) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
0
|
croak "You should use new() without params" if @params; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
0
|
my $self = {}; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
bless $self, $class; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
$self->{_data} = $self->_get_data_with_hsts_preloaded_list(); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# to speed up method host_is_in_hsts_preloaded_list() |
31
|
0
|
|
|
|
|
0
|
$self->{_hosts} = { map { $_->{name} => 1 } @{$self->{_data}->{entries}} }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub host_is_in_hsts_preloaded_list { |
38
|
0
|
|
|
0
|
1
|
0
|
my ($self, $host) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
0
|
croak "Host is not defined" if not defined $host; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
return !!$self->{_hosts}->{$host}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_all_hsts_preloaded_list_data { |
47
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
return $self->{_data}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _get_data_with_hsts_preloaded_list { |
54
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# The only way to download raw content is to download base64-encoded file |
57
|
|
|
|
|
|
|
# https://code.google.com/p/gitiles/issues/detail?id=7 |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
my $url = 'https://chromium.googlesource.com/chromium/src/+/master/net/http/transport_security_state_static.json?format=TEXT'; |
60
|
0
|
|
|
|
|
0
|
my $base64_content = $self->_get_content_from_url( $url ); |
61
|
0
|
|
|
|
|
0
|
my $content = decode_base64 $base64_content; |
62
|
0
|
|
|
|
|
0
|
my $json = $self->_get_data_without_comments( $content ); |
63
|
0
|
|
|
|
|
0
|
my $data = decode_json $json; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
return $data; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _get_data_without_comments { |
69
|
1
|
|
|
1
|
|
313
|
my ($self, $data) = @_; |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
2
|
my $output; |
72
|
1
|
|
|
|
|
6
|
foreach my $line (split /\n/, $data) { |
73
|
10
|
100
|
|
|
|
19
|
if ($line !~ m{^\s*//}) { |
74
|
6
|
|
|
|
|
7
|
$output .= "$line\n"; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
5
|
return $output; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _get_content_from_url { |
82
|
0
|
|
|
0
|
|
|
my ($self, $url) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $response = HTTP::Tiny->new->get($url); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if ($response->{status} eq '200') { |
87
|
0
|
|
|
|
|
|
return $response->{content}; |
88
|
|
|
|
|
|
|
} else { |
89
|
0
|
|
|
|
|
|
croak "Error. Can't get url '$url'. Got http status $response->{status}"; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |