/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.dev.security; import java.security.Key; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; import java.util.Enumeration; import org.h2.security.CipherFactory; import org.h2.util.StringUtils; /** * Tool to generate source code for the SecureSocketFactory. First, create a * keystore using: *
* keytool -genkey -alias h2 -keyalg RSA -dname "cn=H2" * -validity 25000 -keypass h2pass -keystore h2.keystore * -storepass h2pass ** Then run this application to generate the source code. Then replace the code * in the function SecureSocketFactory.getKeyStore as specified */ public class SecureKeyStoreBuilder { private SecureKeyStoreBuilder() { // utility class } /** * This method is called when executing this application from the command * line. * * @param args the command line parameters */ public static void main(String... args) throws Exception { String password = CipherFactory.KEYSTORE_PASSWORD; KeyStore store = CipherFactory.getKeyStore(password); printKeystore(store, password); } private static void printKeystore(KeyStore store, String password) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, CertificateEncodingException { System.out.println("KeyStore store = KeyStore.getInstance(\"" + store.getType() + "\");"); System.out.println("store.load(null, password.toCharArray());"); // System.out.println("keystore provider=" + // store.getProvider().getName()); Enumeration