line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SAML2::Binding::POST; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
117
|
use strict; |
|
13
|
|
|
|
|
31
|
|
|
13
|
|
|
|
|
441
|
|
4
|
13
|
|
|
13
|
|
73
|
use warnings; |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
375
|
|
5
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
76
|
use Moose; |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
112
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.43'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Net::SAML2::Binding::POST - HTTP POST binding for SAML |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
13
|
|
|
13
|
|
105348
|
use Net::SAML2::XML::Sig; |
|
13
|
|
|
|
|
49
|
|
|
13
|
|
|
|
|
119
|
|
14
|
13
|
|
|
13
|
|
885
|
use MIME::Base64 qw/ decode_base64 /; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
764
|
|
15
|
13
|
|
|
13
|
|
6337
|
use Crypt::OpenSSL::Verify; |
|
13
|
|
|
|
|
10616
|
|
|
13
|
|
|
|
|
3311
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'cert_text' => (isa => 'Str', is => 'ro'); |
19
|
|
|
|
|
|
|
has 'cacert' => (isa => 'Maybe[Str]', is => 'ro'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub handle_response { |
23
|
2
|
|
|
2
|
1
|
971
|
my ($self, $response) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# unpack and check the signature |
26
|
2
|
|
|
|
|
70
|
my $xml = decode_base64($response); |
27
|
2
|
|
|
|
|
10
|
my $xml_opts = { x509 => 1 }; |
28
|
2
|
50
|
|
|
|
86
|
$xml_opts->{ cert_text } = $self->cert_text if ($self->cert_text); |
29
|
2
|
|
|
|
|
10
|
$xml_opts->{ exclusive } = 1; |
30
|
2
|
|
|
|
|
5
|
$xml_opts->{ no_xml_declaration } = 1; |
31
|
2
|
|
|
|
|
18
|
my $x = Net::SAML2::XML::Sig->new($xml_opts); |
32
|
2
|
|
|
|
|
15
|
my $ret = $x->verify($xml); |
33
|
2
|
50
|
|
|
|
28
|
die "signature check failed" unless $ret; |
34
|
|
|
|
|
|
|
|
35
|
2
|
50
|
|
|
|
85
|
if ($self->cacert) { |
36
|
2
|
50
|
|
|
|
10
|
my $cert = $x->signer_cert |
37
|
|
|
|
|
|
|
or die "Certificate not provided and not in SAML Response, cannot validate"; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
62
|
my $ca = Crypt::OpenSSL::Verify->new($self->cacert, { strict_certs => 0, }); |
40
|
2
|
50
|
|
|
|
339
|
if ($ca->verify($cert)) { |
41
|
2
|
|
|
|
|
962
|
return sprintf("%s (verified)", $cert->subject); |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
|
return 0; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=pod |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=encoding UTF-8 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Net::SAML2::Binding::POST - Net::SAML2::Binding::POST - HTTP POST binding for SAML |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 VERSION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
version 0.43 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SYNOPSIS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $post = Net::SAML2::Binding::POST->new( |
69
|
|
|
|
|
|
|
cacert => '/path/to/ca-cert.pem' |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
my $ret = $post->handle_response( |
72
|
|
|
|
|
|
|
$saml_response |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Net::SAML2::Binding::POST - HTTP POST binding for SAML2 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 METHODS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 new( ) |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Constructor. Returns an instance of the POST binding. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Arguments: |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item B<cacert> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
path to the CA certificate for verification |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 handle_response( $response ) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Decodes and verifies the response provided, which should be the raw |
98
|
|
|
|
|
|
|
Base64-encoded response, from the SAMLResponse CGI parameter. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Chris Andrews <chrisa@cpan.org> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Chris Andrews and Others, see the git log. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
109
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |