gnodet commented on code in PR #22194:
URL: https://github.com/apache/camel/pull/22194#discussion_r2993622971


##########
core/camel-main/src/main/java/org/apache/camel/main/SelfSignedCertificateGenerator.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.main;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+
+/**
+ * Generates a self-signed certificate for development use. This allows 
enabling HTTPS with minimal configuration when
+ * no keystore is provided.
+ *
+ * The generated certificate is NOT suitable for production use.
+ */
+final class SelfSignedCertificateGenerator {
+
+    private SelfSignedCertificateGenerator() {
+    }
+
+    /**
+     * Generates a PKCS12 KeyStore containing a self-signed certificate with 
Subject Alternative Names for localhost and
+     * 127.0.0.1.
+     *
+     * @param  password  the password for the keystore and key entry
+     * @return           a KeyStore containing the self-signed certificate
+     * @throws Exception if certificate generation fails
+     */
+    static KeyStore generateKeyStore(String password) throws Exception {
+        SecureRandom random = new SecureRandom();
+        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
+        keyGen.initialize(2048, random);
+        KeyPair keyPair = keyGen.generateKeyPair();
+
+        X509Certificate cert = generateCertificate(keyPair, random);
+
+        KeyStore ks = KeyStore.getInstance("PKCS12");

Review Comment:
   PKCS12 is the default keystore type since JDK 9 and is provided by the 
built-in SunJSSE provider — if it's unavailable, no SSL functionality would 
work at all. For FIPS environments, self-signed certificates wouldn't be 
appropriate anyway (FIPS is a production/compliance requirement, 
selfSigned=true is explicitly for dev use). If generation does fail for any 
reason, the exception propagates clearly and the context won't start silently 
without SSL.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to