~ubuntu-branches/ubuntu/natty/icedtea-web/natty-security

« back to all changes in this revision

Viewing changes to netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-02-24 12:57:25 UTC
  • mto: (18.1.1 experimental) (19.1.1 natty-security)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20110224125725-8zq5v35r6o27w8ku
Tags: upstream-1.1~20110320
ImportĀ upstreamĀ versionĀ 1.1~20110320

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import java.awt.Frame;
22
22
import java.awt.Window;
23
 
import java.awt.event.WindowAdapter;
24
 
import java.awt.event.WindowEvent;
25
23
import java.lang.ref.WeakReference;
26
24
import java.net.SocketPermission;
27
25
import java.security.AllPermission;
28
26
import java.security.AccessControlException;
29
 
import java.security.AccessController;
30
27
import java.security.Permission;
31
 
import java.security.PrivilegedAction;
32
28
import java.security.SecurityPermission;
33
 
import java.util.PropertyPermission;
34
29
 
35
30
import javax.swing.JWindow;
36
31
 
37
32
import net.sourceforge.jnlp.JNLPFile;
38
 
import net.sourceforge.jnlp.security.SecurityWarning.AccessType;
 
33
import net.sourceforge.jnlp.security.SecurityDialogs.AccessType;
39
34
import net.sourceforge.jnlp.services.ServiceUtil;
40
35
import net.sourceforge.jnlp.util.WeakList;
41
36
import sun.awt.AWTSecurityManager;
103
98
    private WeakList<ApplicationInstance> weakApplications =
104
99
            new WeakList<ApplicationInstance>();
105
100
 
106
 
    /** weak reference to most app who's windows was most recently activated */
107
 
    private WeakReference activeApplication = null;
108
 
 
109
101
    /** Sets whether or not exit is allowed (in the context of the plugin, this is always false) */
110
102
    private boolean exitAllowed = true;
111
103
 
204
196
 
205
197
        // this needs to be tightened up
206
198
        for (int i = 0; i < stack.length && i < maxDepth; i++) {
207
 
            if (stack[i].getClassLoader() instanceof JNLPClassLoader) {
208
 
                JNLPClassLoader loader = (JNLPClassLoader) stack[i].getClassLoader();
 
199
            ClassLoader cl = stack[i].getClassLoader();
 
200
            
 
201
            // Since we want to deal with JNLPClassLoader, extract it if this 
 
202
            // is a codebase loader
 
203
            if (cl instanceof JNLPClassLoader.CodeBaseClassLoader)
 
204
                cl = ((JNLPClassLoader.CodeBaseClassLoader) cl).getParentJNLPClassLoader();
 
205
 
 
206
            if (cl instanceof JNLPClassLoader) {
 
207
 
 
208
                JNLPClassLoader loader = (JNLPClassLoader) cl;
209
209
 
210
210
                if (loader != null && loader.getApplication() != null) {
211
211
                    return loader.getApplication();
311
311
                            }
312
312
                        }
313
313
                    }
314
 
 
315
 
                } else if (perm instanceof SecurityPermission) {
316
 
                    tmpPerm = perm;
317
 
 
318
 
                    // JCE's initialization requires putProviderProperty permission
319
 
                    if (perm.equals(new SecurityPermission("putProviderProperty.SunJCE"))) {
320
 
                        if (inTrustedCallChain("com.sun.crypto.provider.SunJCE", "run")) {
321
 
                            return;
322
 
                        }
323
 
                    }
324
 
 
325
 
                } else if (perm instanceof RuntimePermission) {
326
 
                    tmpPerm = perm;
327
 
 
328
 
                    // KeyGenerator's init method requires internal spec access
329
 
                    if (perm.equals(new SecurityPermission("accessClassInPackage.sun.security.internal.spec"))) {
330
 
                        if (inTrustedCallChain("javax.crypto.KeyGenerator", "init")) {
331
 
                            return;
332
 
                        }
333
 
                    }
334
 
 
335
314
                } else {
336
315
                    tmpPerm = perm;
337
316
                }
356
335
    }
357
336
 
358
337
    /**
359
 
     * Returns weather the given class and method are in the current stack,
360
 
     * and whether or not everything upto then is trusted
361
 
     *
362
 
     * @param className The name of the class to look for in the stack
363
 
     * @param methodName The name of the method for the given class to look for in the stack
364
 
     * @return Weather or not class::method() are in the chain, and everything upto there is trusted
365
 
     */
366
 
    private boolean inTrustedCallChain(String className, String methodName) {
367
 
 
368
 
        StackTraceElement[] stack = Thread.currentThread().getStackTrace();
369
 
 
370
 
        for (int i = 0; i < stack.length; i++) {
371
 
 
372
 
            // Everything up to the desired class/method must be trusted
373
 
            if (!stack[i].getClass().getProtectionDomain().implies(new AllPermission())) {
374
 
                return false;
375
 
            }
376
 
 
377
 
            if (stack[i].getClassName().equals(className) &&
378
 
                    stack[i].getMethodName().equals(methodName)) {
379
 
                return true;
380
 
            }
381
 
        }
382
 
 
383
 
        return false;
384
 
    }
385
 
 
386
 
    /**
387
338
     * Asks the user whether or not to grant permission.
388
339
     * @param perm the permission to be granted
389
340
     * @return true if the permission was granted, false otherwise.
495
446
        // but when they really call, stop only the app instead of the JVM
496
447
        ApplicationInstance app = getApplication(stack, 0);
497
448
        if (app == null) {
498
 
            // should check caller to make sure it is JFrame.close or
499
 
            // other known System.exit call
500
 
            if (activeApplication != null)
501
 
                app = (ApplicationInstance) activeApplication.get();
502
 
 
503
 
            if (app == null)
504
 
                throw new SecurityException(R("RExitNoApp"));
 
449
            throw new SecurityException(R("RExitNoApp"));
505
450
        }
506
451
 
507
452
        app.destroy();