mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-06-25 22:53:22 +00:00
Added version check to certificate addition
This commit is contained in:
parent
e1dffaa334
commit
e4dd4dbef0
|
@ -26,6 +26,7 @@
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.lang.System;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
|
@ -115,28 +116,36 @@ private static TrustManagerFactory getTrustManager()
|
||||||
TrustManagerFactory tmf = null;
|
TrustManagerFactory tmf = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Certificate ca = CertificateFactory.getInstance( "X.509" )
|
String version = System.getProperty( "java.version" );
|
||||||
.generateCertificate( new ByteArrayInputStream( letsEncryptRootCert.getBytes() ) );
|
if ( version.regionMatches( 0, "1.8.0_", 0, 6 ) && version.length() == 8 ) // 1.8.0_xx (xx < 100)
|
||||||
|
|
||||||
KeyStore ks = KeyStore.getInstance( KeyStore.getDefaultType() );
|
|
||||||
ks.load( null, null );
|
|
||||||
ks.setCertificateEntry( Integer.toString( 1 ), ca );
|
|
||||||
|
|
||||||
TrustManagerFactory additional = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
|
|
||||||
additional.init( ks );
|
|
||||||
|
|
||||||
// Get hold of the extension trust manager
|
|
||||||
X509TrustManager x509tm = null;
|
|
||||||
for ( TrustManager tm : additional.getTrustManagers() )
|
|
||||||
{
|
{
|
||||||
if ( tm instanceof X509TrustManager )
|
Certificate ca = CertificateFactory.getInstance( "X.509" )
|
||||||
{
|
.generateCertificate( new ByteArrayInputStream( letsEncryptRootCert.getBytes() ) );
|
||||||
x509tm = (X509TrustManager) tm;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tmf = new MergedTrustManagerFactory( TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() ), x509tm );
|
KeyStore ks = KeyStore.getInstance( KeyStore.getDefaultType() );
|
||||||
|
ks.load( null, null );
|
||||||
|
ks.setCertificateEntry( Integer.toString( 1 ), ca );
|
||||||
|
|
||||||
|
TrustManagerFactory additional = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
|
||||||
|
additional.init( ks );
|
||||||
|
|
||||||
|
// Get hold of the extension trust manager
|
||||||
|
X509TrustManager x509tm = null;
|
||||||
|
for ( TrustManager tm : additional.getTrustManagers() )
|
||||||
|
{
|
||||||
|
if ( tm instanceof X509TrustManager )
|
||||||
|
{
|
||||||
|
x509tm = (X509TrustManager) tm;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tmf = new MergedTrustManagerFactory( TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() ), x509tm );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmf = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() );
|
||||||
|
}
|
||||||
tmf.init( (KeyStore) null );
|
tmf.init( (KeyStore) null );
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
|
|
Loading…
Reference in New Issue
Block a user