aboutsummaryrefslogtreecommitdiff
path: root/www/common.pl
diff options
context:
space:
mode:
authorMatthias Benkard <matthias.benkard@egym.de>2014-08-14 09:38:28 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2015-04-23 21:55:01 +0200
commit9e680b80e0c22ce76b6314741e05f1bcb0deb4f9 (patch)
tree260cb3a89bbf68ce29090c0b93d8d6f4175427e4 /www/common.pl
parent985a0147726a490c3e586a46ea916893db389bb8 (diff)
Make stateless.
MulkyID does not use session state stored in /tmp anymore. Instead, it uses a cookie encrypted with the private part of the MulkyID instance's RSA key.
Diffstat (limited to 'www/common.pl')
-rw-r--r--www/common.pl17
1 files changed, 17 insertions, 0 deletions
diff --git a/www/common.pl b/www/common.pl
index 736bf00..a094442 100644
--- a/www/common.pl
+++ b/www/common.pl
@@ -7,6 +7,7 @@ use Modern::Perl;
use Mail::ExpandAliases;
use URI;
+use MIME::Base64 qw(encode_base64 decode_base64);
sub load_config() {
$::MULKONF = { };
@@ -41,3 +42,19 @@ sub reluri($$) {
$uri->path_segments(@path);
return "$uri";
}
+
+sub decode_base64_url($) {
+ # From: https://github.com/ptarjan/base64url/blob/master/perl.pl
+ (my $s = shift) =~ tr{-_}{+/};
+ $s .= '=' x (4 - length($s));
+ return decode_base64($s);
+}
+
+sub encode_base64_url($) {
+ my ($s) = shift;
+ $s = encode_base64($s);
+ $s =~ tr{+/}{-_};
+ $s =~ s/=*$//;
+ $s =~ s/\n//g;
+ return $s;
+}