Skip to content

Commit

Permalink
Item14335: utf8 encode before calculating signatures
Browse files Browse the repository at this point in the history
The HMAC routines can't deal with wide characters

SMELL:  This is Foswiki 2.x ONLY.  It needs to be conditional for
backwards compatibiltiy with Foswiki 1.x.  However several of the other
changes are also 2.x only, so this extension needs work to be backwards
compatibile:
  • Loading branch information
gac410 committed Mar 2, 2017
1 parent 8033e7a commit 66a5529
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/Foswiki/Plugins/SafeWikiPlugin/Signatures.pm
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,17 @@ s/<!--safewiki:([0-9A-Za-z\/\+]{27}):([^;]+);;(.*?)-->/$unhoist->($1,$2,$3)/eg;
%TMP_SIGNATURES = ();
}

#SMELL: Foswiki::encode_utf8 is Foswiki 2.x only!
sub getMAC {
my $text = shift;
my $key = $Foswiki::cfg{Plugins}{SafeWikiPlugin}{SecretKey};
my $mac = Digest::HMAC_SHA1->new($key);
$mac->add($text);
my $mac = Digest::HMAC_SHA1->new( Foswiki::encode_utf8($key) );
$mac->add( Foswiki::encode_utf8($text) );
return $mac->b64digest;
}

# Simple: hash a piece of code
sub getSHA { return sha256_base64(shift); }
sub getSHA { return sha256_base64( Foswiki::encode_utf8(shift) ); }

# Check if we have the signature for a piece of code in our whitelist
sub checkSHA { return _haveSHA( getSHA(shift) ); }
Expand Down

0 comments on commit 66a5529

Please sign in to comment.