[java-idp-jetty-base] 02/02: IDP-2333 Generate idp-userfacing.p12 on initial module enable

Rod Widdowson rdw at steadingsoftware.com
Fri Oct 11 13:18:36 UTC 2024


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch dev/IDP-2297
in repository java-idp-jetty-base.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-jetty-base.git;a=commit;h=e0719228194ec28d4883809d8ab6edabdd8eb77c

commit e0719228194ec28d4883809d8ab6edabdd8eb77c
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Oct 11 13:29:13 2024 +0100

    IDP-2333 Generate idp-userfacing.p12 on initial module enable
    
    https://shibboleth.atlassian.net/browse/IDP-2333
---
 jetty-base-impl/pom.xml                            |  13 +++++++++
 .../idp/plugin/jettybase/JettyBaseModule.java      |  31 +++++++++++++++++++++
 .../module/credentials/idp-userfacing.p12          | Bin 3448 -> 0 bytes
 pom.xml                                            |   1 +
 4 files changed, 45 insertions(+)

diff --git a/jetty-base-impl/pom.xml b/jetty-base-impl/pom.xml
index 8b693c2..d5a814d 100644
--- a/jetty-base-impl/pom.xml
+++ b/jetty-base-impl/pom.xml
@@ -22,6 +22,19 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>${shib-shared.groupId}</groupId>
+            <artifactId>shib-security</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>${idp.groupId}</groupId>
+            <artifactId>idp-installer</artifactId>
+            <version>${idp.version}</version>
+            <scope>provided</scope>
+        </dependency>
+
         <dependency>
             <groupId>${shib-profile.groupId}</groupId>
             <artifactId>shib-profile-api</artifactId>
diff --git a/jetty-base-impl/src/main/java/net/shibboleth/idp/plugin/jettybase/JettyBaseModule.java b/jetty-base-impl/src/main/java/net/shibboleth/idp/plugin/jettybase/JettyBaseModule.java
index ff0ba34..c462ffe 100644
--- a/jetty-base-impl/src/main/java/net/shibboleth/idp/plugin/jettybase/JettyBaseModule.java
+++ b/jetty-base-impl/src/main/java/net/shibboleth/idp/plugin/jettybase/JettyBaseModule.java
@@ -26,10 +26,14 @@ import org.apache.commons.lang3.SystemUtils;
 import org.slf4j.Logger;
 
 import net.shibboleth.idp.Version;
+import net.shibboleth.idp.installer.InstallerSupport;
+import net.shibboleth.idp.installer.impl.InstallerProperties;
 import net.shibboleth.idp.module.impl.PluginIdPModule;
 import net.shibboleth.profile.module.ModuleContext;
 import net.shibboleth.profile.module.ModuleException;
+import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.security.impl.SelfSignedCertificateGenerator;
 
 public class JettyBaseModule extends PluginIdPModule {
 
@@ -57,6 +61,10 @@ public class JettyBaseModule extends PluginIdPModule {
             log.error("Create Directory failed", e);
             throw new ModuleException(e);
         }
+        final Path keystore= idpHome.resolve("credentials").resolve("idp-userfacing.p12");
+        if (!Files.exists(keystore)) {
+            generateKeystore(keystore);
+        }
         if (SystemUtils.IS_OS_WINDOWS) {
             final File jettyHelper = idpHome.resolve("jetty-base").resolve("jetty.base.linux").toFile();
             if (!jettyHelper.exists()) {
@@ -75,4 +83,27 @@ public class JettyBaseModule extends PluginIdPModule {
 
         return result;
     }
+
+    /** Generate an mock idp-userfacing.p12 keystore.
+     * @param keystore where to put it
+     * @throws ModuleException if the generator fails
+     */
+    private void generateKeystore(Path keyStore) throws ModuleException {
+        final SelfSignedCertificateGenerator generator = new SelfSignedCertificateGenerator();
+        generator.setKeystoreFile(keyStore.toFile());
+        generator.setKeySize(InstallerProperties.DEFAULT_KEY_SIZE);
+        final String hostName = InstallerSupport.getBestHostName();
+        generator.setHostName(hostName);
+        final String altName = "https://" + hostName + "/idp/shibboleth";
+        generator.setURISubjectAltNames(CollectionSupport.singletonList(altName));
+        generator.setKeystorePassword("changeit");
+        log.info("Creating {}, CN = {} URI = {}, keySize={}",
+                keyStore, hostName, altName, InstallerProperties.DEFAULT_KEY_SIZE);
+        try {
+          generator.generate();
+      } catch (final Exception e) {
+          log.error("Error building ketstore files {}", keyStore, e);
+          throw new ModuleException("Error Key Store", e);
+      }
+    }
 }
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/plugin/jettybase/module/credentials/idp-userfacing.p12 b/jetty-base-impl/src/main/resources/net/shibboleth/idp/plugin/jettybase/module/credentials/idp-userfacing.p12
deleted file mode 100644
index 7acc8f0..0000000
Binary files a/jetty-base-impl/src/main/resources/net/shibboleth/idp/plugin/jettybase/module/credentials/idp-userfacing.p12 and /dev/null differ
diff --git a/pom.xml b/pom.xml
index 011ada6..e6f665f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,6 +19,7 @@
     <properties>
         <idp.groupId>net.shibboleth.idp</idp.groupId>
         <idp.version>5.2.0-SNAPSHOT</idp.version>
+        <shib-shared.groupId>net.shibboleth</shib-shared.groupId>
 
         <shib-profile.groupId>net.shibboleth</shib-profile.groupId>
         <shib-profile.version>5.2.0-SNAPSHOT</shib-profile.version>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list