File-KDBX
view release on metacpan or search on metacpan
lib/File/KDBX/Key.pm view on Meta::CPAN
=head1 NAME
File::KDBX::Key - A credential that can protect a KDBX file
=head1 VERSION
version 0.906
=head1 DESCRIPTION
A master key is one or more credentials that can protect a KDBX database. When you encrypt a database with
a master key, you will need the master key to decrypt it. B<Keep your master key safe!> If someone gains
access to your master key, they can open your database. If you forget or lose any part of your master key, all
data in the database is lost.
There are several different types of keys, each implemented as a subclass:
=over 4
=item *
lib/File/KDBX/Loader/V3.pm view on Meta::CPAN
my $final_key = digest_data('SHA256', $master_seed, $response, $transformed_key);
push @cleanup, erase_scoped $final_key;
my $cipher = $kdbx->cipher(key => $final_key);
$fh = File::KDBX::IO::Crypt->new($fh, cipher => $cipher);
read_all $fh, my $start_bytes, 32 or throw 'Failed to read starting bytes';
my $expected_start_bytes = $kdbx->headers->{stream_start_bytes};
$start_bytes eq $expected_start_bytes
or throw "Invalid credentials or data is corrupt (wrong starting bytes)\n",
got => $start_bytes, expected => $expected_start_bytes, headers => $kdbx->headers;
$kdbx->key($key);
$fh = File::KDBX::IO::HashBlock->new($fh);
my $compress = $kdbx->headers->{+HEADER_COMPRESSION_FLAGS};
if ($compress == COMPRESSION_GZIP) {
load_optional('IO::Uncompress::Gunzip');
$fh = IO::Uncompress::Gunzip->new($fh)
lib/File/KDBX/Loader/V4.pm view on Meta::CPAN
# authentication check
read_all $fh, my $header_hmac, 32 or throw 'Failed to read header HMAC';
my $hmac_key = digest_data('SHA512', $kdbx->headers->{master_seed}, $transformed_key, "\x01");
push @cleanup, erase_scoped $hmac_key;
my $got_header_hmac = hmac('SHA256',
digest_data('SHA512', "\xff\xff\xff\xff\xff\xff\xff\xff", $hmac_key),
$header_data,
);
$got_header_hmac eq $header_hmac
or throw "Invalid credentials or data is corrupt (header HMAC mismatch)\n",
got => $got_header_hmac, expected => $header_hmac;
$kdbx->key($key);
$fh = File::KDBX::IO::HmacBlock->new($fh, key => $hmac_key);
my $final_key = digest_data('SHA256', $kdbx->headers->{master_seed}, $transformed_key);
push @cleanup, erase_scoped $final_key;
my $cipher = $kdbx->cipher(key => $final_key);
}
is $kdbx->minimum_version, $expected_version,
sprintf('Got expected minimum version after modification: %x', $kdbx->minimum_version);
my $master_key = ['fffqcvq4rc', \'this is a keyfile', sub { 'chalresp 523rf2' }];
my $dump;
warnings { $kdbx->dump_string(\$dump, $master_key) };
ok $dump, 'Can dump the database' or diag explain $dump;
like exception { File::KDBX->load_string($dump, 'wrong key') },
qr/invalid credentials/i, 'Cannot load a KDBX with the wrong key';
# print STDERR "DUMP: [$dump]\n";
my $kdbx2 = File::KDBX->load_string($dump, $master_key);
is $kdbx2->version, $expected_version, sprintf('Got expected version: %x', $kdbx2->version);
isnt $kdbx2->kdf->uuid, KDF_UUID_AES, 'No unexpected KDF' if $kdbx2->version >= KDBX_VERSION_4_0;
# diag explain(File::KDBX->load_string($dump, $master_key, inner_format => 'Raw')->raw);
}
( run in 0.375 second using v1.01-cache-2.11-cpan-4d50c553e7e )