diff options
| author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-05-25 21:21:42 +0700 |
|---|---|---|
| committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-05-25 21:21:42 +0700 |
| commit | 60b9f99d260361824424b3f3c866e95f4869c262 (patch) | |
| tree | d9fe06f8af0839fd7b5a9538d776a40be70719fc /src/main/java/cc/polyfrost/oneconfig/network | |
| parent | 368ba3ba0859e00ec245a64c94c1eab1f96d23bd (diff) | |
| download | OneConfig-60b9f99d260361824424b3f3c866e95f4869c262.tar.gz OneConfig-60b9f99d260361824424b3f3c866e95f4869c262.tar.bz2 OneConfig-60b9f99d260361824424b3f3c866e95f4869c262.zip | |
OC-33 OC-35, additions to ColorUtils, and JsonUtils
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/network')
| -rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/network/SSLStore.java | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/network/SSLStore.java b/src/main/java/cc/polyfrost/oneconfig/network/SSLStore.java deleted file mode 100644 index 3b8eed2..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/network/SSLStore.java +++ /dev/null @@ -1,76 +0,0 @@ -package cc.polyfrost.oneconfig.network; - -import javax.net.ssl.KeyManager; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManagerFactory; -import java.io.BufferedInputStream; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.security.KeyStore; -import java.security.SecureRandom; -import java.security.cert.Certificate; -import java.security.cert.CertificateFactory; - -/** - * Adds our certificate to the JavaKeyStore to avoid SSL issues. - */ -public class SSLStore { - private final CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); - private final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); - - public SSLStore() throws Exception { - Path keyStorePath = Paths.get(System.getProperty("java.home"), "lib", "security", "cacerts"); - this.keyStore.load(Files.newInputStream(keyStorePath),(char[])null); - } - - /** - * Loads the specified SSL certificate. - * @param sslFile A .der filename from the resources/assets/oneconfig/ssl directory. - * @throws Exception Uses Exception to cover the SSL loading and generation - */ - public SSLStore load(String sslFile) throws Exception { - InputStream certificateResource = SSLStore.class.getResourceAsStream("/assets/oneconfig/ssl/" + sslFile + ".der"); - Throwable sslThrowable = null; - - // Try to gen and load the certificate - try { - InputStream certStream = new BufferedInputStream(certificateResource); - Certificate generatedCertificate = this.certificateFactory.generateCertificate(certStream); - - this.keyStore.setCertificateEntry(sslFile, generatedCertificate); - } catch (Throwable sslException) { - sslThrowable = sslException; - throw sslException; - } finally { - if (certificateResource != null) { - try { - certificateResource.close(); - } catch (Throwable closeException) { - sslThrowable.addSuppressed(closeException); - } - } else { - certificateResource.close(); - } - } - return this; - } - - /** - * Generates and returns the SSLContext after the new cert has been added with SSLStore.load(). - * @return The SSLContext generated after init. - * @throws Exception Uses Exception to cover the TMF init and SSLContext init. - */ - public SSLContext finish() throws Exception { - // Initialize TrustManagerFactory with the new KeyStore once the new cert has been added - TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - trustManagerFactory.init(this.keyStore); - - // Return the SSLContext after init. - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init((KeyManager[])null, trustManagerFactory.getTrustManagers(), (SecureRandom)null); - - return sslContext; - } -} |
