Skip to content

Commit

Permalink
provide user-friendly verifyDelegate wrapper (#164)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Flynn <patrick@chainguard.dev>

Signed-off-by: Patrick Flynn <patrick@chainguard.dev>
  • Loading branch information
Patrick Flynn authored Sep 22, 2022
1 parent 074a869 commit 86b5a33
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions sigstore-java/src/main/java/dev/sigstore/tuf/TufClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,9 @@ public void updateRoot()
// a) a threshold (from step 2) of keys specified in the trusted metadata
// b) and a threshold of keys in the new root.json.
// Fail if either a or b aren't true.
var trustedRootKeys = trustedRoot.getSignedMeta().getKeys();
var newRootSignatures = newRoot.getSignatures();
byte[] newRootMetaBytes = newRoot.getCanonicalSignedBytes();
// Verify our new root meta against the trusted root keys.
RootRole trustedRootRoleMeta = trustedRoot.getSignedMeta().getRole(Role.Name.ROOT);
verifyDelegate(newRootSignatures, trustedRootKeys, trustedRootRoleMeta, newRootMetaBytes);

var newRootRoleMeta = newRoot.getSignedMeta().getRole(Role.Name.ROOT);
var newRootKeys = newRoot.getSignedMeta().getKeys();
// Verify our new root meta against the new root keys.
verifyDelegate(newRootSignatures, newRootKeys, newRootRoleMeta, newRootMetaBytes);

verifyDelegate(trustedRoot, newRoot);
verifyDelegate(newRoot, newRoot);

// 5.3.5) We've taken the liberty to modify 5.3.5 to just validate that the new root meta
// matches the version we pulled based off of the pattern {version}.root.json. We know due to
Expand Down Expand Up @@ -154,6 +146,17 @@ private boolean hasNewKeys(RootRole oldRole, RootRole newRole) {
return newRole.getKeyids().stream().allMatch(s -> oldRole.getKeyids().contains(s));
}

void verifyDelegate(Root trustedRoot, SignedTufMeta delegate)
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException {
verifyDelegate(
delegate.getSignatures(),
trustedRoot.getSignedMeta().getKeys(),
trustedRoot
.getSignedMeta()
.getRole(Role.Name.valueOf(delegate.getSignedMeta().getType().toUpperCase())),
delegate.getCanonicalSignedBytes());
}

/**
* Verifies that a delegate role has been signed by the threshold amount of keys.
*
Expand Down

0 comments on commit 86b5a33

Please sign in to comment.