line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HSTS::Preloaded; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$HSTS::Preloaded::VERSION = '1.0.0'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Inspect Chrome's HSTS preloaded list |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
13854
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
11
|
1
|
|
|
1
|
|
3
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
12
|
1
|
|
|
1
|
|
486
|
use utf8; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
3
|
|
13
|
1
|
|
|
1
|
|
462
|
use open qw(:std :utf8); |
|
1
|
|
|
|
|
878
|
|
|
1
|
|
|
|
|
3
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
89
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
60
|
|
16
|
1
|
|
|
1
|
|
3083
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
37701
|
|
|
1
|
|
|
|
|
38
|
|
17
|
1
|
|
|
1
|
|
731
|
use JSON::PP; |
|
1
|
|
|
|
|
12448
|
|
|
1
|
|
|
|
|
406
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
0
|
|
|
0
|
1
|
0
|
my ($class, @params) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
0
|
croak "You should use new() without params" if @params; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
my $self = {}; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
bless $self, $class; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
0
|
$self->{_data} = $self->_get_data_with_hsts_preloaded_list(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# to speed up method host_is_in_hsts_preloaded_list() |
33
|
0
|
|
|
|
|
0
|
$self->{_hosts} = { map { $_->{name} => 1 } @{$self->{_data}->{entries}} }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub host_is_in_hsts_preloaded_list { |
40
|
0
|
|
|
0
|
1
|
0
|
my ($self, $host) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
0
|
croak "Host is not defined" if not defined $host; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
return !!$self->{_hosts}->{$host}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_all_hsts_preloaded_list_data { |
49
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
return $self->{_data}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _get_data_with_hsts_preloaded_list { |
56
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
my $url = 'https://git.chromium.org/gitweb/?p=chromium/src/net.git;a=blob_plain;f=http/transport_security_state_static.json;hb=HEAD'; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
my $content = $self->_get_content_from_url( $url ); |
61
|
0
|
|
|
|
|
0
|
my $json = $self->_get_data_without_comments( $content ); |
62
|
0
|
|
|
|
|
0
|
my $data = decode_json $json; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
return $data; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _get_data_without_comments { |
68
|
1
|
|
|
1
|
|
272
|
my ($self, $data) = @_; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
1
|
my $output; |
71
|
1
|
|
|
|
|
6
|
foreach my $line (split /\n/, $data) { |
72
|
10
|
100
|
|
|
|
20
|
if ($line !~ m{^\s*//}) { |
73
|
6
|
|
|
|
|
6
|
$output .= "$line\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
5
|
return $output; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _get_content_from_url { |
81
|
0
|
|
|
0
|
|
|
my ($self, $url) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $response = HTTP::Tiny->new->get($url); |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if ($response->{status} eq '200') { |
86
|
0
|
|
|
|
|
|
return $response->{content}; |
87
|
|
|
|
|
|
|
} else { |
88
|
0
|
|
|
|
|
|
croak "Error. Can't get url '$url'. Got http status $response->{status}"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |