Skip to content

Commit

Permalink
Rekor Entry should be reconstructued to match
Browse files Browse the repository at this point in the history
Signed-off-by: Appu Goundan <appu@google.com>
  • Loading branch information
loosebazooka committed Nov 22, 2024
1 parent b440f06 commit 05a2fe5
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 8 deletions.
20 changes: 20 additions & 0 deletions sigstore-java/src/main/java/dev/sigstore/KeylessVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
import dev.sigstore.encryption.signers.Verifiers;
import dev.sigstore.fulcio.client.FulcioVerificationException;
import dev.sigstore.fulcio.client.FulcioVerifier;
import dev.sigstore.rekor.client.HashedRekordRequest;
import dev.sigstore.rekor.client.RekorEntry;
import dev.sigstore.rekor.client.RekorVerificationException;
import dev.sigstore.rekor.client.RekorVerifier;
import dev.sigstore.tuf.SigstoreTufClient;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
Expand All @@ -44,7 +46,9 @@
import java.sql.Date;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.encoders.Hex;

/** Verify hashrekords from rekor signed using the keyless signing flow with fulcio certificates. */
Expand Down Expand Up @@ -182,6 +186,22 @@ public void verify(byte[] artifactDigest, Bundle bundle, VerificationOptions opt
throw new KeylessVerificationException("Rekor entry signature was not valid", ex);
}

// verify the log entry is relevant to the provided verification materials
try {
var calculatedHashedRekord =
Base64.toBase64String(
HashedRekordRequest.newHashedRekordRequest(
artifactDigest, Certificates.toPemBytes(leafCert), signature)
.toJsonPayload()
.getBytes(StandardCharsets.UTF_8));
if (!Objects.equals(calculatedHashedRekord, rekorEntry.getBody())) {
throw new KeylessVerificationException(
"Provided verification materials are inconsistent with log entry");
}
} catch (IOException e) {
throw new RuntimeException(e);
}

// check if the time of entry inclusion in the log (a stand-in for signing time) is within the
// validity period for the certificate
var entryTime = Date.from(rekorEntry.getIntegratedTimeInstant());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import com.google.common.hash.Hashing;
import com.google.common.primitives.Bytes;
import dev.sigstore.rekor.*;
import dev.sigstore.rekor.hashedRekord.v0_0_1.*;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static dev.sigstore.json.GsonSupplier.GSON;

import dev.sigstore.rekor.HashedRekord;
import dev.sigstore.rekor.hashedRekord.v0_0_1.HashedRekord;

/** Parser for the body.spec element of {@link RekorEntry}. */
public class RekorTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private RekorVerifier(List<TransparencyLog> tlogs) {
}

/**
* Verify that a Rekor Entry is signed with the rekor public key loaded into this verifier
* Verify that a Rekor Entry is signed with the rekor public key loaded into this verifier.
*
* @param entry the entry to verify
* @throws RekorVerificationException if the entry cannot be verified
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://rekor.sigstore.dev/types/rekord/rekord_v0_0_1_schema.json",
"$id": "http://rekor.sigstore.dev/types/rekord/hashedrekord_v0_0_1_schema.json",
"title": "Hashed Rekor v0.0.1 Schema",
"description": "Schema for Hashed Rekord object",
"type": "object",
Expand All @@ -15,11 +15,11 @@
"format": "byte"
},
"publicKey" : {
"description": "The public key that can verify the signature",
"description": "The public key that can verify the signature; this can also be an X509 code signing certificate that contains the raw public key information",
"type": "object",
"properties": {
"content": {
"description": "Specifies the content of the public key inline within the document",
"description": "Specifies the content of the public key or code signing certificate inline within the document",
"type": "string",
"format": "byte"
}
Expand All @@ -38,10 +38,10 @@
"algorithm": {
"description": "The hashing function used to compute the hash value",
"type": "string",
"enum": [ "sha256" ]
"enum": [ "sha256", "sha384", "sha512" ]
},
"value": {
"description": "The hash value for the content",
"description": "The hash value for the content, as represented by a lower case hexadecimal string",
"type": "string"
}
},
Expand Down
21 changes: 21 additions & 0 deletions sigstore-java/src/test/java/dev/sigstore/KeylessVerifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ public void testVerify_mismatchedSet() throws Exception {
VerificationOptions.empty()));
}

@Test
public void testVerify_mismatchedArtifactHash() throws Exception {
// a bundle file that uses the tlog entry from another artifact signed with the same
// certificate. The Bundle is fully valid except that the artifact hash doesn't match
var bundleFile =
Resources.toString(
Resources.getResource(
"dev/sigstore/samples/bundles/bundle-with-wrong-tlog-entry.sigstore"),
StandardCharsets.UTF_8);
var artifact = Resources.getResource("dev/sigstore/samples/bundles/artifact.txt").getPath();

var verifier = KeylessVerifier.builder().sigstorePublicDefaults().build();
Assertions.assertThrows(
KeylessVerificationException.class,
() ->
verifier.verify(
Path.of(artifact),
Bundle.from(new StringReader(bundleFile)),
VerificationOptions.empty()));
}

@Test
public void testVerify_errorsOnDSSEBundle() throws Exception {
var bundleFile =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"mediaType": "application/vnd.dev.sigstore.bundle.v0.3+json",
"verificationMaterial": {
"tlogEntries": [{
"logIndex": "150603746",
"logId": {
"keyId": "wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
},
"kindVersion": {
"kind": "hashedrekord",
"version": "0.0.1"
},
"integratedTime": "1732221080",
"inclusionPromise": {
"signedEntryTimestamp": "MEUCIQDY5kN3WEDvMndKO5JImUGrtV5jW1cVGnEDylEKRk7ZsAIgZN1MIv+eILssoHtsqqk+b9Tda+2ZN3Lkz1Mw8GwTD9k="
},
"inclusionProof": {
"logIndex": "28699484",
"rootHash": "p+AbctDd928yM1oCzeJPou8nHME2Qyka0DMB1tOlqsI=",
"treeSize": "28699488",
"hashes": ["fcyRKy95RMsZh/HeRQaZK8jFhhrdqqA5iFs+wInZsaI=", "zl59JwaJVeTvAF5pCTPbaXXdXgsYidumj8TgjRvcZIA=", "4mck2Czn6tiBqOQYPlh3ATO9DaTvouT7biFAkCz4bWM=", "BipkUG/DzduS/XjrbEd3uC5odEYaC9OTJTYElA10POo=", "9yDO9YZftL6yDveO6bWY32s8D4y3+uWUKVLEPmRwbHk=", "GMMIMtm+cQ0ajPC1YWzZCJIZ517pDeYJ5+FnZinynQg=", "9henJICU+Lo3pa+Rrtnt8+5esX8hhksuDcqmaYvxLHA=", "aL2yyr/c5w5R72E6L+AagxQB/oMUftqB7fHIs625QR0=", "Fvp+S31pMTO9ts92nEBj6sYay8OFauXxYrevM73sg3U=", "tk7EpIXIblK0ktOJNY9T+WCMpW0loWy+GouFKk7me8k=", "Ky28cDNBQqCVLHhOLegW99yo/fkUTkjmWsr56fXTt+E=", "PTN8SB4uaeclDiwUlPK/FSmiK7voPpkD8GBfNeRCFnw=", "0C1qnoT2c+8KErA01/VosqRATcsPFXeswb8bk/eb/3g=", "5EVC7yaMdjhwDR6OLXLyveRuRrF8xvXTzlm+8+vzfxE=", "bulsENariUUsC4xiR1yFtqKzD8evI9p/s+YCpl8t9tE=", "E2rLOYPJFKiizYiyu07QLqkMVTVL7i2ZgXiQywdI9KQ=", "4lUF0YOu9XkIDXKXA0wMSzd6VeDY3TZAgmoOeWmS2+Y=", "gf+9m552B3PnkWnO0o4KdVvjcT3WVHLrCbf1DoVYKFw="],
"checkpoint": {
"envelope": "rekor.sigstore.dev - 1193050959916656506\n28699488\np+AbctDd928yM1oCzeJPou8nHME2Qyka0DMB1tOlqsI\u003d\n\n— rekor.sigstore.dev wNI9ajBFAiEA+50Xtrawp0K2slioi3f8lpCrZGu8k919PDoZ+Z80/WUCIDaUTds/GljSB8/Mu7DLj879oi/odHrPZ0OUeubKlBGd\n"
}
},
"canonicalizedBody": "eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2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Qow1W76Ab8="
},
"signature": "MEYCIQCGZcJ+4mTIMPAyIKV7XZjZ5KyvX1tz/glbin9vVF+9fwIhANUb5z/2Rb88vtvtABHAmQyBl4Yp8ipMLCnv36Ln8/Eb"
}
}

0 comments on commit 05a2fe5

Please sign in to comment.