[utilities COMMIT] /java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertifi...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Jul 9 23:03:07 EDT 2014
Author: scantor
Date: Wed Jul 9 23:03:07 2014
New Revision: 619
URL: http://svn.shibboleth.net/view/utilities?rev=619&view=rev
Log:
IDP-410: cleaned up, added more command line options
Modified:
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java
Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java?rev=619&r1=618&r2=619&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java Wed Jul 9 23:03:07 2014
@@ -22,7 +22,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
-import java.nio.file.Files;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
@@ -30,11 +29,18 @@
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.GregorianCalendar;
+import java.util.List;
import javax.annotation.Nonnull;
-
+import javax.annotation.Nullable;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.annotation.constraint.Positive;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
@@ -55,57 +61,23 @@
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
+import com.beust.jcommander.converters.BaseConverter;
+import com.google.common.collect.Lists;
/**
* A helper class to generate self-signed keypairs.
*/
public class SelfSignedCertificateGenerator {
- /** Command line argument container. */
- private static final CommandLineArgs COMMAND_LINE_ARGS = new CommandLineArgs();
-
/** Class logger. */
@Nonnull private Logger log = LoggerFactory.getLogger(SelfSignedCertificateGenerator.class);
-
- /** Type of key to generated. */
- @Nonnull @NotEmpty private String keyType;
-
- /** Size of the generated key. */
- private int keySize;
-
- /** Number of years before the self-signed certificate expires. */
- private int certificateLifetime;
-
- /** Hostname that will appear as the certifcate's DN common name component. */
- private String hostname;
-
- /** Optional DNS subject alt names. */
- private String[] dnsSubjectAltNames;
-
- /** Optional DNS subject alt names. */
- private String[] uriSubjectAltNames;
-
- /** File to which the public key will be written. */
- private File privateKeyFile;
-
- /** File to which the certificate will be written. */
- private File certificateFile;
-
- /** Type of keystore to create. */
- private String keystoreType;
-
- /** File to which the keystore will be written. */
- private File keystoreFile;
-
- /** Password for the generated keystore. */
- private String keystorePassword;
-
+
+ /** Container for options that can be parsed from a command line. */
+ @Nonnull private final CommandLineArgs args;
+
/** Constructor. */
public SelfSignedCertificateGenerator() {
- keyType = "RSA";
- keySize = 2048;
- certificateLifetime = 20;
- keystoreType = "PKCS12";
+ args = new CommandLineArgs();
}
/**
@@ -113,8 +85,8 @@
*
* @param type type of key that will be generated
*/
- public void setKeyType(String type) {
- keyType = type;
+ public void setKeyType(@Nonnull @NotEmpty final String type) {
+ args.keyType = Constraint.isNotNull(StringSupport.trimOrNull(type), "Key type cannot be null or empty");
}
/**
@@ -122,8 +94,10 @@
*
* @param size size of the generated key
*/
- public void setKeySize(int size) {
- keySize = size;
+ public void setKeySize(@Positive final int size) {
+ Constraint.isGreaterThan(0, size, "Key size must be greater than 0");
+
+ args.keySize = size;
}
/**
@@ -131,8 +105,10 @@
*
* @param lifetime number of years for which the certificate will be valid
*/
- public void setCertificateLifetime(int lifetime) {
- certificateLifetime = lifetime;
+ public void setCertificateLifetime(@Positive final int lifetime) {
+ Constraint.isGreaterThan(0, lifetime, "Certificate lifetime must be greater than 0");
+
+ args.certificateLifetime = lifetime;
[... 464 lines stripped ...]
More information about the commits
mailing list