📄 sesecuritymanagerimpl.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SESecurityManagerImpl.java
package org.gudy.azureus2.core3.security.impl;
import com.aelitis.azureus.core.util.CopyOnWriteList;
import java.io.*;
import java.net.*;
import java.security.*;
import java.security.cert.*;
import java.util.*;
import javax.net.ssl.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.security.*;
import org.gudy.azureus2.core3.util.*;
// Referenced classes of package org.gudy.azureus2.core3.security.impl:
// SESecurityManagerBC
public class SESecurityManagerImpl
{
private static final LogIDs LOGID;
protected static SESecurityManagerImpl singleton = new SESecurityManagerImpl();
protected static String KEYSTORE_TYPE;
protected String keystore_name;
protected String truststore_name;
protected List certificate_listeners;
protected CopyOnWriteList password_listeners;
private static ThreadLocal tls = new ThreadLocal() {
public Object initialValue()
{
return null;
}
};
protected Map password_handlers;
protected Map certificate_handlers;
protected boolean exit_vm_permitted;
protected AEMonitor this_mon;
private boolean initialized;
private List stoppable_threads;
public SESecurityManagerImpl()
{
certificate_listeners = new ArrayList();
password_listeners = new CopyOnWriteList();
password_handlers = new HashMap();
certificate_handlers = new HashMap();
exit_vm_permitted = false;
this_mon = new AEMonitor("SESecurityManager");
initialized = false;
stoppable_threads = new ArrayList();
}
public static SESecurityManagerImpl getSingleton()
{
return singleton;
}
public void initialise()
{
label0:
{
synchronized (this)
{
if (!initialized)
break label0;
}
return;
}
initialized = true;
sesecuritymanagerimpl;
JVM INSTR monitorexit ;
goto _L1
exception;
throw exception;
_L1:
keystore_name = FileUtil.getUserFile(".keystore").getAbsolutePath();
truststore_name = FileUtil.getUserFile(".certs").getAbsolutePath();
System.setProperty("javax.net.ssl.trustStore", truststore_name);
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
installAuthenticator();
String providers[] = {
"com.sun.net.ssl.internal.ssl.Provider", "org.metastatic.jessie.provider.Jessie"
};
String provider = null;
int i = 0;
do
{
if (i >= providers.length)
break;
try
{
Class.forName(providers[i]).newInstance();
provider = providers[i];
break;
}
catch (Throwable e)
{
i++;
}
} while (true);
if (provider == null)
Debug.out("No SSL provider available");
try
{
SESecurityManagerBC.initialise();
}
catch (Throwable e)
{
Logger.log(new LogEvent(LOGID, 3, "Bouncy Castle not available"));
}
installSecurityManager();
ensureStoreExists(keystore_name);
ensureStoreExists(truststore_name);
return;
}
public String getKeystoreName()
{
return keystore_name;
}
public String getKeystorePassword()
{
return "changeit";
}
protected void installSecurityManager()
{
String prop = System.getProperty("azureus.security.manager.install", "1");
if (prop.equals("0"))
{
Debug.outNoStack("Not installing security manager - disabled by system property");
return;
}
try
{
final SecurityManager old_sec_man = System.getSecurityManager();
System.setSecurityManager(new SecurityManager() {
final SecurityManager val$old_sec_man;
final SESecurityManagerImpl this$0;
public void checkAccept(String s, int i)
{
}
public void checkRead(String s)
{
}
public void checkWrite(String s)
{
}
public void checkExit(int status)
{
if (old_sec_man != null)
old_sec_man.checkExit(status);
if (!exit_vm_permitted)
throw new SecurityException("VM exit operation prohibited");
else
return;
}
public void checkPermission(Permission perm)
{
if (!(perm instanceof RuntimePermission) || !perm.getName().equals("stopThread"))
break MISSING_BLOCK_LABEL_70;
List list = stoppable_threads;
JVM INSTR monitorenter ;
if (stoppable_threads.contains(Thread.currentThread()))
return;
break MISSING_BLOCK_LABEL_60;
Exception exception;
exception;
throw exception;
throw new SecurityException("Thread.stop operation prohibited");
if (old_sec_man != null)
old_sec_man.checkPermission(perm);
return;
}
public void checkPermission(Permission perm, Object context)
{
if ((perm instanceof RuntimePermission) && perm.getName().equals("stopThread"))
throw new SecurityException("Thread.stop operation prohibited");
if (old_sec_man != null)
old_sec_man.checkPermission(perm, context);
}
{
this$0 = SESecurityManagerImpl.this;
old_sec_man = securitymanager;
super();
}
});
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public void stopThread(Thread t)
{
synchronized (stoppable_threads)
{
stoppable_threads.add(Thread.currentThread());
}
t.stop();
synchronized (stoppable_threads)
{
stoppable_threads.remove(Thread.currentThread());
}
break MISSING_BLOCK_LABEL_109;
Exception exception2;
exception2;
synchronized (stoppable_threads)
{
stoppable_threads.remove(Thread.currentThread());
}
throw exception2;
}
public void exitVM(int status)
{
exit_vm_permitted = true;
try
{
System.exit(status);
}
catch (Throwable t) { }
exit_vm_permitted = false;
break MISSING_BLOCK_LABEL_29;
Exception exception;
exception;
exit_vm_permitted = false;
throw exception;
}
public void installAuthenticator()
{
Authenticator.setDefault(new Authenticator() {
protected AEMonitor auth_mon;
final SESecurityManagerImpl this$0;
protected PasswordAuthentication getPasswordAuthentication()
{
PasswordAuthentication passwordauthentication;
auth_mon.enter();
PasswordAuthentication res = getAuthentication(getRequestingPrompt(), getRequestingProtocol(), getRequestingHost(), getRequestingPort());
passwordauthentication = res;
auth_mon.exit();
return passwordauthentication;
Exception exception;
exception;
auth_mon.exit();
throw exception;
}
{
this$0 = SESecurityManagerImpl.this;
super();
auth_mon = new AEMonitor("SESecurityManager:auth");
}
});
}
public PasswordAuthentication getAuthentication(String realm, String protocol, String host, int port)
{
if (protocol.toLowerCase().startsWith("socks"))
{
String socks_user = COConfigurationManager.getStringParameter("Proxy.Username").trim();
String socks_pw = COConfigurationManager.getStringParameter("Proxy.Password").trim();
if (socks_user.equalsIgnoreCase("<none>"))
return new PasswordAuthentication("", "".toCharArray());
if (socks_user.length() == 0)
Logger.log(new LogAlert(false, 1, "Socks server is requesting authentication, please setup user and password in config"));
return new PasswordAuthentication(socks_user, socks_pw.toCharArray());
}
URL tracker_url = new URL((new StringBuilder()).append(protocol).append("://").append(host).append(":").append(port).append("/").toString());
return getPasswordAuthentication(realm, tracker_url);
MalformedURLException e;
e;
Debug.printStackTrace(e);
return null;
}
protected boolean checkKeyStoreHasEntry()
{
File f = new File(keystore_name);
if (!f.exists())
{
Logger.logTextResource(new LogAlert(false, 3, "Security.keystore.empty"), new String[] {
keystore_name
});
return false;
}
KeyStore key_store = loadKeyStore();
Enumeration enumx = key_store.aliases();
if (enumx.hasMoreElements())
break MISSING_BLOCK_LABEL_123;
Logger.logTextResource(new LogAlert(false, 3, "Security.keystore.empty"), new String[] {
keystore_name
});
return false;
Throwable e;
e;
Logger.logTextResource(new LogAlert(false, 3, "Security.keystore.corrupt"), new String[] {
keystore_name
});
return false;
return true;
}
protected boolean ensureStoreExists(String name)
{
KeyStore keystore;
FileOutputStream out;
this_mon.enter();
keystore = KeyStore.getInstance(KEYSTORE_TYPE);
if ((new File(name)).exists())
break MISSING_BLOCK_LABEL_92;
keystore.load(null, null);
out = null;
out = new FileOutputStream(name);
keystore.store(out, "changeit".toCharArray());
if (out != null)
out.close();
break MISSING_BLOCK_LABEL_79;
Exception exception;
exception;
if (out != null)
out.close();
throw exception;
boolean flag1 = true;
this_mon.exit();
return flag1;
boolean flag = false;
this_mon.exit();
return flag;
Throwable e;
e;
Debug.printStackTrace(e);
flag = false;
this_mon.exit();
return flag;
Exception exception1;
exception1;
this_mon.exit();
throw exception1;
}
public KeyStore getKeyStore()
throws Exception
{
return loadKeyStore();
}
public KeyStore getTrustStore()
throws Exception
{
KeyStore keystore;
FileInputStream in;
keystore = KeyStore.getInstance(KEYSTORE_TYPE);
if (!(new File(truststore_name)).exists())
{
keystore.load(null, null);
break MISSING_BLOCK_LABEL_79;
}
in = null;
in = new FileInputStream(truststore_name);
keystore.load(in, "changeit".toCharArray());
if (in != null)
in.close();
break MISSING_BLOCK_LABEL_79;
Exception exception;
exception;
if (in != null)
in.close();
throw exception;
return keystore;
}
protected KeyStore loadKeyStore()
throws Exception
{
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
return loadKeyStore(keyManagerFactory);
}
protected KeyStore loadKeyStore(KeyManagerFactory keyManagerFactory)
throws Exception
{
KeyStore key_store;
InputStream kis;
key_store = KeyStore.getInstance(KEYSTORE_TYPE);
if (!(new File(keystore_name)).exists())
{
key_store.load(null, null);
break MISSING_BLOCK_LABEL_81;
}
kis = null;
kis = new FileInputStream(keystore_name);
key_store.load(kis, "changeit".toCharArray());
if (kis != null)
kis.close();
break MISSING_BLOCK_LABEL_81;
Exception exception;
exception;
if (kis != null)
kis.close();
throw exception;
keyManagerFactory.init(key_store, "changeit".toCharArray());
return key_store;
}
public SSLServerSocketFactory getSSLServerSocketFactory()
throws Exception
{
if (!checkKeyStoreHasEntry())
{
return null;
} else
{
SSLContext context = SSLContext.getInstance("SSL");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
loadKeyStore(keyManagerFactory);
context.init(keyManagerFactory.getKeyManagers(), null, RandomUtils.SECURE_RANDOM);
SSLServerSocketFactory factory = context.getServerSocketFactory();
return factory;
}
}
public SEKeyDetails getKeyDetails(String alias)
throws Exception
{
KeyStore key_store = loadKeyStore();
final Key key = key_store.getKey(alias, "changeit".toCharArray());
if (key == null)
return null;
Certificate chain[] = key_store.getCertificateChain(alias);
final X509Certificate res[] = new X509Certificate[chain.length];
for (int i = 0; i < chain.length; i++)
{
if (!(chain[i] instanceof X509Certificate))
throw new Exception("Certificate chain must be comprised of X509Certificate entries");
res[i] = (X509Certificate)chain[i];
}
return new SEKeyDetails() {
final Key val$key;
final X509Certificate val$res[];
final SESecurityManagerImpl this$0;
public Key getKey()
{
return key;
}
public X509Certificate[] getCertificateChain()
{
return res;
}
{
this$0 = SESecurityManagerImpl.this;
key = key1;
res = ax509certificate;
super();
}
};
}
public Certificate createSelfSignedCertificate(String alias, String cert_dn, int strength)
throws Exception
{
return SESecurityManagerBC.createSelfSignedCertificate(this, alias, cert_dn, strength);
}
public SSLSocketFactory getSSLSocketFactory()
{
SSLSocketFactory sslsocketfactory1;
this_mon.enter();
KeyStore keystore = getTrustStore();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keystore);
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, tmf.getTrustManagers(), null);
SSLSocketFactory factory = ctx.getSocketFactory();
sslsocketfactory1 = factory;
this_mon.exit();
return sslsocketfactory1;
Throwable e;
e;
SSLSocketFactory sslsocketfactory;
Debug.printStackTrace(e);
sslsocketfactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
this_mon.exit();
return sslsocketfactory;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public SSLSocketFactory installServerCertificates(URL https_url)
{
String host;
int port;
SSLSocket socket;
this_mon.enter();
host = https_url.getHost();
port = https_url.getPort();
if (port == -1)
port = 443;
socket = null;
Certificate serverCerts[];
Certificate cert;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -