mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-01 15:54:53 +00:00
Add sample perl code to decrypt authentication tokens
Code from Claes Jakobsson
This commit is contained in:
30
tools/communityauth/sample/perl/generic_perl.pl
Normal file
30
tools/communityauth/sample/perl/generic_perl.pl
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# This is just a generic function that handles the decryption and parsing steps as
|
||||
# an example, it's not a complete authentication plugin (since that will be framework
|
||||
# dependent)
|
||||
#
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use 5.10.0;
|
||||
|
||||
use Crypt::CBC;
|
||||
use MIME::Base64 qw(decode_base64url);
|
||||
use URI::Escape qw(uri_unescape);
|
||||
use Data::Dumper qw(Dumper);
|
||||
|
||||
sub encrypted_b64_to_hash {
|
||||
my ($iv, $key, $data) = map { decode_base64url($_) } @_;
|
||||
|
||||
my $cipher = Crypt::CBC->new(
|
||||
-literal_key => 1,
|
||||
-key => $key,
|
||||
-iv => $iv,
|
||||
-cipher => 'Crypt::OpenSSL::AES',
|
||||
-header => 'none',
|
||||
);
|
||||
|
||||
return map { /^(.*?)=(.*)/ ? ( $1 => uri_unescape($2) ) : () } split /&/, $cipher->decrypt($data);
|
||||
}
|
Reference in New Issue
Block a user