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

Implement new SimpleSigstoreVerifier and update exceptions in Verifier #134

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@
<artifactId>jakarta.el</artifactId>
<version>4.0.2</version>
</dependency>
<!-- sigstore-java -->
<dependency>
<groupId>dev.sigstore</groupId>
<artifactId>sigstore-java</artifactId>
<version>0.10.0</version>
</dependency>


</dependencies>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.intoto.dsse.helpers;

import dev.sigstore.KeylessVerificationException;
import dev.sigstore.KeylessVerifier;
import dev.sigstore.VerificationOptions;
import dev.sigstore.bundle.Bundle;
import dev.sigstore.bundle.BundleParseException;
import io.github.intoto.dsse.models.Verifier;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;

public class SimpleSigstoreVerifier implements Verifier {
private VerificationOptions verificationOptions;
Bundle bundle;
String keyId;


@Override
public boolean verify(byte[] bundleJsonBytes, byte[] artifactDigest, String keyId) throws NoSuchAlgorithmException, SignatureException, InvalidKeySpecException, InvalidKeyException, BundleParseException, InvalidAlgorithmParameterException, CertificateException, IOException, KeylessVerificationException {
this.bundle = Bundle.from(new BufferedReader(new StringReader(new String(bundleJsonBytes, StandardCharsets.UTF_8))));
this.keyId = keyId;
String issuer = this.keyId.split(">:")[0];
issuer = issuer.substring(issuer.indexOf("<") + 1);

String san = this.keyId.split(">:")[1];
san = san.substring(san.indexOf("<") + 1, san.lastIndexOf(">"));

this.setVerificationOptions(issuer, san);

KeylessVerifier verifier = new KeylessVerifier.Builder().sigstorePublicDefaults().build();
verifier.verify(artifactDigest, this.bundle, this.verificationOptions);
return true;
}

public void setVerificationOptions(String issuer, String san) {
this.verificationOptions = VerificationOptions.builder()
.addCertificateIdentities(
VerificationOptions.CertificateIdentity.builder()
.issuer(issuer)
.subjectAlternativeName(san)
.build())
.build();
}

@Override
public String getKeyId() {
if (this.keyId.isEmpty()) throw new RuntimeException("Verify the artifact digest to initialize the keyId");
return this.keyId;
}
}
10 changes: 8 additions & 2 deletions src/main/java/io/github/intoto/dsse/models/Verifier.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package io.github.intoto.dsse.models;

import dev.sigstore.KeylessVerificationException;
import dev.sigstore.bundle.BundleParseException;

import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;

/** Interface for a DSSE Verifier */
Expand All @@ -23,8 +29,8 @@ public interface Verifier {
* length, uninitialized, etc).
*/
boolean verify(byte[] publicKey, byte[] encryptedMessage, String message)
throws NoSuchAlgorithmException, SignatureException, InvalidKeySpecException,
InvalidKeyException;
throws NoSuchAlgorithmException, SignatureException, InvalidKeySpecException,
InvalidKeyException, BundleParseException, InvalidAlgorithmParameterException, CertificateException, IOException, KeylessVerificationException;

/** Returns the ID of this key, or null if not supported. */
String getKeyId();
Expand Down