
org.webpieces.plugin.secure.sslcert.WebSSLFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin-install-sslcert Show documentation
Show all versions of plugin-install-sslcert Show documentation
plugin for wizard to install an ssl cert
The newest version!
package org.webpieces.plugin.secure.sslcert;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.security.KeyManagementException;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import org.jose4j.base64url.Base64;
import org.shredzone.acme4j.util.KeyPairUtils;
import org.webpieces.nio.api.SSLEngineFactory;
import org.webpieces.router.api.extensions.NeedsSimpleStorage;
import org.webpieces.router.api.extensions.SimpleStorage;
import org.webpieces.util.exceptions.SneakyThrow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WebSSLFactory implements SSLEngineFactory, NeedsSimpleStorage {
private static final Logger log = LoggerFactory.getLogger(WebSSLFactory.class);
private String serverKeystore = "/keystore.jks";
private String password = "password";
private char[] passphrase = password.toCharArray();
private SimpleStorage storage;
private KeyPair accountKeyPair;
private X509Certificate[] certChain;
@Inject
public WebSSLFactory(SimpleStorage storage) {
//since this bites a lot of people, let's read in the keystor early
try(InputStream keySt = WebSSLFactory.class.getResourceAsStream(serverKeystore)) {
if(keySt == null)
throw new IllegalStateException("keystore was not found");
} catch(IOException e) {
throw SneakyThrow.sneak(e);
}
}
//NOTE: In development MODE, this may be called a few times to pass in the newly compiled one each time
//in production, this is called ONCE. This was a definite workaround due to class loading and dependencies since
//the main system in this case wants to read the certs from storage (so the cert is in ONE place instead of on
//N machines in your cluster, it will be read from storage that you lock down).
@Override
public CompletableFuture init(SimpleStorage storage) {
log.info("intializing storage="+storage);
this.storage = storage;
CompletableFuture
© 2015 - 2025 Weber Informatics LLC | Privacy Policy