|
17 | 17 |
|
18 | 18 | import com.google.common.hash.Hashing;
|
19 | 19 | import dev.sigstore.encryption.signers.Verifiers;
|
| 20 | +import dev.sigstore.rekor.client.RekorEntry.Checkpoint; |
20 | 21 | import dev.sigstore.trustroot.SigstoreTrustedRoot;
|
| 22 | +import dev.sigstore.trustroot.TransparencyLog; |
21 | 23 | import dev.sigstore.trustroot.TransparencyLogs;
|
22 | 24 | import java.security.InvalidKeyException;
|
23 | 25 | import java.security.NoSuchAlgorithmException;
|
24 | 26 | import java.security.SignatureException;
|
25 | 27 | import java.security.spec.InvalidKeySpecException;
|
| 28 | +import java.util.Arrays; |
26 | 29 | import java.util.Base64;
|
27 | 30 | import org.bouncycastle.util.encoders.Hex;
|
28 | 31 |
|
@@ -84,6 +87,7 @@ public void verifyEntry(RekorEntry entry) throws RekorVerificationException {
|
84 | 87 |
|
85 | 88 | // verify inclusion proof
|
86 | 89 | verifyInclusionProof(entry);
|
| 90 | + verifyCheckpoint(entry, tlog); |
87 | 91 | }
|
88 | 92 |
|
89 | 93 | /** Verify that a Rekor Entry is in the log by checking inclusion proof. */
|
@@ -134,6 +138,43 @@ private void verifyInclusionProof(RekorEntry entry) throws RekorVerificationExce
|
134 | 138 | }
|
135 | 139 | }
|
136 | 140 |
|
| 141 | + private void verifyCheckpoint(RekorEntry entry, TransparencyLog tlog) |
| 142 | + throws RekorVerificationException { |
| 143 | + Checkpoint checkpoint; |
| 144 | + try { |
| 145 | + checkpoint = entry.getVerification().getInclusionProof().parsedCheckpoint(); |
| 146 | + } catch (RekorParseException ex) { |
| 147 | + throw new RekorVerificationException("Could not parse checkpoint", ex); |
| 148 | + } |
| 149 | + |
| 150 | + byte[] inclusionRootHash = |
| 151 | + Hex.decode(entry.getVerification().getInclusionProof().getRootHash()); |
| 152 | + byte[] checkpointRootHash = Base64.getDecoder().decode(checkpoint.getBase64Hash()); |
| 153 | + |
| 154 | + if (!Arrays.equals(inclusionRootHash, checkpointRootHash)) { |
| 155 | + throw new RekorVerificationException( |
| 156 | + "Checkpoint root hash does not match root hash provided in inclusion proof"); |
| 157 | + } |
| 158 | + var keyHash = Hashing.sha256().hashBytes(tlog.getPublicKey().getRawBytes()).asBytes(); |
| 159 | + // checkpoint 0 is always the log, not any of the cross signing verifiers/monitors |
| 160 | + var sig = checkpoint.getSignatures().get(0); |
| 161 | + for (int i = 0; i < 4; i++) { |
| 162 | + if (sig.getKeyHint()[i] != keyHash[i]) { |
| 163 | + throw new RekorVerificationException( |
| 164 | + "Checkpoint key hint did not match provided log public key"); |
| 165 | + } |
| 166 | + } |
| 167 | + try { |
| 168 | + Verifiers.newVerifier(tlog.getPublicKey().toJavaPublicKey()) |
| 169 | + .verifyDigest(inclusionRootHash, sig.getSignature()); |
| 170 | + } catch (NoSuchAlgorithmException |
| 171 | + | InvalidKeySpecException |
| 172 | + | SignatureException |
| 173 | + | InvalidKeyException ex) { |
| 174 | + throw new RekorVerificationException("Could not verify checkpoint signature", ex); |
| 175 | + } |
| 176 | + } |
| 177 | + |
137 | 178 | private static byte[] combineBytes(byte[] first, byte[] second) {
|
138 | 179 | byte[] result = new byte[first.length + second.length];
|
139 | 180 | System.arraycopy(first, 0, result, 0, first.length);
|
|
0 commit comments