Permalink
Browse files

Rewrap PEM data embedded in an Assertion for OpenSSL's benefit.

  • Loading branch information...
1 parent 072ec8d commit 08cc123287e4f13db0c953f8603d4819ee6b9393 @chrisa committed Jan 12, 2012
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/Net/SAML2/XML/Sig.pm
View
@@ -225,6 +225,19 @@ sub _verify_rsa {
sub _clean_x509 {
my $self = shift;
my ($cert) = @_;
+
+ # rewrap the base64 data from the certificate; it may not be
+ # wrapped at 64 characters as PEM requires
+ $cert =~ s/\n//g;
+
+ my @lines;
+ while (length $cert > 64) {
+ push @lines, substr $cert, 0, 64, '';
+ }
+ push @lines, $cert;
+
+ $cert = join "\n", @lines;
+
$cert = "-----BEGIN CERTIFICATE-----\n" . $cert . "\n-----END CERTIFICATE-----\n";
return $cert;
}
@@ -243,7 +256,7 @@ sub _verify_x509 {
# This is added because the X509 parser requires it for self-identification
$certificate = $self->_clean_x509($certificate);
-
+
my $cert = Crypt::OpenSSL::X509->new_from_string($certificate);
return $self->_verify_x509_cert($cert, $canonical, $sig);
}

0 comments on commit 08cc123

Please sign in to comment.