-
Notifications
You must be signed in to change notification settings - Fork 13
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 SimpleSigstoreSigner and update exceptions in Signer #133
Draft
KiranSatyaRaj
wants to merge
6
commits into
in-toto:master
Choose a base branch
from
KiranSatyaRaj:new-SimpleSigstoreSigner
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
421c4e6
Implement new SimpleSigstoreSigner and update exceptions in Signer
KiranSatyaRaj 17520df
format keyId and fix Build errors
KiranSatyaRaj 135bd31
separate header and provider from issuer to match expected issuer value
KiranSatyaRaj 0de9afc
Convert payload into SHA-256 Digest
KiranSatyaRaj 8ec4f3f
tidy up the code
KiranSatyaRaj 82a5e2a
represent keyId as issuer and san pair
KiranSatyaRaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/io/github/intoto/dsse/helpers/SimpleSigstoreSigner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.github.intoto.dsse.helpers; | ||
|
||
import dev.sigstore.KeylessSigner; | ||
import dev.sigstore.KeylessSignerException; | ||
import dev.sigstore.bundle.Bundle; | ||
import io.github.intoto.dsse.models.Signer; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.*; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
import java.security.spec.InvalidKeySpecException; | ||
import java.util.Optional; | ||
|
||
public class SimpleSigstoreSigner implements Signer { | ||
private String keyId; | ||
Optional<Bundle.DSSESignature> dsseSignature; | ||
Bundle result; | ||
|
||
public byte[] sign(byte[] payload) throws InvalidAlgorithmParameterException, CertificateException, IOException, NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, KeylessSignerException { | ||
KeylessSigner functionary = new KeylessSigner.Builder().sigstorePublicDefaults().build(); | ||
this.result = functionary.sign(payload); | ||
|
||
// set keyId | ||
X509Certificate certificate = (X509Certificate) (this.result.getCertPath().getCertificates().getFirst()); | ||
String oid = "1.3.6.1.4.1.57264.1.8"; | ||
byte[] extensionValue = certificate.getExtensionValue(oid); | ||
String issuer = new String(extensionValue, StandardCharsets.UTF_8); | ||
this.keyId = issuer.substring(4); | ||
Object subAltArr = certificate.getSubjectAlternativeNames().toArray()[0]; | ||
String subAltName = subAltArr.toString(); | ||
subAltName = subAltName.substring(4, subAltName.length() - 1); | ||
this.keyId = keyId.concat(" " + subAltName); | ||
|
||
this.dsseSignature = result.getDSSESignature(); | ||
return dsseSignature.get().getSignature(); | ||
} | ||
|
||
@Override | ||
public String getKeyId() { | ||
if (this.keyId.isEmpty()) { | ||
throw new RuntimeException("Sign the artifact to initialize keyId"); | ||
} | ||
return this.keyId; | ||
} | ||
|
||
public byte[] getPayload() { | ||
if (this.dsseSignature.isEmpty()) { | ||
throw new RuntimeException("Cannot retrieve and unsigned payload"); | ||
} | ||
return this.dsseSignature.get().getPayload().getBytes(StandardCharsets.UTF_8); | ||
} | ||
|
||
public Bundle getResult() { | ||
return this.result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you compute the keyid such as:
<oidc provider>:<SAN>
? this way we can also know who actually provided the identity to fulcioThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this how it's supposed to look?
<https://accounts.example.com>: <[email protected]>
@SantiagoTorres