Skip to content

Commit 9cf6288

Browse files
committed
Improved the Javadoc
1 parent 80c1cc9 commit 9cf6288

File tree

10 files changed

+145
-17
lines changed

10 files changed

+145
-17
lines changed

jsign-core/src/main/java/net/jsign/AuthenticodeSigner.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,22 @@
7676
/**
7777
* Sign a file with Authenticode. Timestamping is enabled by default and relies
7878
* on the Sectigo server (http://timestamp.sectigo.com).
79-
*
79+
*
80+
* <p>Example:</p>
81+
* <pre>
82+
* KeyStore keystore = new KeyStoreBuilder().keystore("keystore.p12").storepass("password").build();
83+
*
84+
* AuthenticodeSigner signer = new AuthenticodeSigner(keystore, "alias", "secret");
85+
* signer.withProgramName("My Application")
86+
* .withProgramURL("http://www.example.com")
87+
* .withTimestamping(true)
88+
* .withTimestampingAuthority("http://timestamp.sectigo.com");
89+
*
90+
* try (Signable file = Signable.of(new File("application.exe"))) {
91+
* signer.sign(file);
92+
* }
93+
* </pre>
94+
*
8095
* @author Emmanuel Bourg
8196
* @since 3.0
8297
*/
@@ -536,6 +551,7 @@ protected CMSSignedData addNestedSignature(CMSSignedData primary, CMSSignedData
536551
* By default looks up the default identifier but also makes sure it includes
537552
* the algorithm parameters and if not includes a DER NULL in order to align
538553
* with what signtool currently does.
554+
*
539555
* @param signatureAlgorithm to get the corresponding digest algorithm identifier for
540556
* @return an AlgorithmIdentifier for the digestAlgorithm and including parameters
541557
*/

jsign-core/src/main/java/net/jsign/DigestAlgorithm.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,20 @@
2929
* @since 1.3
3030
*/
3131
public enum DigestAlgorithm {
32+
33+
/** MD5 Message-Digest Algorithm (128 bits) */
3234
MD5("MD5", TSPAlgorithms.MD5),
35+
36+
/** Secure Hash Algorithm 1 (160 bits) */
3337
SHA1("SHA-1", TSPAlgorithms.SHA1),
38+
39+
/** Secure Hash Algorithm 2 (256 bits) */
3440
SHA256("SHA-256", TSPAlgorithms.SHA256),
41+
42+
/** Secure Hash Algorithm 2 (384 bits) */
3543
SHA384("SHA-384", TSPAlgorithms.SHA384),
44+
45+
/** Secure Hash Algorithm 2 (512 bits) */
3646
SHA512("SHA-512", TSPAlgorithms.SHA512);
3747

3848
/** The JCE name of the algorithm */

jsign-core/src/main/java/net/jsign/KeyStoreBuilder.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,17 @@ String parameterName() {
6868
return parameterName;
6969
}
7070

71+
/**
72+
* Sets the file containing the keystore.
73+
*/
7174
public KeyStoreBuilder keystore(File keystore) {
7275
return keystore(keystore.getPath());
7376
}
7477

78+
/**
79+
* Sets the name of the resource containing the keystore. Either the path of the keystore file,
80+
* the SunPKCS11 configuration file or the cloud keystore name depending on the type of keystore.
81+
*/
7582
public KeyStoreBuilder keystore(String keystore) {
7683
this.keystore = keystore;
7784
return this;
@@ -81,6 +88,11 @@ String keystore() {
8188
return keystore;
8289
}
8390

91+
/**
92+
* Sets the password to access the keystore. The password can be loaded from a file by using the <code>file:</code>
93+
* prefix followed by the path of the file, or from an environment variable by using the <code>env:</code> prefix
94+
* followed by the name of the variable.
95+
*/
8496
public KeyStoreBuilder storepass(String storepass) {
8597
this.storepass = storepass;
8698
return this;
@@ -91,11 +103,20 @@ String storepass() {
91103
return storepass;
92104
}
93105

106+
/**
107+
* Sets the type of the keystore.
108+
*/
94109
public KeyStoreBuilder storetype(KeyStoreType storetype) {
95110
this.storetype = storetype;
96111
return this;
97112
}
98113

114+
/**
115+
* Sets the type of the keystore.
116+
*
117+
* @param storetype the type of the keystore
118+
* @throws IllegalArgumentException if the type is not recognized
119+
*/
99120
public KeyStoreBuilder storetype(String storetype) {
100121
try {
101122
this.storetype = storetype != null ? KeyStoreType.valueOf(storetype) : null;
@@ -124,6 +145,11 @@ KeyStoreType storetype() {
124145
return storetype;
125146
}
126147

148+
/**
149+
* Sets the password to access the private key. The password can be loaded from a file by using the <code>file:</code>
150+
* prefix followed by the path of the file, or from an environment variable by using the <code>env:</code> prefix
151+
* followed by the name of the variable.
152+
*/
127153
public KeyStoreBuilder keypass(String keypass) {
128154
this.keypass = keypass;
129155
return this;
@@ -134,10 +160,16 @@ String keypass() throws SignerException {
134160
return keypass;
135161
}
136162

163+
/**
164+
* Sets the file containing the private key.
165+
*/
137166
public KeyStoreBuilder keyfile(String keyfile) {
138167
return keyfile(createFile(keyfile));
139168
}
140169

170+
/**
171+
* Sets the file containing the private key.
172+
*/
141173
public KeyStoreBuilder keyfile(File keyfile) {
142174
this.keyfile = keyfile;
143175
return this;
@@ -147,10 +179,18 @@ File keyfile() {
147179
return keyfile;
148180
}
149181

182+
/**
183+
* Sets the file containing the certificate chain.
184+
* The certificate used for signing must be the first one.
185+
*/
150186
public KeyStoreBuilder certfile(String certfile) {
151187
return certfile(createFile(certfile));
152188
}
153189

190+
/**
191+
* Sets the file containing the certificate chain.
192+
* The certificate used for signing must be the first one.
193+
*/
154194
public KeyStoreBuilder certfile(File certfile) {
155195
this.certfile = certfile;
156196
return this;
@@ -234,6 +274,9 @@ public Provider provider() {
234274

235275
/**
236276
* Builds the keystore.
277+
*
278+
* @throws IllegalArgumentException if the parameters are invalid
279+
* @throws KeyStoreException if the keystore can't be loaded
237280
*/
238281
public KeyStore build() throws KeyStoreException {
239282
validate();

jsign-core/src/main/java/net/jsign/KeyStoreType.java

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ void validate(KeyStoreBuilder params) {
134134
}
135135
},
136136

137-
/** PKCS#11 hardware token */
137+
/**
138+
* PKCS#11 hardware token. The keystore parameter specifies either the name of the provider defined
139+
* in <code>jre/lib/security/java.security</code> or the path to the
140+
* <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/p11guide.html#Config">SunPKCS11 configuration file</a>.
141+
*/
138142
PKCS11(false, true, true) {
139143
@Override
140144
void validate(KeyStoreBuilder params) {
@@ -160,7 +164,13 @@ Provider getProvider(KeyStoreBuilder params) {
160164
}
161165
},
162166

163-
/** OpenPGP card */
167+
/**
168+
* OpenPGP card. OpenPGP cards contain up to 3 keys, one for signing, one for encryption, and one for authentication.
169+
* All of them can be used for code signing (except encryption keys based on an elliptic curve). The alias
170+
* to select the key is either, <code>SIGNATURE</code>, <code>ENCRYPTION</code> or <code>AUTHENTICATION</code>.
171+
* This keystore can be used with a Nitrokey (non-HSM models) or a Yubikey. It doesn't require any external library
172+
* to be installed.
173+
*/
164174
OPENPGP(false, false, false) {
165175
@Override
166176
void validate(KeyStoreBuilder params) {
@@ -186,23 +196,36 @@ Provider getProvider(KeyStoreBuilder params) {
186196
}
187197
},
188198

189-
/** OpenSC supported smart card */
199+
/**
200+
* OpenSC supported smart card.
201+
* This keystore requires the installation of <a href="https://github.com/OpenSC/OpenSC">OpenSC</a>.
202+
* If multiple devices are connected, the keystore parameter can be used to specify the name of the one to use.
203+
*/
190204
OPENSC(false, true, true) {
191205
@Override
192206
Provider getProvider(KeyStoreBuilder params) {
193207
return OpenSC.getProvider(params.keystore());
194208
}
195209
},
196210

197-
/** Nitrokey HSM */
211+
/**
212+
* Nitrokey HSM. This keystore requires the installation of <a href="https://github.com/OpenSC/OpenSC">OpenSC</a>.
213+
* Other Nitrokeys based on the OpenPGP card standard are also supported with this storetype, but an X.509
214+
* certificate must be imported into the Nitrokey (using the gnupg writecert command). Keys without certificates
215+
* are ignored. Otherwise the {@link #OPENPGP} type should be used.
216+
*/
198217
NITROKEY(false, true, true) {
199218
@Override
200219
Provider getProvider(KeyStoreBuilder params) {
201220
return OpenSC.getProvider(params.keystore() != null ? params.keystore() : "Nitrokey");
202221
}
203222
},
204223

205-
/** YubiKey PIV */
224+
/**
225+
* YubiKey PIV. This keystore requires the ykcs11 library from the <a href="https://developers.yubico.com/yubico-piv-tool/">Yubico PIV Tool</a>
226+
* to be installed at the default location. On Windows, the path to the library must be specified in the
227+
* <code>PATH</code> environment variable.
228+
*/
206229
YUBIKEY(false, true, true) {
207230
@Override
208231
Provider getProvider(KeyStoreBuilder params) {
@@ -218,7 +241,18 @@ Set<String> getAliases(KeyStore keystore) throws KeyStoreException {
218241
}
219242
},
220243

221-
/** AWS KMS */
244+
/**
245+
* AWS Key Management Service (KMS). AWS KMS stores only the private key, the certificate must be provided
246+
* separately. The keystore parameter references the AWS region.
247+
*
248+
* <p>The AWS access key, secret key, and optionally the session token, are concatenated and used as
249+
* the storepass parameter; if the latter is not provided, Jsign attempts to fetch the credentials from
250+
* the environment variables (<code>AWS_ACCESS_KEY_ID</code>, <code>AWS_SECRET_ACCESS_KEY</code> and
251+
* <code>AWS_SESSION_TOKEN</code>) or from the IMDSv2 service when running on an AWS EC2 instance.</p>
252+
*
253+
* <p>In any case, the credentials must allow the following actions: <code>kms:ListKeys</code>,
254+
* <code>kms:DescribeKey</code> and <code>kms:Sign</code>.</p>
255+
* */
222256
AWS(false, false, false) {
223257
@Override
224258
void validate(KeyStoreBuilder params) {
@@ -257,7 +291,11 @@ Provider getProvider(KeyStoreBuilder params) {
257291
}
258292
},
259293

260-
/** Azure Key Vault */
294+
/**
295+
* Azure Key Vault. The keystore parameter specifies the name of the key vault, either the short name
296+
* (e.g. <code>myvault</code>), or the full URL (e.g. <code>https://myvault.vault.azure.net</code>).
297+
* The Azure API access token is used as the keystore password.
298+
*/
261299
AZUREKEYVAULT(false, true, false) {
262300
@Override
263301
void validate(KeyStoreBuilder params) {
@@ -275,7 +313,11 @@ Provider getProvider(KeyStoreBuilder params) {
275313
}
276314
},
277315

278-
/** DigiCert ONE */
316+
/**
317+
* DigiCert ONE. Certificates and keys stored in the DigiCert ONE Secure Software Manager can be used directly
318+
* without installing the DigiCert client tools. The API key, the PKCS#12 keystore holding the client certificate
319+
* and its password are combined to form the storepass parameter: <code>&lt;api-key&gt;|&lt;keystore&gt;|&lt;password&gt;</code>.
320+
*/
279321
DIGICERTONE(false, true, false) {
280322
@Override
281323
void validate(KeyStoreBuilder params) {
@@ -291,7 +333,10 @@ Provider getProvider(KeyStoreBuilder params) {
291333
}
292334
},
293335

294-
/** SSL.com eSigner */
336+
/**
337+
* SSL.com eSigner. The SSL.com username and password are used as the keystore password (<code>&lt;username&gt;|&lt;password&gt;</code>),
338+
* and the base64 encoded TOTP secret is used as the key password.
339+
*/
295340
ESIGNER(false, true, false) {
296341
@Override
297342
void validate(KeyStoreBuilder params) {
@@ -317,7 +362,11 @@ boolean reuseKeyStorePassword() {
317362
}
318363
},
319364

320-
/** Google Cloud KMS */
365+
/**
366+
* Google Cloud KMS. Google Cloud KMS stores only the private key, the certificate must be provided separately.
367+
* The keystore parameter references the path of the keyring. The alias can specify either the full path of the key,
368+
* or only the short name. If the version is omitted the most recent one will be picked automatically.
369+
*/
321370
GOOGLECLOUD(false, false, false) {
322371
@Override
323372
void validate(KeyStoreBuilder params) {
@@ -344,7 +393,12 @@ Provider getProvider(KeyStoreBuilder params) {
344393
}
345394
},
346395

347-
/** HashiCorp Vault secrets engine (GCP only) */
396+
/**
397+
* HashiCorp Vault secrets engine (GCP only). Since Google Cloud KMS stores only the private key, the certificate
398+
* must be provided separately. The keystore parameter references the URL of the HashiCorp Vault secrets engine
399+
* (<code>https://vault.example.com/v1/gcpkms</code>). The alias specifies the name of the key in Vault and the key version
400+
* in Google Cloud separated by a colon character (<code>mykey:1</code>).
401+
*/
348402
HASHICORPVAULT(false, false, false) {
349403
@Override
350404
void validate(KeyStoreBuilder params) {

jsign-core/src/main/java/net/jsign/asn1/authenticode/AuthenticodeTimeStampRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* <pre>
2929
* TimeStampRequest ::= SEQUENCE {
30-
* countersignatureType OBJECT IDENTIFIER,
30+
* countersignatureType OBJECT IDENTIFIER, // 1.3.6.1.4.1.311.3.2.1
3131
* attributes Attributes OPTIONAL,
3232
* content ContentInfo
3333
* }

jsign-core/src/main/java/net/jsign/cat/CatalogFile.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public class CatalogFile implements Signable {
5858
*
5959
* @param file the file to check
6060
* @return <code>true</code> if the file is a Windows catalog, <code>false</code> otherwise
61-
* @throws IOException if an I/O error occurs
6261
*/
6362
public static boolean isCatalogFile(File file) {
6463
if (!file.exists() || !file.isFile()) {

jsign-core/src/main/java/net/jsign/jca/DigiCertOneSigningService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public String getName() {
9898
/**
9999
* Returns the certificate details
100100
*
101-
* @param alias the id of alias of the certificate
101+
* @param alias the id or alias of the certificate
102102
*/
103103
private Map<String, ?> getCertificateInfo(String alias) throws IOException {
104104
if (!certificates.containsKey(alias)) {

jsign-core/src/main/java/net/jsign/jca/HashiCorpVaultSigningService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import net.jsign.DigestAlgorithm;
3434

3535
/**
36-
* Signing service using the HashiCorp Vault API.
36+
* Signing service using the HashiCorp Vault API. It supports the Google Cloud KMS secrets engine only.
3737
*
3838
* @see <a href="https://developer.hashicorp.com/vault/api-docs/secret/gcpkms">HashiCorp Vault API - Google Cloud KMS Secrets Engine</a>
3939
* @since 5.0

jsign-core/src/main/java/net/jsign/jca/OpenPGPCard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private ResponseAPDU transmit(CommandAPDU command) throws CardException {
393393
}
394394

395395
/**
396-
* Get the OpenPGP card matching the specified name.
396+
* Get the OpenPGP card.
397397
*/
398398
public static OpenPGPCard getCard() throws CardException {
399399
killSmartCardDaemon();

jsign-core/src/main/java/net/jsign/jca/SigningServiceJcaProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
/**
2727
* JCA Provider using a signing service.
2828
*
29+
* <p>Example:</p>
30+
* <pre>
31+
* Provider provider = new SigningServiceJcaProvider(new AzureKeyVaultSigningService(vault, token));
32+
* KeyStore keystore = KeyStore.getInstance("AZUREKEYVAULT", provider);
33+
* </pre>
34+
*
2935
* @since 4.0
3036
*/
3137
public class SigningServiceJcaProvider extends Provider {

0 commit comments

Comments
 (0)