Skip to content

Commit 2a3ac62

Browse files
authored
Merge pull request #867 from sigstore/update-rekor-types
Import dsse/hashrekord types from rekor
2 parents 9c32a52 + ab54596 commit 2a3ac62

File tree

6 files changed

+139
-11
lines changed

6 files changed

+139
-11
lines changed

fuzzing/src/main/java/fuzzing/RekorTypesFuzzer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ public class RekorTypesFuzzer {
2929

3030
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
3131
try {
32+
int type = data.pickValue(new int[] {0, 1});
3233
String string = data.consumeRemainingAsString();
3334

3435
URI uri = new URI(URL);
3536
RekorEntry entry = RekorResponse.newRekorResponse(uri, string).getEntry();
3637

37-
RekorTypes.getHashedRekord(entry);
38+
if (type == 0) {
39+
RekorTypes.getHashedRekord(entry);
40+
} else {
41+
RekorTypes.getDsse(entry);
42+
}
3843
} catch (URISyntaxException | RekorTypeException | RekorParseException e) {
3944
// Known exception
4045
}

sigstore-java/src/main/java/dev/sigstore/rekor/client/HashedRekordRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import com.google.common.hash.Hashing;
2121
import com.google.common.primitives.Bytes;
22-
import dev.sigstore.rekor.*;
22+
import dev.sigstore.rekor.hashedRekord.v0_0_1.*;
2323
import java.io.IOException;
2424
import java.nio.charset.StandardCharsets;
2525
import java.util.Base64;

sigstore-java/src/main/java/dev/sigstore/rekor/client/RekorTypeException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ public class RekorTypeException extends Exception {
1919
public RekorTypeException(String message) {
2020
super(message);
2121
}
22+
23+
public RekorTypeException(String message, Throwable reason) {
24+
super(message, reason);
25+
}
2226
}

sigstore-java/src/main/java/dev/sigstore/rekor/client/RekorTypes.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

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

20-
import dev.sigstore.rekor.HashedRekord;
20+
import com.google.gson.JsonParseException;
21+
import dev.sigstore.rekor.dsse.v0_0_1.Dsse;
22+
import dev.sigstore.rekor.hashedRekord.v0_0_1.HashedRekord;
2123

2224
/** Parser for the body.spec element of {@link RekorEntry}. */
2325
public class RekorTypes {
@@ -27,12 +29,33 @@ public class RekorTypes {
2729
*
2830
* @param entry the rekor entry obtained from rekor
2931
* @return the parsed pojo
30-
* @throws RekorTypeException if the kind != hashedrekord or apiVersion != 0.0.1
32+
* @throws RekorTypeException if the hashrekord:0.0.1 entry could not be parsed
3133
*/
3234
public static HashedRekord getHashedRekord(RekorEntry entry) throws RekorTypeException {
3335
expect(entry, "hashedrekord", "0.0.1");
3436

35-
return GSON.get().fromJson(entry.getBodyDecoded().getSpec(), HashedRekord.class);
37+
try {
38+
return GSON.get().fromJson(entry.getBodyDecoded().getSpec(), HashedRekord.class);
39+
} catch (JsonParseException jpe) {
40+
throw new RekorTypeException("Could not parse hashrekord:0.0.1", jpe);
41+
}
42+
}
43+
44+
/**
45+
* Parse a dsse from rekor at api version 0.0.1.
46+
*
47+
* @param entry the rekor entry obtained from rekor
48+
* @return the parsed pojo
49+
* @throws RekorTypeException if the dsse:0.0.1 entry could not be parsed
50+
*/
51+
public static Dsse getDsse(RekorEntry entry) throws RekorTypeException {
52+
expect(entry, "dsse", "0.0.1");
53+
54+
try {
55+
return GSON.get().fromJson(entry.getBodyDecoded().getSpec(), Dsse.class);
56+
} catch (JsonParseException jpe) {
57+
throw new RekorTypeException("Could not parse dsse:0.0.1", jpe);
58+
}
3659
}
3760

3861
private static void expect(RekorEntry entry, String expectedKind, String expectedApiVersion)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "http://rekor.sigstore.dev/types/dsse/dsse_v0_0_1_schema.json",
4+
"title": "DSSE v0.0.1 Schema",
5+
"description": "Schema for DSSE envelopes",
6+
"type": "object",
7+
"properties": {
8+
"proposedContent": {
9+
"type": "object",
10+
"properties": {
11+
"envelope": {
12+
"description": "DSSE envelope specified as a stringified JSON object",
13+
"type": "string",
14+
"writeOnly": true
15+
},
16+
"verifiers": {
17+
"description": "collection of all verification material (e.g. public keys or certificates) used to verify signatures over envelope's payload, specified as base64-encoded strings",
18+
"type": "array",
19+
"minItems": 1,
20+
"items": {
21+
"type": "string",
22+
"format": "byte"
23+
},
24+
"writeOnly": true
25+
}
26+
},
27+
"writeOnly": true,
28+
"required": [ "envelope", "verifiers" ]
29+
},
30+
"signatures": {
31+
"description": "extracted collection of all signatures of the envelope's payload; elements will be sorted by lexicographical order of the base64 encoded signature strings",
32+
"type": "array",
33+
"minItems": 1,
34+
"items": {
35+
"description": "a signature of the envelope's payload along with the verification material for the signature",
36+
"type": "object",
37+
"properties": {
38+
"signature": {
39+
"description": "base64 encoded signature of the payload",
40+
"type": "string",
41+
"pattern": "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$"
42+
},
43+
"verifier": {
44+
"description": "verification material that was used to verify the corresponding signature, specified as a base64 encoded string",
45+
"type": "string",
46+
"format": "byte"
47+
}
48+
},
49+
"required": [ "signature", "verifier" ]
50+
},
51+
"readOnly": true
52+
},
53+
"envelopeHash": {
54+
"description": "Specifies the hash algorithm and value encompassing the entire envelope sent to Rekor",
55+
"type": "object",
56+
"properties": {
57+
"algorithm": {
58+
"description": "The hashing function used to compute the hash value",
59+
"type": "string",
60+
"enum": [ "sha256" ]
61+
},
62+
"value": {
63+
"description": "The value of the computed digest over the entire envelope",
64+
"type": "string"
65+
}
66+
},
67+
"required": [ "algorithm", "value" ],
68+
"readOnly": true
69+
},
70+
"payloadHash": {
71+
"description": "Specifies the hash algorithm and value covering the payload within the DSSE envelope",
72+
"type": "object",
73+
"properties": {
74+
"algorithm": {
75+
"description": "The hashing function used to compute the hash value",
76+
"type": "string",
77+
"enum": [ "sha256" ]
78+
},
79+
"value": {
80+
"description": "The value of the computed digest over the payload within the envelope",
81+
"type": "string"
82+
}
83+
},
84+
"required": [ "algorithm", "value" ],
85+
"readOnly": true
86+
}
87+
},
88+
"oneOf": [
89+
{
90+
"required": [ "proposedContent" ]
91+
},
92+
{
93+
"required": [ "signatures", "envelopeHash", "payloadHash" ]
94+
}
95+
]
96+
}

sigstore-java/src/main/resources/rekor/model/hashedRekord.json renamed to sigstore-java/src/main/resources/rekor/model/hashedRekord/v0.0.1/hashedRekord.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$id": "http://rekor.sigstore.dev/types/rekord/rekord_v0_0_1_schema.json",
3+
"$id": "http://rekor.sigstore.dev/types/rekord/hashedrekord_v0_0_1_schema.json",
44
"title": "Hashed Rekor v0.0.1 Schema",
55
"description": "Schema for Hashed Rekord object",
66
"type": "object",
@@ -15,11 +15,11 @@
1515
"format": "byte"
1616
},
1717
"publicKey" : {
18-
"description": "The public key that can verify the signature",
18+
"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",
1919
"type": "object",
2020
"properties": {
2121
"content": {
22-
"description": "Specifies the content of the public key inline within the document",
22+
"description": "Specifies the content of the public key or code signing certificate inline within the document",
2323
"type": "string",
2424
"format": "byte"
2525
}
@@ -38,16 +38,16 @@
3838
"algorithm": {
3939
"description": "The hashing function used to compute the hash value",
4040
"type": "string",
41-
"enum": [ "sha256" ]
41+
"enum": [ "sha256", "sha384", "sha512" ]
4242
},
4343
"value": {
44-
"description": "The hash value for the content",
44+
"description": "The hash value for the content, as represented by a lower case hexadecimal string",
4545
"type": "string"
4646
}
4747
},
4848
"required": [ "algorithm", "value" ]
4949
}
50-
}
50+
}
5151
}
5252
},
5353
"required": [ "signature", "data" ]

0 commit comments

Comments
 (0)