Skip to content

Instantly share code, notes, and snippets.

@aduitsis
Created March 6, 2013 17:19
Show Gist options
  • Save aduitsis/5101097 to your computer and use it in GitHub Desktop.
Save aduitsis/5101097 to your computer and use it in GitHub Desktop.

Revisions

  1. aduitsis created this gist Mar 6, 2013.
    49 changes: 49 additions & 0 deletions gistfile1.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/usr/bin/perl -w

    use strict;
    use warnings;
    use Carp;
    use MIME::Base64;
    use Compress::Zlib;
    use URI;
    use URI::QueryParam;
    use XML::Canonical;


    print STDERR "Please paste a SAMLRequest URL, then press enter, then press Ctrl-D\n";
    my $slurp = do { local $/; <STDIN> };

    my $u = URI->new($slurp, 'http');

    for my $key ($u->query_param) {
    print "$key: ", join(", ", $u->query_param($key)), "\n";
    }

    #SAMLRequest:
    #RelayState:
    #SigAlg: http://www.w3.org/2000/09/xmldsig#rsa-sha1
    #Signature:
    #

    ###print decode_base64($slurp);

    if( defined $u->query_param('SAMLRequest') ) {
    my ( $i, $status ) = inflateInit( -windowBits => -&MAX_WBITS );
    if ( $status == Z_OK && $i ) {
    my $buffer;
    $$buffer = decode_base64($u->query_param('SAMLRequest'));
    #print $$buffer;
    #exit;
    my ( $uncompressed, $status ) = $i->inflate( $buffer );
    if ( ($status != Z_OK) && ($status != Z_STREAM_END) ) {
    croak $i->gzerror() ;
    }
    my $canon = XML::Canonical->new(comments => 1);
    print "\n\n";
    print $canon->canonicalize_string($uncompressed);
    print "\n\n";
    }
    else {
    print STDERR 'SAMLRequest is missing from this URL';
    }
    }