Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #68 #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Spreadsheet/ParseXLSX/Decryptor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ sub _agileDecryption {
my $encryptedVerifierHashInput = MIME::Base64::decode($info->att('encryptedVerifierHashInput'));
my $encryptedVerifierHashValue = MIME::Base64::decode($info->att('encryptedVerifierHashValue'));
my $encryptedKeyValue = MIME::Base64::decode($info->att('encryptedKeyValue'));
my $hashSize = 0 + $info->att('hashSize');

my $keyDecryptor = Spreadsheet::ParseXLSX::Decryptor::Agile->new({
cipherAlgorithm => $info->att('cipherAlgorithm'),
Expand All @@ -155,7 +156,7 @@ sub _agileDecryption {
blockSize => 0 + $info->att('blockSize')
});

$keyDecryptor->verifyPassword($encryptedVerifierHashInput, $encryptedVerifierHashValue);
$keyDecryptor->verifyPassword($encryptedVerifierHashInput, $encryptedVerifierHashValue, $hashSize);

my $key = $keyDecryptor->decrypt($encryptedKeyValue, "\x14\x6e\x0b\xe7\xab\xac\xd0\xd6");

Expand Down Expand Up @@ -194,7 +195,7 @@ sub new {

if ($self->{hashAlgorithm} eq 'SHA512') {
$self->{hashProc} = \&Digest::SHA::sha512;
} elsif ($self->{hashAlgorithm} eq 'SHA-1') {
} elsif (($self->{hashAlgorithm} eq 'SHA-1') || ($self->{hashAlgorithm} eq 'SHA1')) {
$self->{hashProc} = \&Digest::SHA::sha1;
} elsif ($self->{hashAlgorithm} eq 'SHA256') {
$self->{hashProc} = \&Digest::SHA::sha256;
Expand Down
4 changes: 3 additions & 1 deletion lib/Spreadsheet/ParseXLSX/Decryptor/Agile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ sub decryptFile {

sub verifyPassword {
my $self = shift;
my ($encryptedVerifier, $encryptedVerifierHash) = @_;
my ($encryptedVerifier, $encryptedVerifierHash, $hashSize) = @_;

my $encryptedVerifierHash0 = $self->{hashProc}->($self->decrypt($encryptedVerifier, "\xfe\xa7\xd2\x76\x3b\x4b\x9e\x79"));
$encryptedVerifierHash = $self->decrypt($encryptedVerifierHash, "\xd7\xaa\x0f\x6d\x30\x61\x34\x4e");
$encryptedVerifierHash0 = substr($encryptedVerifierHash0, 0, $hashSize);
$encryptedVerifierHash = substr($encryptedVerifierHash, 0, $hashSize);

die "Wrong password: $self" unless ($encryptedVerifierHash0 eq $encryptedVerifierHash);
}
Expand Down
Binary file added t/data/encryption-agile-SHA1-foobar.xlsx
Binary file not shown.
18 changes: 18 additions & 0 deletions t/encryption.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ use Spreadsheet::ParseXLSX;
}
}

{
my $filename = 't/data/encryption-agile-SHA1-foobar.xlsx';
my @inputs = (
$filename,
do { open my $fh, '<:raw:bytes', $filename or die; $fh },
do { open my $fh, '<:raw:bytes', $filename or die; local $/; my $d = <$fh>; \$d },
);

my $parser = Spreadsheet::ParseXLSX->new(Password => 'foobar');
for my $input (@inputs) {
my $workbook = $parser->parse($input);

my $worksheet = $workbook->worksheet(0);
my $cell = $worksheet->get_cell(0, 0);
is($cell->value, 'i can read this cell');
}
}

{
my $filename = 't/data/encryption-standard-default-password.xlsx';
my @inputs = (
Expand Down