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

Use spec-compliant persisted target filenames #411

Merged
merged 1 commit into from
Apr 5, 2023
Merged
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: 4 additions & 1 deletion sigstore-java/src/main/java/dev/sigstore/tuf/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ void downloadTargets(Targets targets)
throw new FileNotFoundException(targetName, fetcher.getSource());
}
verifyHashes(entry.getKey(), targetBytes, targetData.getHashes());
localStore.storeTargetFile(versionedTargetName, targetBytes);

// when persisting targets use the targetname without sha512 prefix
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link you mention suggests checksum-prefixed names for consistent snapshots scheme. Why we should skip checksums here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the relevant line of the link:

In either case, the client MUST write the file to non-volatile storage as FILENAME.EXT.

The code already does fetch by the checksummed prefixed name (versionedTargetName), but we write without the prefix.

// https://theupdateframework.github.io/specification/latest/index.html#fetch-target
localStore.storeTargetFile(targetName, targetBytes);
}
}

Expand Down
26 changes: 7 additions & 19 deletions sigstore-java/src/test/java/dev/sigstore/tuf/UpdaterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.hash.Hashing;
import com.google.gson.JsonSyntaxException;
import dev.sigstore.encryption.signers.Verifier;
import dev.sigstore.encryption.signers.Verifiers;
Expand Down Expand Up @@ -591,24 +592,9 @@ public void testTargetsDownload_success()
var snapshot = updater.updateSnapshot(root, timestamp.get());
var targets = updater.updateTargets(root, snapshot);
updater.downloadTargets(targets);
assertTrue(
updater
.getLocalStore()
.getTargetFile(
"860de8f9a858eea7190fcfa1b53fe55914d3c38f17f8f542273012d19cc9509bb423f37b7c13c577a56339ad7f45273b479b1d0df837cb6e20a550c27cce0885.test.txt")
!= null);
assertTrue(
updater
.getLocalStore()
.getTargetFile(
"32005f02eac21b4cf161a02495330b6c14b548622b5f7e19d59ecfa622de650603ecceea39ed86cc322749a813503a72ad14ce5462c822b511eaf2f2cd2ad8f2.test.txt.v2")
!= null);
assertTrue(
updater
.getLocalStore()
.getTargetFile(
"53904bc6216230bf8da0ec42d34004a3f36764de698638641870e37d270e4fd13e1079285f8bca73c2857a279f6f7fbc82038274c3eb48ec5bb2da9b2e30491a.test2.txt")
!= null);
assertTrue(updater.getLocalStore().getTargetFile("test.txt") != null);
assertTrue(updater.getLocalStore().getTargetFile("test.txt.v2") != null);
assertTrue(updater.getLocalStore().getTargetFile("test2.txt") != null);
}

// End to end sanity test on the actual prod sigstore repo.
Expand Down Expand Up @@ -648,9 +634,11 @@ public void testUpdate_fromProdData()
Map<String, TargetMeta.TargetData> targetsData = targets.get().getSignedMeta().getTargets();
for (String file : targetsData.keySet()) {
TargetMeta.TargetData fileData = targetsData.get(file);
byte[] fileBytes = localStore.getTargetFile(fileData.getHashes().getSha512() + "." + file);
byte[] fileBytes = localStore.getTargetFile(file);
assertNotNull(fileBytes, "each file from targets data should be present");
assertEquals(fileData.getLength(), fileBytes.length, "file length should match metadata");
assertEquals(
fileData.getHashes().getSha512(), Hashing.sha512().hashBytes(fileBytes).toString());
}
}

Expand Down