Skip to content

Commit

Permalink
[backend] add BSTUF::key2keyid helper
Browse files Browse the repository at this point in the history
This calculates a TUF key id from a TUF key
  • Loading branch information
mlschroe authored and coolo committed Nov 14, 2018
1 parent 2df12b0 commit 902d7c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/backend/BSPublisher/Registry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ sub update_tuf {
'keytype' => 'rsa',
'keyval' => { 'private' => undef, 'public' => $tuf->{'timestamp_pubkey'} },
};
my $root_key_id = Digest::SHA::sha256_hex(BSTUF::canonical_json($root_key));
my $timestamp_key_id = Digest::SHA::sha256_hex(BSTUF::canonical_json($timestamp_key));
my $root_key_id = BSTUF::key2keyid($root_key);
my $timestamp_key_id = BSTUF::key2keyid($timestamp_key);

#
# setup root
Expand Down
4 changes: 4 additions & 0 deletions src/backend/BSTUF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ sub canonical_json {
return JSON::XS->new->utf8->canonical->encode($d);
}

sub key2keyid {
return Digest::SHA::sha256_hex(canonical_json($_[0]));
}

sub sign {
my ($data, $signargs) = @_;
return BSUtil::xsystem($data, $BSConfig::sign, @$signargs, '-O', '-h', 'sha256');
Expand Down

0 comments on commit 902d7c5

Please sign in to comment.