📄 sesecuritymanagerimpl.java
字号:
TrustManager trustAllCerts[] = {
new X509TrustManager() {
final SESecurityManagerImpl this$0;
public X509Certificate[] getAcceptedIssuers()
{
return null;
}
public void checkClientTrusted(X509Certificate ax509certificate[], String s)
{
}
public void checkServerTrusted(X509Certificate ax509certificate[], String s)
{
}
{
this$0 = SESecurityManagerImpl.this;
super();
}
}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, RandomUtils.SECURE_RANDOM);
SSLSocketFactory factory = sc.getSocketFactory();
socket = (SSLSocket)factory.createSocket(host, port);
socket.startHandshake();
serverCerts = socket.getSession().getPeerCertificates();
if (serverCerts.length != 0)
break MISSING_BLOCK_LABEL_139;
cert = null;
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
this_mon.exit();
return cert;
X509Certificate x509_cert;
String resource;
String alias;
SSLSocketFactory sslsocketfactory1;
cert = serverCerts[0];
if (cert instanceof X509Certificate)
{
x509_cert = (X509Certificate)cert;
} else
{
CertificateFactory cf = CertificateFactory.getInstance("X.509");
x509_cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(cert.getEncoded()));
}
resource = https_url.toString();
int param_pos = resource.indexOf("?");
if (param_pos != -1)
resource = resource.substring(0, param_pos);
String url_s = (new StringBuilder()).append(https_url.getProtocol()).append("://").append(https_url.getHost()).append(":").append(https_url.getPort()).append("/").toString();
Object handler[] = (Object[])(Object[])certificate_handlers.get(url_s);
alias = host.concat(":").concat(String.valueOf(port));
KeyStore keystore = getTrustStore();
byte new_encoded[] = x509_cert.getEncoded();
int count = 0;
do
{
if (count >= 256)
break;
String test_alias = count != 0 ? (new StringBuilder()).append(alias).append(".").append(count).toString() : alias;
Certificate existing = keystore.getCertificate(test_alias);
if (existing != null)
{
if (Arrays.equals(new_encoded, existing.getEncoded()))
{
alias = test_alias;
break;
}
} else
{
alias = test_alias;
break;
}
count++;
} while (true);
if (handler == null || !((SECertificateListener)handler[0]).trustCertificate(resource, x509_cert))
break MISSING_BLOCK_LABEL_478;
sslsocketfactory1 = addCertToTrustStore(alias, cert, true);
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
this_mon.exit();
return sslsocketfactory1;
int i = 0;
_L1:
SSLSocketFactory sslsocketfactory2;
if (i >= certificate_listeners.size())
break MISSING_BLOCK_LABEL_568;
if (!((SECertificateListener)certificate_listeners.get(i)).trustCertificate(resource, x509_cert))
break MISSING_BLOCK_LABEL_562;
sslsocketfactory2 = addCertToTrustStore(alias, cert, true);
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
this_mon.exit();
return sslsocketfactory2;
i++;
goto _L1
i = null;
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
this_mon.exit();
return i;
Throwable e;
e;
SSLSocketFactory sslsocketfactory;
Debug.printStackTrace(e);
sslsocketfactory = null;
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
this_mon.exit();
return sslsocketfactory;
Exception exception;
exception;
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
throw exception;
Exception exception1;
exception1;
this_mon.exit();
throw exception1;
}
public SSLSocketFactory installServerCertificates(String alias, String host, int port)
{
SSLSocket socket;
this_mon.enter();
socket = null;
Certificate serverCerts[];
SSLSocketFactory sslsocketfactory1;
TrustManager trustAllCerts[] = {
new X509TrustManager() {
final SESecurityManagerImpl this$0;
public X509Certificate[] getAcceptedIssuers()
{
return null;
}
public void checkClientTrusted(X509Certificate ax509certificate[], String s)
{
}
public void checkServerTrusted(X509Certificate ax509certificate[], String s)
{
}
{
this$0 = SESecurityManagerImpl.this;
super();
}
}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, RandomUtils.SECURE_RANDOM);
SSLSocketFactory factory = sc.getSocketFactory();
socket = (SSLSocket)factory.createSocket(host, port);
socket.startHandshake();
serverCerts = socket.getSession().getPeerCertificates();
if (serverCerts.length != 0)
break MISSING_BLOCK_LABEL_120;
sslsocketfactory1 = null;
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
this_mon.exit();
return sslsocketfactory1;
SSLSocketFactory sslsocketfactory2;
Certificate cert = serverCerts[0];
X509Certificate x509_cert;
if (cert instanceof X509Certificate)
{
x509_cert = (X509Certificate)cert;
} else
{
CertificateFactory cf = CertificateFactory.getInstance("X.509");
x509_cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(cert.getEncoded()));
}
sslsocketfactory2 = addCertToTrustStore(alias, cert, false);
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
this_mon.exit();
return sslsocketfactory2;
Throwable e;
e;
SSLSocketFactory sslsocketfactory;
Debug.printStackTrace(e);
sslsocketfactory = null;
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
this_mon.exit();
return sslsocketfactory;
Exception exception;
exception;
if (socket != null)
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
throw exception;
Exception exception1;
exception1;
this_mon.exit();
throw exception1;
}
protected void addCertToKeyStore(String alias, Key public_key, Certificate certChain[])
throws Exception
{
KeyStore key_store;
FileOutputStream out;
this_mon.enter();
key_store = loadKeyStore();
if (key_store.containsAlias(alias))
key_store.deleteEntry(alias);
key_store.setKeyEntry(alias, public_key, "changeit".toCharArray(), certChain);
out = null;
out = new FileOutputStream(keystore_name);
key_store.store(out, "changeit".toCharArray());
if (out != null)
out.close();
break MISSING_BLOCK_LABEL_117;
Throwable e;
e;
Debug.printStackTrace(e);
if (out != null)
out.close();
break MISSING_BLOCK_LABEL_117;
Exception exception;
exception;
if (out != null)
out.close();
throw exception;
this_mon.exit();
break MISSING_BLOCK_LABEL_139;
Exception exception1;
exception1;
this_mon.exit();
throw exception1;
}
protected SSLSocketFactory addCertToTrustStore(String alias, Certificate cert, boolean update_https_factory)
throws Exception
{
KeyStore keystore;
FileOutputStream out;
this_mon.enter();
keystore = getTrustStore();
if (cert == null)
break MISSING_BLOCK_LABEL_95;
if (keystore.containsAlias(alias))
keystore.deleteEntry(alias);
keystore.setCertificateEntry(alias, cert);
out = null;
out = new FileOutputStream(truststore_name);
keystore.store(out, "changeit".toCharArray());
if (out != null)
out.close();
break MISSING_BLOCK_LABEL_95;
Exception exception;
exception;
if (out != null)
out.close();
throw exception;
SSLSocketFactory sslsocketfactory;
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keystore);
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, tmf.getTrustManagers(), null);
SSLSocketFactory factory = ctx.getSocketFactory();
if (update_https_factory)
HttpsURLConnection.setDefaultSSLSocketFactory(factory);
sslsocketfactory = factory;
this_mon.exit();
return sslsocketfactory;
Exception exception1;
exception1;
this_mon.exit();
throw exception1;
}
public PasswordAuthentication getPasswordAuthentication(String realm, URL tracker)
{
Object handler[];
SEPasswordListener thread_listener = (SEPasswordListener)tls.get();
if (thread_listener != null)
return thread_listener.getAuthentication(realm, tracker);
handler = (Object[])(Object[])password_handlers.get(tracker.toString());
if (handler == null)
break MISSING_BLOCK_LABEL_77;
return ((SEPasswordListener)handler[0]).getAuthentication(realm, (URL)handler[1]);
Throwable e;
e;
Debug.printStackTrace(e);
Iterator it = password_listeners.iterator();
_L2:
if (!it.hasNext())
break; /* Loop/switch isn't completed */
PasswordAuthentication res = ((SEPasswordListener)it.next()).getAuthentication(realm, tracker);
if (res != null)
return res;
continue; /* Loop/switch isn't completed */
Throwable e;
e;
Debug.printStackTrace(e);
if (true) goto _L2; else goto _L1
_L1:
return null;
}
public void setPasswordAuthenticationOutcome(String realm, URL tracker, boolean success)
{
SEPasswordListener thread_listener = (SEPasswordListener)tls.get();
if (thread_listener != null)
thread_listener.setAuthenticationOutcome(realm, tracker, success);
for (Iterator it = password_listeners.iterator(); it.hasNext(); ((SEPasswordListener)it.next()).setAuthenticationOutcome(realm, tracker, success));
}
public void addPasswordListener(SEPasswordListener l)
{
this_mon.enter();
password_listeners.add(l);
this_mon.exit();
break MISSING_BLOCK_LABEL_35;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public void removePasswordListener(SEPasswordListener l)
{
this_mon.enter();
password_listeners.remove(l);
this_mon.exit();
break MISSING_BLOCK_LABEL_36;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public void clearPasswords()
{
SEPasswordListener thread_listener = (SEPasswordListener)tls.get();
if (thread_listener != null)
thread_listener.clearPasswords();
for (Iterator it = password_listeners.iterator(); it.hasNext();)
try
{
((SEPasswordListener)it.next()).clearPasswords();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public void setThreadPasswordHandler(SEPasswordListener l)
{
tls.set(l);
}
public void unsetThreadPasswordHandler()
{
tls.set(null);
}
public void setPasswordHandler(URL url, SEPasswordListener l)
{
String url_s = (new StringBuilder()).append(url.getProtocol()).append("://").append(url.getHost()).append(":").append(url.getPort()).append("/").toString();
if (l == null)
password_handlers.remove(url_s);
else
password_handlers.put(url_s, ((Object) (new Object[] {
l, url
})));
}
public void addCertificateListener(SECertificateListener l)
{
this_mon.enter();
certificate_listeners.add(l);
this_mon.exit();
break MISSING_BLOCK_LABEL_38;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public void setCertificateHandler(URL url, SECertificateListener l)
{
String url_s = (new StringBuilder()).append(url.getProtocol()).append("://").append(url.getHost()).append(":").append(url.getPort()).append("/").toString();
if (l == null)
certificate_handlers.remove(url_s);
else
certificate_handlers.put(url_s, ((Object) (new Object[] {
l, url
})));
}
public void removeCertificateListener(SECertificateListener l)
{
this_mon.enter();
certificate_listeners.remove(l);
this_mon.exit();
break MISSING_BLOCK_LABEL_38;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public static void main(String args[])
{
SESecurityManagerImpl man = getSingleton();
man.initialise();
try
{
man.createSelfSignedCertificate("SomeAlias", "CN=fred,OU=wap,O=wip,L=here,ST=there,C=GB", 1000);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
static
{
LOGID = LogIDs.NET;
String types[] = {
"JKS", "GKR"
};
int i = 0;
do
{
if (i >= types.length)
break;
try
{
KeyStore.getInstance(types[i]);
KEYSTORE_TYPE = types[i];
break;
}
catch (Throwable e)
{
i++;
}
} while (true);
if (KEYSTORE_TYPE == null)
KEYSTORE_TYPE = "JKS";
Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("Keystore type is ").append(KEYSTORE_TYPE).toString()));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -