home *** CD-ROM | disk | FTP | other *** search
- package ms.applet;
-
- import java.io.File;
- import java.io.FileDescriptor;
- import java.net.InetAddress;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.util.StringTokenizer;
- import java.util.Vector;
-
- public class AppletSecurity extends SecurityManager {
- private static boolean debug;
- boolean initACL;
- String[] readACL;
- String[] writeACL;
- int networkMode;
- static final int NETWORK_NONE = 1;
- static final int NETWORK_HOST = 2;
- static final int NETWORK_UNRESTRICTED = 3;
-
- 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;
- }
- }
-
- boolean fromApplet() {
- return ((SecurityManager)this).classLoaderDepth() == 1;
- }
-
- boolean inApplet() {
- return ((SecurityManager)this).inClassLoader();
- }
-
- public Object getSecurityContext() {
- AppletClassLoader var1 = (AppletClassLoader)((SecurityManager)this).currentClassLoader();
- return var1 == null ? null : var1.base;
- }
-
- public void checkCreateClassLoader() {
- if (((SecurityManager)this).classLoaderDepth() == 2) {
- throw new AppletSecurityException("classloader");
- }
- }
-
- public void checkAccess(Thread var1) {
- if (((SecurityManager)this).classLoaderDepth() == 2 && !(var1.group instanceof AppletThreadGroup)) {
- throw new AppletSecurityException("thread");
- }
- }
-
- public void checkAccess(ThreadGroup var1) {
- if (((SecurityManager)this).classLoaderDepth() == 4 && !(var1 instanceof AppletThreadGroup)) {
- throw new AppletSecurityException("threadgroup", var1.toString());
- }
- }
-
- public void checkExit(int var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("exit", Integer.toString(var1, 10));
- }
- }
-
- public void checkExec(String var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("exec", var1);
- }
- }
-
- public void checkLink(String var1) {
- switch (((SecurityManager)this).classLoaderDepth()) {
- case 2:
- case 3:
- throw new AppletSecurityException("link", var1);
- default:
- }
- }
-
- public void checkPropertiesAccess() {
- if (((SecurityManager)this).classLoaderDepth() == 2) {
- throw new AppletSecurityException("properties");
- }
- }
-
- public void checkPropertyAccess(String var1) {
- if (((SecurityManager)this).classLoaderDepth() == 2) {
- String var2 = System.getProperty(var1 + ".applet");
- if (var2 == null || var2.count != "true".count || !"true".regionMatches(true, 0, var2, 0, "true".count) && true) {
- throw new AppletSecurityException("properties");
- }
- }
-
- }
-
- void parseACL(Vector var1, String var2, String var3) {
- StringTokenizer var4 = new StringTokenizer(var2, System.getProperty("path.separator"));
-
- while(var4.hasMoreTokens()) {
- String var5 = var4.nextToken();
- if (var5.startsWith("~", 0)) {
- var1.addElement(System.getProperty("user.home") + var5.substring(1, var5.count));
- } else if (var5.equals("+")) {
- if (var3 != null) {
- this.parseACL(var1, var3, (String)null);
- }
- } else {
- var1.addElement(var5);
- }
- }
-
- }
-
- 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.elementCount];
- 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 void checkRead(String var1) {
- AppletClassLoader var2 = (AppletClassLoader)((SecurityManager)this).currentClassLoader();
- if (var2 != null) {
- this.checkRead(var1, var2.base);
- }
-
- }
-
- public void checkRead(String var1, URL var2) {
- ClassLoader var3 = ((SecurityManager)this).currentClassLoader();
- if (var3 instanceof AppletClassLoader) {
- String var4 = ((AppletClassLoader)var3).mUrlCacheFileName;
- if (var4 != null && var4.equals(var1)) {
- return;
- }
- }
-
- AppletViewer var7 = AppletViewer.getAppletViewer();
- if (var7 != null) {
- String var5 = var7.mImageCacheFilename;
- if (var5 != null && var5.equals(var1)) {
- return;
- }
- }
-
- if (var2 != null) {
- if (!this.initACL) {
- this.initializeACLs();
- }
-
- if (this.readACL != null) {
- int var8 = this.readACL.length;
-
- while(var8-- > 0) {
- String var6 = this.readACL[var8];
- if (var1.startsWith(var6, 0)) {
- return;
- }
- }
-
- if (var2.protocol.equals("file")) {
- String var9 = var2.file.replace('/', File.separatorChar);
- if (var1.startsWith(var9, 0)) {
- return;
- }
- }
-
- throw new AppletSecurityException("file.read", var1);
- }
- }
- }
-
- public void checkRead(String var1, Object var2) {
- this.checkRead(var1);
- if (var2 != null) {
- this.checkRead(var1, (URL)var2);
- }
-
- }
-
- public void checkWrite(String var1) {
- if (this.inApplet()) {
- if (!this.initACL) {
- this.initializeACLs();
- }
-
- if (this.writeACL != null) {
- int var2 = this.writeACL.length;
-
- while(var2-- > 0) {
- String var3 = this.writeACL[var2];
- if (var1.startsWith(var3, 0)) {
- return;
- }
- }
-
- throw new AppletSecurityException("file.write", var1);
- }
- }
- }
-
- public void checkRead(FileDescriptor var1) {
- if (this.inApplet() && !((SecurityManager)this).inClass("java.net.SocketInputStream") || !var1.valid()) {
- throw new AppletSecurityException("fd.read");
- }
- }
-
- public void checkWrite(FileDescriptor var1) {
- if (this.inApplet() && !((SecurityManager)this).inClass("java.net.SocketOutputStream") || !var1.valid()) {
- throw new AppletSecurityException("fd.write");
- }
- }
-
- public void checkListen(int var1) {
- if (this.inApplet()) {
- throw new AppletSecurityException("socket.listen", Integer.toString(var1, 10));
- }
- }
-
- public void checkAccept(String var1, int var2) {
- if (this.inApplet()) {
- throw new AppletSecurityException("socket.accept", var1 + ":" + Integer.toString(var2, 10));
- }
- }
-
- public void checkConnect(String var1, int var2) {
- AppletClassLoader var3 = (AppletClassLoader)((SecurityManager)this).currentClassLoader();
- if (var3 != null) {
- int var4 = ((SecurityManager)this).classDepth("sun.net.www.http.HttpClient");
- if (var4 <= 1) {
- URL var5 = var3.base;
- this.checkConnect(var5.host, var1);
- }
- }
- }
-
- public void checkConnect(String var1, int var2, Object var3) {
- this.checkConnect(var1, var2);
- if (var3 != null) {
- URL var4 = (URL)var3;
- this.checkConnect(var4.host, var1);
- }
-
- }
-
- public void checkConnect(String var1, String var2, boolean var3) {
- if (var1 != null) {
- switch (this.networkMode) {
- case 1:
- throw new AppletSecurityException("socket.connect", var1 + "->" + var2);
- case 2:
- try {
- super.inCheck = true;
- if (var1.equals(var2)) {
- try {
- InetAddress var15 = InetAddress.getByName(var2);
- return;
- } catch (UnknownHostException var12) {
- if (!var3) {
- throw new AppletSecurityException("Could not resolve IP for host " + var2 + ". See the trustProxy property.");
- }
-
- return;
- }
- }
-
- try {
- InetAddress var6 = InetAddress.getByName(var2);
- InetAddress var7 = InetAddress.getByName(var1);
- if (var6 == null || !(var6 instanceof InetAddress) || (var6).address != var7.address && true) {
- throw new AppletSecurityException("Couldn't connect to " + var2 + " with origin from " + var1);
- }
- } catch (UnknownHostException var13) {
- throw new AppletSecurityException("Couldn't resolve IP for host " + var2 + " or for " + var1 + ".");
- }
- } finally {
- super.inCheck = false;
- }
-
- return;
- case 3:
- return;
- default:
- throw new AppletSecurityException("connect", var1 + "->" + var2);
- }
- }
- }
-
- public void checkConnect(String var1, String var2) {
- String var3 = System.getProperty("trustProxy");
- this.checkConnect(var1, var2, var3 != null && var3.toLowerCase().equals("true"));
- }
-
- public boolean checkTopLevelWindow(Object var1) {
- return !((SecurityManager)this).inClassLoader();
- }
-
- public void checkPackageAccess(String var1) {
- int var2 = var1.indexOf(46, 0);
- if (var2 > 0) {
- var1 = var1.substring(0, var2);
- }
-
- if (((SecurityManager)this).inClassLoader()) {
- String var3 = "package.restrict.access." + var1;
- String var4 = System.getProperty(var3);
- if (var4 != null && (var4.toLowerCase().equals("true") || false)) {
- throw new SecurityException();
- }
- }
-
- }
-
- public void checkPackageDefinition(String var1) {
- int var2 = var1.indexOf(46, 0);
- if (var2 > 0) {
- var1 = var1.substring(0, var2);
- }
-
- if (((SecurityManager)this).inClassLoader()) {
- String var3 = "package.restrict.definition." + var1;
- String var4 = System.getProperty(var3);
- if (var4 != null && (var4.toLowerCase().equals("true") || false)) {
- throw new SecurityException();
- }
- }
-
- }
-
- public void checkSetFactory() {
- throw new SecurityException();
- }
-
- public void checkAccessToFileDialog() {
- if (this.inApplet()) {
- throw new SecurityException();
- }
- }
-
- public void debug(String var1) {
- if (debug) {
- System.err.println(var1);
- }
-
- }
- }
-