X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=sidebyside;f=aux%2Fcgi%2Frecovery.cgi;fp=aux%2Fcgi%2Frecovery.cgi;h=186bf2f99c56ced5fb25c3fe03578ccc3357d018;hb=efce7ece23d93ca5274ceb1e2bd3579c480d999a;hp=6d6f3a17dbd21d8dfb597126d29c3890920f9b95;hpb=97cbb6cd2640bc3a0528dadb1730840ccae503c0;p=blerg.git diff --git a/aux/cgi/recovery.cgi b/aux/cgi/recovery.cgi index 6d6f3a1..186bf2f 100755 --- a/aux/cgi/recovery.cgi +++ b/aux/cgi/recovery.cgi @@ -1,6 +1,7 @@ #!/usr/bin/perl use CGI::Fast qw/:cgi/; -use Digest::SHA qw/hmac_sha256_base64/; +use Digest::SHA qw/hmac_sha256/; +use MIME::Base64 qw/encode_base64url/; use Blerg::Database; use strict; use v5.10; @@ -37,31 +38,31 @@ sub generate_reset_url { my $expiry = time + $validity; my $counter = Blerg::Database::auth_get_counter($username) or return undef; - my $data = "$username;$expiry;$counter"; + my $data = "$username:$expiry:$counter"; # HMAC-SHA256 it - my $hmac = hmac_sha256_base64($data, $hmac_key); + my $hmac = encode_base64url(hmac_sha256($data, $hmac_key)); - return Blerg::Database::BASEURL . "#/recovery/$data;$hmac"; + return Blerg::Database::BASEURL . "#/recovery/$data:$hmac"; } sub validate_reset_data { my ($data) = @_; my ($payload, $hmac); - if ($data =~ /^(.*);([^;]+)$/) { + if ($data =~ /^(.*):([^:]+)$/) { $payload = $1; $hmac = $2; } else { return undef; } - my $computed_hmac = hmac_sha256_base64($payload, $hmac_key); + my $computed_hmac = encode_base64url(hmac_sha256($payload, $hmac_key)); if ($hmac ne $computed_hmac) { return undef; } - my ($username, $expiry, $counter) = split(';', $payload); + my ($username, $expiry, $counter) = split(':', $payload); if (time > $expiry || $counter != Blerg::Database::auth_get_counter($username)) { return undef;