line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SAML2::Binding::POST; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
104
|
use strict; |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
441
|
|
4
|
13
|
|
|
13
|
|
77
|
use warnings; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
366
|
|
5
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
70
|
use Moose; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
116
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.41'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Net::SAML2::Binding::POST - HTTP POST binding for SAML |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
13
|
|
|
13
|
|
106056
|
use Net::SAML2::XML::Sig; |
|
13
|
|
|
|
|
106
|
|
|
13
|
|
|
|
|
112
|
|
14
|
13
|
|
|
13
|
|
886
|
use MIME::Base64 qw/ decode_base64 /; |
|
13
|
|
|
|
|
37
|
|
|
13
|
|
|
|
|
793
|
|
15
|
13
|
|
|
13
|
|
6410
|
use Crypt::OpenSSL::Verify; |
|
13
|
|
|
|
|
10217
|
|
|
13
|
|
|
|
|
3607
|
|
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
|
666
|
my ($self, $response) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# unpack and check the signature |
26
|
2
|
|
|
|
|
93
|
my $xml = decode_base64($response); |
27
|
2
|
|
|
|
|
12
|
my $xml_opts = { x509 => 1 }; |
28
|
2
|
50
|
|
|
|
83
|
$xml_opts->{ cert_text } = $self->cert_text if ($self->cert_text); |
29
|
2
|
|
|
|
|
7
|
$xml_opts->{ exclusive } = 1; |
30
|
2
|
|
|
|
|
5
|
$xml_opts->{ no_xml_declaration } = 1; |
31
|
2
|
|
|
|
|
19
|
my $x = Net::SAML2::XML::Sig->new($xml_opts); |
32
|
2
|
|
|
|
|
12
|
my $ret = $x->verify($xml); |
33
|
2
|
50
|
|
|
|
12
|
die "signature check failed" unless $ret; |
34
|
|
|
|
|
|
|
|
35
|
2
|
50
|
|
|
|
89
|
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
|
|
|
|
|
59
|
my $ca = Crypt::OpenSSL::Verify->new($self->cacert, { strict_certs => 0, }); |
40
|
2
|
50
|
|
|
|
246
|
if ($ca->verify($cert)) { |
41
|
2
|
|
|
|
|
938
|
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.41 |
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 |