Skip to content

Commit 5d56179

Browse files
authored
Merge pull request chrisa#1 from timlegge/dev
Merge Changes to Remove Comments from XML
2 parents 4cb8313 + a0d3754 commit 5d56179

File tree

12 files changed

+83
-24
lines changed

12 files changed

+83
-24
lines changed

Makefile.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ name 'Net-SAML2';
99
all_from 'lib/Net/SAML2.pm';
1010

1111
requires 'XML::XPath';
12+
requires 'XML::Tidy';
1213
requires 'XML::Generator';
1314
requires 'XML::Writer';
1415
requires 'Crypt::OpenSSL::RSA';

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ supporting the Web Browser SSO profile.
66
Major dependencies:
77

88
* XML::XPath
9+
* XML::Tidy
910
* Crypt::OpenSSL::RSA
1011
* Crypt::OpenSSL::X509
1112
* Crypt::OpenSSL::VerifyX509

lib/Net/SAML2/Binding/POST.pm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use warnings;
55

66
use Moose;
77
use MooseX::Types::Moose qw/ Str /;
8+
use Net::SAML2::XML::Util qw/ no_comments /;
89

910
=head1 NAME
1011
@@ -57,25 +58,25 @@ sub handle_response {
5758
my ($self, $response) = @_;
5859

5960
# unpack and check the signature
60-
my $xml = decode_base64($response);
61+
my $xml = no_comments(decode_base64($response));
6162
my $xml_opts = { x509 => 1 };
6263
$xml_opts->{ cert_text } = $self->cert_text if ($self->cert_text);
6364
my $x = Net::SAML2::XML::Sig->new($xml_opts);
6465
my $ret = $x->verify($xml);
6566
die "signature check failed" unless $ret;
66-
67+
6768
if ($self->cacert) {
6869
my $cert = $x->signer_cert
6970
or die "Certificate not provided and not in SAML Response, cannot validate";
70-
71+
7172
my $ca = Crypt::OpenSSL::VerifyX509->new($self->cacert);
7273
if ($ca->verify($cert)) {
7374
return sprintf("%s (verified)", $cert->subject);
7475
} else {
7576
return 0;
7677
}
7778
}
78-
79+
7980
return 1;
8081
}
8182

lib/Net/SAML2/Binding/SOAP.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package Net::SAML2::Binding::SOAP;
22
use Moose;
33
use MooseX::Types::Moose qw/ Str Object /;
44
use MooseX::Types::URI qw/ Uri /;
5+
use Net::SAML2::XML::Util qw/ no_comments /;
56

67
=head1 NAME
78
@@ -124,7 +125,7 @@ sub handle_response {
124125
my $subject = sprintf("%s (verified)", $cert->subject);
125126

126127
# parse the SOAP response and return the payload
127-
my $parser = XML::XPath->new( xml => $response );
128+
my $parser = XML::XPath->new( xml => no_comments($response) );
128129
$parser->set_namespace('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
129130
$parser->set_namespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
130131

@@ -143,7 +144,7 @@ Accepts a string containing the complete SOAP request.
143144
sub handle_request {
144145
my ($self, $request) = @_;
145146

146-
my $parser = XML::XPath->new( xml => $request );
147+
my $parser = XML::XPath->new( xml => no_comments($request) );
147148
$parser->set_namespace('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
148149
$parser->set_namespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
149150

lib/Net/SAML2/IdP.pm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package Net::SAML2::IdP;
22
use Moose;
33
use MooseX::Types::Moose qw/ Str Object HashRef ArrayRef /;
44
use MooseX::Types::URI qw/ Uri /;
5+
use Net::SAML2::XML::Util qw/ no_comments /;
56

67
=head1 NAME
78
@@ -59,7 +60,7 @@ sub new_from_url {
5960

6061
my $res = $ua->request($req);
6162
die "no metadata" unless $res->is_success;
62-
my $xml = $res->content;
63+
my $xml = no_comments($res->content);
6364

6465
return $class->new_from_xml(xml => $xml, cacert => $args{cacert});
6566
}
@@ -74,7 +75,7 @@ document.
7475
sub new_from_xml {
7576
my($class, %args) = @_;
7677

77-
my $xpath = XML::XPath->new(xml => $args{xml});
78+
my $xpath = XML::XPath->new(xml => no_comments($args{xml}));
7879
$xpath->set_namespace('md', 'urn:oasis:names:tc:SAML:2.0:metadata');
7980
$xpath->set_namespace('ds', 'http://www.w3.org/2000/09/xmldsig#');
8081

@@ -126,12 +127,12 @@ sub new_from_xml {
126127
$data->{NameIDFormat}->{unspecified} = 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified';
127128
$data->{DefaultFormat} = 'unspecified' unless exists $data->{DefaultFormat};
128129
}
129-
130+
130131
for my $key (
131132
$xpath->findnodes('//md:EntityDescriptor/md:IDPSSODescriptor/md:KeyDescriptor'))
132133
{
133134
my $use = $key->getAttribute('use') || 'signing';
134-
135+
135136
# We can't select by ds:KeyInfo/ds:X509Data/ds:X509Certificate
136137
# because of https://rt.cpan.org/Public/Bug/Display.html?id=8784
137138
my ($text)
@@ -172,7 +173,7 @@ sub new_from_xml {
172173

173174
sub BUILD {
174175
my($self) = @_;
175-
176+
176177
if ($self->cacert) {
177178
my $ca = Crypt::OpenSSL::VerifyX509->new($self->cacert);
178179

lib/Net/SAML2/Protocol/Assertion.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use MooseX::Types::DateTime qw/ DateTime /;
55
use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
66
use DateTime;
77
use DateTime::Format::XSD;
8+
use Net::SAML2::XML::Util qw/ no_comments /;
89

910
with 'Net::SAML2::Role::ProtocolMessage';
1011

@@ -53,7 +54,8 @@ XML data
5354
sub new_from_xml {
5455
my($class, %args) = @_;
5556

56-
my $xpath = XML::XPath->new(xml => $args{xml});
57+
my $xpath = XML::XPath->new(xml => no_comments($args{xml}));
58+
5759
$xpath->set_namespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
5860
$xpath->set_namespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
5961

@@ -126,10 +128,10 @@ sub valid {
126128

127129
return 0 unless defined $audience;
128130
return 0 unless($audience eq $self->audience);
129-
131+
130132
return 0 unless !defined $in_response_to
131133
or $in_response_to eq $self->in_response_to;
132-
134+
133135
my $now = DateTime::->now;
134136

135137
# not_before is "NotBefore" element - exact match is ok

lib/Net/SAML2/Protocol/AuthnRequest.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ sub as_xml {
7373
my ($self) = @_;
7474
my $saml = 'urn:oasis:names:tc:SAML:2.0:assertion';
7575
my $samlp = 'urn:oasis:names:tc:SAML:2.0:protocol';
76-
my $x = XML::Writer->new(
77-
OUTPUT => 'self',
76+
my $x = XML::Writer->new(
77+
OUTPUT => 'self',
7878
NAMESPACES => 1,
7979
FORCED_NS_DECLS => [$saml, $samlp],
8080
PREFIX_MAP => {
@@ -88,9 +88,9 @@ sub as_xml {
8888
IssueInstant => $self->issue_instant,
8989
Version => '2.0',
9090
};
91-
91+
9292
my $issuer_attrs = {};
93-
93+
9494
my $protocol_bindings = {
9595
'HTTP-POST' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
9696
};
@@ -119,7 +119,7 @@ sub as_xml {
119119
}
120120
}
121121
}
122-
122+
123123
$x->startTag([$samlp, 'AuthnRequest'], %$req_atts);
124124
$x->dataElement([$saml, 'Issuer'], $self->issuer, %$issuer_attrs);
125125
if ($self->nameid) {

lib/Net/SAML2/Protocol/LogoutRequest.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package Net::SAML2::Protocol::LogoutRequest;
22
use Moose;
33
use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
44
use MooseX::Types::URI qw/ Uri /;
5+
use Net::SAML2::XML::Util qw/ no_comments /;
56

67
with 'Net::SAML2::Role::ProtocolMessage';
78

@@ -75,7 +76,7 @@ XML data
7576
sub new_from_xml {
7677
my ($class, %args) = @_;
7778

78-
my $xpath = XML::XPath->new( xml => $args{xml} );
79+
my $xpath = XML::XPath->new( xml => no_comments($args{xml}) );
7980
$xpath->set_namespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
8081
$xpath->set_namespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
8182

lib/Net/SAML2/Protocol/LogoutResponse.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package Net::SAML2::Protocol::LogoutResponse;
22
use Moose;
33
use MooseX::Types::Moose qw/ Str /;
44
use MooseX::Types::URI qw/ Uri /;
5+
use Net::SAML2::XML::Util qw/ no_comments /;
56

67
with 'Net::SAML2::Role::ProtocolMessage';
78

@@ -69,7 +70,7 @@ XML data
6970
sub new_from_xml {
7071
my ($class, %args) = @_;
7172

72-
my $xpath = XML::XPath->new( xml => $args{xml} );
73+
my $xpath = XML::XPath->new( xml => no_comments($args{xml}) );
7374
$xpath->set_namespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
7475
$xpath->set_namespace('samlp', 'urn:oasis:names:tc:SAML:2.0:protocol');
7576

lib/Net/SAML2/SP.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ base for all SP service URLs
3737
3838
=item B<id>
3939
40-
SP's identity URI.
40+
SP's identity URI.
4141
4242
=item B<cert>
4343

0 commit comments

Comments
 (0)