Package dev.sigstore.plugin
Class JarSign
java.lang.Object
org.apache.maven.plugin.AbstractMojo
dev.sigstore.plugin.JarSign
- All Implemented Interfaces:
- org.apache.maven.plugin.ContextEnabled,- org.apache.maven.plugin.Mojo
@Mojo(name="jarsign",
      defaultPhase=PACKAGE)
public class JarSign
extends org.apache.maven.plugin.AbstractMojo
Goal which:
- generates ephemeral key pair
- gets OIDC token and associated email
- requests code signing certificate from sigstore Fulcio
- signs the JAR file (with jarsigner)
- publishes signed JAR file (that contains the signature per JAR signing spec) to sigstore Rekor
- 
Field SummaryFields inherited from interface org.apache.maven.plugin.MojoROLE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidexecute()generateKeyPair(String signingAlgorithm, String signingAlgorithmSpec) Returns a new ephemeral keypair according to the plugin parameterscom.google.api.client.http.HttpTransportGenerates an HTTP Transport according to the requested SSL verification settingsgetIDToken(String expectedEmailAddress) Obtains an OpenID Connect Identity Token from the OIDC provider specified inoidcAuthURLgetSigningCert(String signedEmail, PublicKey pubKey, String idToken) Obtains a X509 code signing certificate signed by the Fulcio instance specified infulcioInstanceURL.signEmailAddress(String emailAddress, PrivateKey privKey) Signs the provided email address using the provided private keybyte[]signJarFile(PrivateKey privKey, CertPath certs) Signs a JAR file withjarsignerusing the private key; the provided certificate chain will be included in the signed JAR filesubmitToRekor(byte[] jarBytes) Submits the jarsigned JAR to a Rekor transparency log, with rekorjartypevoidwriteSigningCertToFile(CertPath certs, File outputSigningCert) Writes the code signing certificate to a fileMethods inherited from class org.apache.maven.plugin.AbstractMojogetLog, getPluginContext, setLog, setPluginContext
- 
Constructor Details- 
JarSignpublic JarSign()
 
- 
- 
Method Details- 
executepublic void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
- org.apache.maven.plugin.MojoExecutionException
 
- 
generateKeyPairpublic KeyPair generateKeyPair(String signingAlgorithm, String signingAlgorithmSpec) throws org.apache.maven.plugin.MojoExecutionException Returns a new ephemeral keypair according to the plugin parameters- Parameters:
- signingAlgorithm- an absolute URL giving the base location of the image
- signingAlgorithmSpec- the location of the image, relative to the url argument
- Returns:
- the public and private keypair
- Throws:
- org.apache.maven.plugin.MojoExecutionException- If any exception happened during the key generation process
 
- 
signEmailAddresspublic String signEmailAddress(String emailAddress, PrivateKey privKey) throws org.apache.maven.plugin.MojoExecutionException Signs the provided email address using the provided private key- Parameters:
- emailAddress- The email address to sign; this should match the email address in the OIDC token
- privKey- The private key used to sign the email address
- Returns:
- base64 encoded String containing the signature for the provided email address
- Throws:
- org.apache.maven.plugin.MojoExecutionException- If any exception happened during the signing process
 
- 
getHttpTransportpublic com.google.api.client.http.HttpTransport getHttpTransport()Generates an HTTP Transport according to the requested SSL verification settings- Returns:
- transport object with SSL verification enabled/disabled per the plugin parameter sslVerification
 
- 
getIDTokenpublic String getIDToken(String expectedEmailAddress) throws org.apache.maven.plugin.MojoExecutionException Obtains an OpenID Connect Identity Token from the OIDC provider specified inoidcAuthURL- Parameters:
- expectedEmailAddress- The email address we expected to see in the identity token
- Returns:
- the ID token String (in JWS format)
- Throws:
- org.apache.maven.plugin.MojoExecutionException- If any exception happened during the OIDC authentication flow
 
- 
getSigningCertpublic CertPath getSigningCert(String signedEmail, PublicKey pubKey, String idToken) throws org.apache.maven.plugin.MojoExecutionException Obtains a X509 code signing certificate signed by the Fulcio instance specified infulcioInstanceURL.- Parameters:
- signedEmail- a base64 encoded String containing the signed email address to associate with the requested certificate
- pubKey- the public key used to verify the signed email address; this key will be included in the final certificate
- idToken- a raw OIDC Identity token specified in JWS format
- Returns:
- The certificate chain including the code signing certificate
- Throws:
- org.apache.maven.plugin.MojoExecutionException- If any exception happened during the request for the code signing certificate
 
- 
signJarFilepublic byte[] signJarFile(PrivateKey privKey, CertPath certs) throws org.apache.maven.plugin.MojoExecutionException Signs a JAR file withjarsignerusing the private key; the provided certificate chain will be included in the signed JAR file- Parameters:
- privKey- the private key that should be used to sign the JAR file
- certs- The certificate chain including the code signing certificate which can be used to verify the signature
- Returns:
- The signed JAR file in byte array
- Throws:
- org.apache.maven.plugin.MojoExecutionException- If any exception happened during the JAR signing process
 
- 
writeSigningCertToFilepublic void writeSigningCertToFile(CertPath certs, File outputSigningCert) throws org.apache.maven.plugin.MojoExecutionException Writes the code signing certificate to a file- Parameters:
- certs- The certificate chain including the code signing certificate which can be used to verify the signature
- outputSigningCert- The file where the code signing cert should be written to
- Throws:
- org.apache.maven.plugin.MojoExecutionException- If any exception happened during writing the certificate to the specified file
 
- 
submitToRekorSubmits the jarsigned JAR to a Rekor transparency log, with rekorjartype- Parameters:
- jarBytes- The signed JAR file in a byte array
- Returns:
- The URL where the entry in the transparency log can be seen for this signature/key combination
- Throws:
- org.apache.maven.plugin.MojoExecutionException- If any exception happened during interaction with the Rekor instance
 
 
-