diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2012-10-03 18:59:16 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2012-10-03 18:59:16 +0200 |
commit | 08b9ee11fe5e5a54af866a061c9e8d7782cac3c7 (patch) | |
tree | 5715109aa14dee38c368118abec0495d8d3e91fd /www/sign.pl | |
parent | 72abba77573c3583dc373526f6ce86b895eacc6d (diff) |
Make /etc/aliases optional. Add configurability through setup.pl.
Diffstat (limited to 'www/sign.pl')
-rwxr-xr-x | www/sign.pl | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/www/sign.pl b/www/sign.pl index 85f75b3..d936303 100755 --- a/www/sign.pl +++ b/www/sign.pl @@ -15,12 +15,12 @@ use CGI; use CGI::Fast; use CGI::Session; -use Mail::ExpandAliases; - use MIME::Base64 qw(encode_base64 decode_base64); use Time::HiRes qw(time); +do "common.pl"; + sub decode_base64_url($) { # From: https://github.com/ptarjan/base64url/blob/master/perl.pl @@ -39,14 +39,14 @@ sub encode_base64_url($) { } -sub sign($$$$) { +sub sign($$$$$) { # NB. Treating the jwcrypto code as the spec here. - my ($key, $client_pubkey, $email, $duration) = @_; + my ($key, $client_pubkey, $email, $duration, $domain) = @_; my $issued_at = int(1000*time); my $cert = { - iss => "mulk.eu", + iss => $domain, exp => $issued_at + 1000*$duration, iat => $issued_at, "public-key" => $client_pubkey, @@ -65,31 +65,28 @@ sub sign($$$$) { } -our $MULKONF; -do "config.pl"; - while (my $cgi = new CGI::Fast) { + local $::MULKONF = { }; + do "config.pl"; + my $cookie = $cgi->cookie('mulkid_session') or die "No session cookie"; my $session = new CGI::Session("driver:File", $cookie, {Directory=>"/tmp"}) or die "Invalid session cookie"; print $cgi->header(-content_type => 'application/json; charset=UTF-8'); - my $key = Crypt::OpenSSL::RSA->new_private_key(scalar read_file($MULKONF->{pemfile})); + my $key = Crypt::OpenSSL::RSA->new_private_key(scalar read_file($::MULKONF->{pemfile})); $key->use_pkcs1_padding(); $key->use_sha256_hash(); - my $aliases = Mail::ExpandAliases->new("/etc/aliases"); my $user_pubkey = $cgi->param('pubkey') or die "Nothing to sign"; my $duration = $cgi->param('duration') || 24*3600; my $email = $cgi->param('email') or die "No email address supplied"; my $session_user = $session->param('user'); - my $alias; my $domain; - if ($email =~ /^(.*?)@(.*)/) { $alias = $1; $domain = $2; } - my $email_users = $aliases->expand($alias) or die "User not found"; + if ($email =~ /^(.*?)@(.*)/) { $domain = $2; } die "User is not authorized to use this email address" - unless ($session_user ~~ @$email_users); + unless ($session_user ~~ email_users($::MULKONF, $email)); my $sig = sign $key, decode_json($user_pubkey), $email, $duration, $domain; say encode_json({signature => $sig}); |