line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::SSLLabs; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
202024
|
use strict; |
|
3
|
|
|
|
|
26
|
|
|
3
|
|
|
|
|
86
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
66
|
|
5
|
3
|
|
|
3
|
|
1994
|
use JSON(); |
|
3
|
|
|
|
|
36644
|
|
|
3
|
|
|
|
|
72
|
|
6
|
3
|
|
|
3
|
|
1296
|
use URI::Escape(); |
|
3
|
|
|
|
|
3796
|
|
|
3
|
|
|
|
|
70
|
|
7
|
3
|
|
|
3
|
|
2068
|
use LWP::UserAgent(); |
|
3
|
|
|
|
|
135412
|
|
|
3
|
|
|
|
|
81
|
|
8
|
3
|
|
|
3
|
|
1450
|
use WebService::SSLLabs::Info(); |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
60
|
|
9
|
3
|
|
|
3
|
|
1372
|
use WebService::SSLLabs::Host(); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
62
|
|
10
|
3
|
|
|
3
|
|
22
|
use WebService::SSLLabs::Endpoint(); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
41
|
|
11
|
3
|
|
|
3
|
|
1329
|
use WebService::SSLLabs::StatusCodes(); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
3660
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.33'; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
0
|
|
0
|
sub _MINIMUM_ETA_TIME { return 10; } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
2
|
|
|
2
|
1
|
189
|
my ($class) = @_; |
19
|
2
|
|
|
|
|
7
|
my $self = {}; |
20
|
2
|
|
|
|
|
6
|
bless $self, $class; |
21
|
2
|
|
|
|
|
12
|
$self->{url} = 'https://api.ssllabs.com/api/v2/'; |
22
|
2
|
|
|
|
|
15
|
$self->{ua} = LWP::UserAgent->new(); |
23
|
2
|
|
|
|
|
5935
|
$self->{ua}->env_proxy(); |
24
|
2
|
|
|
|
|
30512
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _parse_success { |
28
|
0
|
|
|
0
|
|
0
|
my ( $self, $response ) = @_; |
29
|
|
|
|
|
|
|
$self->{max_assessments} = |
30
|
0
|
|
|
|
|
0
|
$response->headers()->header('X-Max-Assessments'); |
31
|
|
|
|
|
|
|
$self->{current_assessments} = |
32
|
0
|
|
|
|
|
0
|
$response->headers()->header('X-Current-Assessments'); |
33
|
0
|
|
|
|
|
0
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub max_assessments { |
37
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
38
|
0
|
|
|
|
|
0
|
return $self->{max_assessments}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub current_assessments { |
42
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
43
|
0
|
|
|
|
|
0
|
return $self->{current_assessments}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub info { |
47
|
1
|
|
|
1
|
1
|
10
|
my ($self) = @_; |
48
|
1
|
|
|
|
|
4
|
my $url = $self->{url} . 'info'; |
49
|
1
|
|
|
|
|
6
|
my $response = $self->{ua}->get($url); |
50
|
1
|
50
|
|
|
|
12970
|
if ( $response->is_success() ) { |
51
|
0
|
|
|
|
|
0
|
$self->_parse_success($response); |
52
|
0
|
|
|
|
|
0
|
return WebService::SSLLabs::Info->new( |
53
|
|
|
|
|
|
|
JSON::decode_json( $response->decoded_content() ) ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
1
|
|
|
|
|
16
|
Carp::croak( "Failed to retrieve $url:" . $response->status_line() ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _translate_params { |
61
|
17
|
|
|
17
|
|
51
|
my ( $self, %params ) = @_; |
62
|
17
|
|
|
|
|
24
|
my %translated_params; |
63
|
17
|
|
|
|
|
81
|
foreach my $key ( sort { $a cmp $b } sort keys %params ) { |
|
19
|
|
|
|
|
49
|
|
64
|
34
|
50
|
|
|
|
78
|
if ( defined $params{$key} ) { |
65
|
34
|
|
|
|
|
56
|
my $translated_key = $key; |
66
|
34
|
|
|
|
|
111
|
$translated_key =~ s/_([[:lower:]])/uc $1/egsmx; |
|
11
|
|
|
|
|
47
|
|
67
|
34
|
|
|
|
|
89
|
$translated_params{$translated_key} = $params{$key}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
17
|
|
|
|
|
68
|
return %translated_params; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub analyze { |
74
|
15
|
|
|
15
|
1
|
8879
|
my ( $self, %params ) = @_; |
75
|
15
|
|
|
|
|
55
|
my %translated_params = $self->_translate_params(%params); |
76
|
|
|
|
|
|
|
my $url = $self->{url} . 'analyze?' . ( |
77
|
|
|
|
|
|
|
join q[&], |
78
|
|
|
|
|
|
|
map { |
79
|
15
|
|
|
|
|
83
|
URI::Escape::uri_escape_utf8($_) . q[=] |
80
|
28
|
|
|
|
|
482
|
. URI::Escape::uri_escape_utf8( $translated_params{$_} ) |
81
|
|
|
|
|
|
|
} sort _sort_ssllabs_params keys %translated_params |
82
|
|
|
|
|
|
|
); |
83
|
15
|
|
|
|
|
474
|
my $response = $self->{ua}->get($url); |
84
|
15
|
50
|
|
|
|
2128
|
if ( $response->is_success() ) { |
85
|
0
|
|
|
|
|
0
|
$self->_parse_success($response); |
86
|
0
|
|
|
|
|
0
|
my $host = WebService::SSLLabs::Host->new( |
87
|
|
|
|
|
|
|
JSON::decode_json( $response->decoded_content() ) ); |
88
|
0
|
|
|
|
|
0
|
$self->{_previous_host} = $host; |
89
|
0
|
|
|
|
|
0
|
return $host; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
15
|
|
|
|
|
121
|
Carp::croak( "Failed to retrieve $url:" . $response->status_line() ); |
93
|
|
|
|
|
|
|
} |
94
|
0
|
|
|
|
|
0
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub previous_eta { |
98
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
99
|
0
|
|
|
|
|
0
|
my $eta = _MINIMUM_ETA_TIME(); |
100
|
0
|
0
|
|
|
|
0
|
if ( $self->{_previous_host} ) { |
101
|
0
|
|
|
|
|
0
|
my $host_eta = $self->{_previous_host}->eta(); |
102
|
0
|
0
|
0
|
|
|
0
|
if ( ( defined $host_eta ) |
|
|
|
0
|
|
|
|
|
103
|
|
|
|
|
|
|
&& ( $host_eta =~ /^\d+$/smx ) |
104
|
|
|
|
|
|
|
&& ( $host_eta >= $eta ) ) |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
|
|
0
|
$eta = $host_eta; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
0
|
return $eta; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _sort_ssllabs_params { |
113
|
18
|
100
|
|
18
|
|
58
|
if ( $a eq 'host' ) { |
|
|
100
|
|
|
|
|
|
114
|
10
|
|
|
|
|
25
|
return -1; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif ( $b eq 'host' ) { |
117
|
6
|
|
|
|
|
14
|
return 1; |
118
|
|
|
|
|
|
|
} |
119
|
2
|
100
|
|
|
|
8
|
if ( $a eq 's' ) { |
|
|
50
|
|
|
|
|
|
120
|
1
|
|
|
|
|
3
|
return -1; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
elsif ( $b eq 's' ) { |
123
|
1
|
|
|
|
|
3
|
return 1; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
else { |
126
|
0
|
|
|
|
|
0
|
return $a cmp $b; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub get_endpoint_data { |
131
|
2
|
|
|
2
|
1
|
917
|
my ( $self, %params ) = @_; |
132
|
2
|
|
|
|
|
56
|
my %translated_params = $self->_translate_params(%params); |
133
|
|
|
|
|
|
|
my $url = $self->{url} . 'getEndpointData?' . ( |
134
|
|
|
|
|
|
|
join q[&], |
135
|
|
|
|
|
|
|
map { |
136
|
2
|
|
|
|
|
12
|
URI::Escape::uri_escape_utf8($_) . q[=] |
137
|
6
|
|
|
|
|
123
|
. URI::Escape::uri_escape_utf8( $translated_params{$_} ) |
138
|
|
|
|
|
|
|
} sort _sort_ssllabs_params keys %translated_params |
139
|
|
|
|
|
|
|
); |
140
|
2
|
|
|
|
|
60
|
my $response = $self->{ua}->get($url); |
141
|
2
|
50
|
|
|
|
95
|
if ( $response->is_success() ) { |
142
|
0
|
|
|
|
|
0
|
$self->_parse_success($response); |
143
|
0
|
|
|
|
|
0
|
return WebService::SSLLabs::Endpoint->new( |
144
|
|
|
|
|
|
|
JSON::decode_json( $response->decoded_content() ) ); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else { |
147
|
2
|
|
|
|
|
17
|
Carp::croak( "Failed to retrieve $url:" . $response->status_line() ); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub get_status_codes { |
152
|
1
|
|
|
1
|
1
|
11570
|
my ($self) = @_; |
153
|
1
|
|
|
|
|
5
|
my $url = $self->{url} . 'getStatusCodes'; |
154
|
1
|
|
|
|
|
5
|
my $response = $self->{ua}->get($url); |
155
|
1
|
50
|
|
|
|
1376
|
if ( $response->is_success() ) { |
156
|
0
|
|
|
|
|
0
|
$self->_parse_success($response); |
157
|
0
|
|
|
|
|
0
|
return WebService::SSLLabs::StatusCodes->new( |
158
|
|
|
|
|
|
|
JSON::decode_json( $response->decoded_content() ) ); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
else { |
161
|
1
|
|
|
|
|
12
|
Carp::croak( "Failed to retrieve $url:" . $response->status_line() ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub get_root_certs_raw { |
166
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
167
|
0
|
|
|
|
|
|
my $url = $self->{url} . 'getRootCertsRaw'; |
168
|
0
|
|
|
|
|
|
my $response = $self->{ua}->get($url); |
169
|
0
|
0
|
|
|
|
|
if ( $response->is_success() ) { |
170
|
0
|
|
|
|
|
|
$self->_parse_success($response); |
171
|
0
|
|
|
|
|
|
return $response->decoded_content(); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
else { |
174
|
0
|
|
|
|
|
|
Carp::croak( "Failed to retrieve $url:" . $response->status_line() ); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; # End of WebService::SSLLabs |
179
|
|
|
|
|
|
|
__END__ |