home *** CD-ROM | disk | FTP | other *** search
- package sun.applet;
-
- import java.io.File;
- import java.io.FileDescriptor;
- import java.io.IOException;
- import java.net.InetAddress;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.security.IdentityScope;
- import java.util.Hashtable;
- import java.util.StringTokenizer;
- import java.util.Vector;
- import sun.security.provider.IdentityDatabase;
- import sun.security.provider.SystemIdentity;
- import sun.security.provider.SystemSigner;
-
- public class AppletSecurity extends SecurityManager {
- private static boolean debug;
- static final int NETWORK_NONE = 1;
- static final int NETWORK_HOST = 2;
- static final int NETWORK_UNRESTRICTED = 3;
- private static final int PRIVELEGED_PORT = 1024;
- boolean initACL;
- String[] readACL;
- String[] writeACL;
- int networkMode;
- IdentityScope scope;
- Hashtable loadedClasses;
-
- public AppletSecurity() {
- this.reset();
- }
-
- public void reset() {
- String var1 = System.getProperty("appletviewer.security.mode");
- if (var1 == null) {
- var1 = "host";
- }
-
- if (var1.equals("unrestricted")) {
- this.networkMode = 3;
- } else if (var1.equals("none")) {
- this.networkMode = 1;
- } else {
- this.networkMode = 2;
- }
-
- IdentityScope var2 = IdentityScope.getSystemScope();
- if (var2 instanceof IdentityDatabase) {
- this.scope = (IdentityDatabase)var2;
- this.debug("installing " + var2 + " as the scope for signers.");
- } else {
- this.debug("no signer scope found.");
- }
-
- this.loadedClasses = new Hashtable();
- }
-
- boolean fromApplet() {
- return ((SecurityManager)this).classLoaderDepth() == 1;
- }
-
- protected boolean assessTrust(Object[] var1) {
- for(int var2 = 0; var2 < var1.length; ++var2) {
- if (var1[var2] instanceof SystemIdentity) {
- SystemIdentity var3 = (SystemIdentity)var1[var2];
- if (var3.isTrusted()) {
- return true;
- }
- } else if (var1[var2] instanceof SystemSigner) {
- SystemSigner var4 = (SystemSigner)var1[var2];
- if (var4.isTrusted()) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- boolean inApplet() {
- return ((SecurityManager)this).inClassLoader();
- }
-
- public Object getSecurityContext() {
- ClassLoader var1 = ((SecurityManager)this).currentClassLoader();
- if (var1 == null) {
- return null;
- } else if (var1 instanceof AppletClassLoader) {
- AppletClassLoader var2 = (AppletClassLoader)var1;
- return var2.base;
- } else {
- throw new AppletSecurityException("getsecuritycontext.unknown");
- }
- }
-
- public synchronized boolean getInCheck() {
- return super.getInCheck();
- }
-
- public synchronized void checkCreateClassLoader() {
- if (((SecurityManager)this).classLoaderDepth() == 2) {
- throw new AppletSecurityException("checkcreateclassloader");
- }
- }
-
- protected boolean inThreadGroup(ThreadGroup var1) {
- ClassLoader var2 = ((SecurityManager)this).currentClassLoader();
- if (var2 instanceof AppletClassLoader) {
- AppletClassLoader var3 = (AppletClassLoader)var2;
- ThreadGroup var4 = var3.getThreadGroup();
- return var4.parentOf(var1);
- } else {
- return false;
- }
- }
-
- protected boolean inThreadGroup(Thread var1) {
- return this.inThreadGroup(var1.getThreadGroup());
- }
-
- public synchronized void checkAccess(Thread var1) {
- if (((SecurityManager)this).classLoaderDepth() == 3 && !this.inThreadGroup(var1)) {
- throw new AppletSecurityException("checkaccess.thread");
- }
- }
-
- public synchronized void checkAccess(ThreadGroup var1) {
- if (((SecurityManager)this).classLoaderDepth() == 4 && !this.inThreadGroup(var1)) {
- throw new AppletSecurityException("checkaccess.threadgroup", var1.toString());
- }
- }
-
- public synchronized void checkExit(int var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("checkexit", String.valueOf(var1));
- }
- }
-
- public synchronized void checkExec(String var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("checkexec", var1);
- }
- }
-
- public synchronized void checkLink(String var1) {
- switch (((SecurityManager)this).classLoaderDepth()) {
- case 2:
- case 3:
- throw new AppletSecurityException("checklink", var1);
- default:
- }
- }
-
- public synchronized void checkPropertiesAccess() {
- if (((SecurityManager)this).classLoaderDepth() == 2) {
- throw new AppletSecurityException("checkpropsaccess");
- }
- }
-
- public synchronized void checkPropertyAccess(String var1) {
- if (((SecurityManager)this).classLoaderDepth() == 2) {
- String var2 = System.getProperty(var1 + ".applet");
- boolean var3 = new Boolean(var2);
- if (!var3) {
- throw new AppletSecurityException("checkpropsaccess.key", var2);
- }
- }
- }
-
- void parseACL(Vector var1, String var2, String var3) {
- String var4 = System.getProperty("path.separator");
- StringTokenizer var5 = new StringTokenizer(var2, var4);
-
- while(var5.hasMoreTokens()) {
- String var6 = var5.nextToken();
- if (var6.startsWith("~")) {
- var1.addElement(System.getProperty("user.home") + var6.substring(1));
- } else if (var6.equals("+")) {
- if (var3 != null) {
- this.parseACL(var1, var3, (String)null);
- }
- } else {
- var1.addElement(var6);
- }
- }
-
- }
-
- String[] parseACL(String var1, String var2) {
- if (var1 == null) {
- return new String[0];
- } else if (var1.equals("*")) {
- return null;
- } else {
- Vector var3 = new Vector();
- this.parseACL(var3, var1, var2);
- String[] var4 = new String[var3.size()];
- var3.copyInto(var4);
- return var4;
- }
- }
-
- void initializeACLs() {
- this.readACL = this.parseACL(System.getProperty("acl.read"), System.getProperty("acl.read.default"));
- this.writeACL = this.parseACL(System.getProperty("acl.write"), System.getProperty("acl.write.default"));
- this.initACL = true;
- }
-
- public synchronized void checkRead(String var1) {
- ClassLoader var2 = ((SecurityManager)this).currentClassLoader();
- if (var2 != null) {
- if (!(var2 instanceof AppletClassLoader)) {
- throw new AppletSecurityException("checkread.unknown", var1);
- } else {
- AppletClassLoader var3 = (AppletClassLoader)var2;
- this.checkRead(var1, var3.base);
- }
- }
- }
-
- public synchronized void checkRead(String var1, URL var2) {
- if (var2 != null) {
- if (!this.initACL) {
- this.initializeACLs();
- }
-
- if (this.readACL != null) {
- Object var3 = null;
-
- try {
- var9 = (new File(var1)).getCanonicalPath();
- } catch (IOException var8) {
- throw new AppletSecurityException("checkread.exception1", ((Throwable)var8).getMessage(), var1);
- }
-
- int var4 = this.readACL.length;
-
- while(var4-- > 0) {
- if (var9.startsWith(this.readACL[var4])) {
- return;
- }
- }
-
- if (var2.getProtocol().equals("file")) {
- Object var5 = null;
-
- try {
- var10 = (new File(var2.getFile())).getCanonicalPath();
- } catch (IOException var7) {
- throw new AppletSecurityException("checkread.exception2", ((Throwable)var7).toString());
- }
-
- if (var9.startsWith(var10)) {
- return;
- }
- }
-
- throw new AppletSecurityException("checkread", var1, var9);
- }
- }
- }
-
- public void checkRead(String var1, Object var2) {
- this.checkRead(var1);
- if (var2 != null) {
- this.checkRead(var1, (URL)var2);
- }
-
- }
-
- public synchronized void checkWrite(String var1) {
- if (this.inApplet()) {
- if (!this.initACL) {
- this.initializeACLs();
- }
-
- if (this.writeACL != null) {
- Object var2 = null;
-
- try {
- var5 = (new File(var1)).getCanonicalPath();
- } catch (IOException var4) {
- throw new AppletSecurityException("checkwrite.exception", ((Throwable)var4).getMessage(), var1);
- }
-
- int var3 = this.writeACL.length;
-
- while(var3-- > 0) {
- if (var5.startsWith(this.writeACL[var3])) {
- return;
- }
- }
-
- throw new AppletSecurityException("checkwrite", var1, var5);
- }
- }
- }
-
- public synchronized void checkRead(FileDescriptor var1) {
- if (this.inApplet() && !((SecurityManager)this).inClass("java.net.SocketInputStream") || !var1.valid()) {
- throw new AppletSecurityException("checkread.fd");
- }
- }
-
- public synchronized void checkWrite(FileDescriptor var1) {
- if (this.inApplet() && !((SecurityManager)this).inClass("java.net.SocketOutputStream") || !var1.valid()) {
- throw new AppletSecurityException("checkwrite.fd");
- }
- }
-
- public synchronized void checkListen(int var1) {
- if (this.inApplet() && var1 > 0 && var1 < 1024) {
- throw new AppletSecurityException("checklisten", String.valueOf(var1));
- }
- }
-
- public synchronized void checkAccept(String var1, int var2) {
- if (this.inApplet() && var2 < 1024) {
- throw new AppletSecurityException("checkaccept", var1, String.valueOf(var2));
- } else {
- this.checkConnect(var1, var2);
- }
- }
-
- public synchronized void checkConnect(String var1, int var2) {
- ClassLoader var3 = ((SecurityManager)this).currentClassLoader();
- if (var3 != null) {
- int var4 = ((SecurityManager)this).classDepth("sun.net.www.http.HttpClient");
- if (var4 <= 1) {
- if (var3 instanceof AppletClassLoader) {
- AppletClassLoader var5 = (AppletClassLoader)var3;
- this.checkConnect(var5.base.getHost(), var1);
- } else {
- throw new AppletSecurityException("checkconnect.unknown");
- }
- }
- }
- }
-
- public void checkConnect(String var1, int var2, Object var3) {
- this.checkConnect(var1, var2);
- if (var3 != null) {
- this.checkConnect(((URL)var3).getHost(), var1);
- }
-
- }
-
- public synchronized void checkConnect(String var1, String var2, boolean var3) {
- if (var1 != null) {
- switch (this.networkMode) {
- case 1:
- throw new AppletSecurityException("checkconnect.networknone", var1, var2);
- case 2:
- try {
- super.inCheck = true;
- if (var1.equals(var2)) {
- try {
- InetAddress var14 = InetAddress.getByName(var2);
- return;
- } catch (UnknownHostException var12) {
- if (!var3) {
- throw new AppletSecurityException("checkconnect.networkhost3", var2);
- }
-
- return;
- }
- }
-
- try {
- InetAddress var6 = InetAddress.getByName(var2);
- InetAddress var7 = InetAddress.getByName(var1);
- if (!var7.equals(var6)) {
- throw new AppletSecurityException("checkconnect.networkhost1", var2, var1);
- }
- } catch (UnknownHostException var11) {
- throw new AppletSecurityException("checkconnect.networkhost2", var2, var1);
- }
- } finally {
- super.inCheck = false;
- }
-
- return;
- case 3:
- return;
- default:
- throw new AppletSecurityException("checkconnect", var1, var2);
- }
- }
- }
-
- public synchronized void checkConnect(String var1, String var2) {
- this.checkConnect(var1, var2, Boolean.getBoolean("trustProxy"));
- }
-
- public synchronized boolean checkTopLevelWindow(Object var1) {
- return !((SecurityManager)this).inClassLoader();
- }
-
- public synchronized void checkPackageAccess(String var1) {
- if (((SecurityManager)this).inClassLoader()) {
- for(int var2 = var1.indexOf(46); var2 > 0; var2 = var1.indexOf(46, var2 + 1)) {
- String var3 = var1.substring(0, var2);
- if (Boolean.getBoolean("package.restrict.access." + var3)) {
- throw new AppletSecurityException("checkpackageaccess", var1);
- }
- }
-
- }
- }
-
- public synchronized void checkPackageDefinition(String var1) {
- if (((SecurityManager)this).inClassLoader()) {
- for(int var2 = var1.indexOf(46); var2 > 0; var2 = var1.indexOf(46, var2 + 1)) {
- String var3 = var1.substring(0, var2);
- if (Boolean.getBoolean("package.restrict.definition." + var3)) {
- throw new AppletSecurityException("checkpackagedefinition", var1);
- }
- }
-
- }
- }
-
- public synchronized void checkSetFactory() {
- if (this.inApplet() && !((SecurityManager)this).inClass("sun.net.www.MimeTable")) {
- throw new AppletSecurityException("cannotsetfactory");
- }
- }
-
- public void checkMemberAccess(Class var1, int var2) {
- if (var2 != 0) {
- ClassLoader var3 = ((SecurityManager)this).currentClassLoader();
- if (var3 != null && ((SecurityManager)this).classLoaderDepth() <= 3 && var3 != var1.getClassLoader()) {
- throw new AppletSecurityException("checkmemberaccess");
- }
- }
-
- }
-
- public void checkPrintJobAccess() {
- if (this.inApplet()) {
- throw new AppletSecurityException("checkgetprintjob");
- }
- }
-
- public void checkSystemClipboardAccess() {
- if (this.inApplet()) {
- throw new AppletSecurityException("checksystemclipboardaccess");
- }
- }
-
- public void checkAwtEventQueueAccess() {
- throw new AppletSecurityException("checkawteventqueueaccess");
- }
-
- public void checkSecurityAccess(String var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("checksecurityaccess", var1);
- }
- }
-
- public ThreadGroup getThreadGroup() {
- ClassLoader var1 = ((SecurityManager)this).currentClassLoader();
- if (var1 != null && var1 instanceof AppletClassLoader) {
- AppletClassLoader var2 = (AppletClassLoader)var1;
- return var2.getThreadGroup();
- } else {
- return super.getThreadGroup();
- }
- }
-
- public void debug(String var1) {
- if (debug) {
- System.err.println(var1);
- }
-
- }
- }
-