View Javadoc
1   package org.codehaus.mojo.webstart.sign;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.MojoExecutionException;
23  
24  import java.io.File;
25  
26  /**
27   * Tool api for jarsigner operations.
28   *
29   * @author tchemit <chemit@codelutin.com>
30   * @since 1.0-beta-3
31   */
32  public interface SignTool
33  {
34  
35      /**
36       * Plexus component role.
37       */
38      String ROLE = SignTool.class.getName();
39  
40      /**
41       * Obtain the location of the given keystore.
42       * <p/>
43       * If the keystore is a file then just return it, otherwise if is a resource from class path or a valid url,
44       * then copy the resource to given working keystore location.
45       *
46       * @param keystore        keystore location to find
47       * @param workingKeystore location where to copy keystore if coming from an url or from classpath
48       * @param classLoader     classloader where to find keystore in classpath
49       * @return the file location of the keystore saved if required in working directory or {@code null} if could not
50       * locate keystore.
51       * @throws MojoExecutionException if something wrong occurs
52       * @since 1.0-beta-4
53       */
54      File getKeyStoreFile( String keystore, File workingKeystore, ClassLoader classLoader )
55          throws MojoExecutionException;
56  
57      /**
58       * Generate a key store using keytool.
59       *
60       * @param config       sign configuration
61       * @param keystoreFile location of the keystore to generate
62       * @throws MojoExecutionException if something wrong occurs
63       */
64      void generateKey( SignConfig config, File keystoreFile )
65          throws MojoExecutionException;
66  
67      /**
68       * Sign a jar using jarsigner.
69       *
70       * @param config    sign configuration
71       * @param jarFile   location of the jar to sign
72       * @param signedJar optional location of the signed jar to produce (if not set, will use the original location)
73       * @throws MojoExecutionException if something wrong occurs
74       */
75      void sign( SignConfig config, File jarFile, File signedJar )
76          throws MojoExecutionException;
77  
78      /**
79       * Verify a jar file using jarsigner.
80       *
81       * @param config  sign configuration
82       * @param jarFile location of the jar to sign
83       * @param certs   flag to show certificats details
84       * @throws MojoExecutionException if something wrong occurs
85       */
86      void verify( SignConfig config, File jarFile, boolean certs )
87          throws MojoExecutionException;
88  
89      /**
90       * Tests if the given jar is signed.
91       *
92       * @param jarFile the jar file to test
93       * @return {@code true} if jar file is signed, {@code false} otherwise
94       * @throws MojoExecutionException if something wrong occurs
95       * @since 1.0-beta-4
96       */
97      boolean isJarSigned( File jarFile )
98          throws MojoExecutionException;
99  
100     /**
101      * Unsign a jar.
102      *
103      * @param jarFile location of the jar to unsign
104      * @param verbose flag to display verbose logs
105      * @throws MojoExecutionException if something wrong occurs
106      * @since 1.0-beta-4
107      */
108     void unsign( File jarFile, boolean verbose )
109         throws MojoExecutionException;
110 
111     /**
112      * Delete an existing key store
113      *
114      * @param keystore the keystore to delete
115      * @param verbose  flag to display verbose logs
116      */
117     void deleteKeyStore( File keystore, boolean verbose );
118 }