Skip to content

Instantly share code, notes, and snippets.

@oc
Last active December 17, 2015 20:39
Show Gist options
  • Save oc/5669625 to your computer and use it in GitHub Desktop.
Save oc/5669625 to your computer and use it in GitHub Desktop.
require "rubygems"
require "sinatra"
require "base64"
require "zlib"
require "cgi"
get '/' do
content_type :html
form = <<-EOS
<html>
<head><title>Decoder</title></head>
<body>
<form action='/decode' method='get'>
<label>Paste encoded SAML here:</label><br/>
<textarea rows='15' cols='60' name='q'></textarea><br/>
<input type='submit'/>
</form>
</body>
</html>
EOS
end
get '/decode' do
content_type :xml
encoded = params[:q]
encoded = unescape(encoded) if encoded =~ /%/
inflate(decode(encoded))
end
private
def decode(raw)
Base64.decode64(raw)
end
def inflate(raw)
zlib = Zlib::Inflate.new(-Zlib::MAX_WBITS)
zlib.inflate(raw)
end
def unescape(raw)
CGI::unescape(raw)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment