代码之家  ›  专栏  ›  技术社区  ›  Julien Chastang

谷歌应用引擎JRE类“黑名单”

  •  10
  • Julien Chastang  · 技术社区  · 17 年前

    有一个“ JRE Class White List “谷歌应用引擎。

    我真正想要的是一个“黑名单”——换句话说,在GAE上不工作的Java API。有这样的名单吗?是否有任何开发者在GAE上遇到Java API的问题?

    5 回复  |  直到 10 年前
        1
  •  9
  •   Grey Panther    17 年前

    他们似乎采取了更多的白名单方式: http://code.google.com/appengine/docs/java/jrewhitelist.html .

    这里还有关于沙盒(它可以访问哪些文件等)的更多详细信息: http://code.google.com/appengine/docs/java/runtime.html#The_Sandbox

    这些限制看起来非常直观(比如受限制的文件系统访问,没有jni等等)。

        2
  •  6
  •   Miguel Ping    17 年前

    我不知道黑名单,但以下链接可能会有帮助: http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine

        3
  •  1
  •   itsadok    17 年前

    我在google的i/o上得到了一张广告卡:

    LTech AppEngine Compatibility Analyzer

    听起来可能对你有用。我没有试过,如果你试过,请回来评论。谢谢!

        4
  •  1
  •   magallanes    15 年前

    我在gae项目中使用了servlet,但是它不在白名单中,即使它可以正常工作。实际上,google提到了如何使用servlet,但它不在白名单中

    导入javax.servlet.http.*;

    这里提到:

    http://code.google.com/appengine/docs/java/runtime.html

    但此处不包括:

    http://code.google.com/appengine/docs/java/jrewhitelist.html

    我喜欢gae(因为免费配额),但是文档很混乱。

    我使用intellij,当导入不在白名单中时,它会标记为错误。但是,可以禁用它。

        5
  •  1
  •   Avis    10 年前

    当我遇到这个查询时,我正在寻找一些东西,所以我想分享gae(google app engine)黑白列表上的详细信息,这样任何人都可以正确地解决这个问题。细节:

    appengine-agentruntime.jar文件 有两个实例变量:

    private static Agent agent      
    private static Set<String> blackList
    

    我们从探员那里得到黑名单= AppEngineDevAgent.getAgent() . 所以如果我们检查一下 b)appengine-agent.jar文件 我们可以找到探员 Class<?> implClass = agentImplLoader.loadClass("com.google.appengine.tools.development.agent.impl.AgentImpl");

    然后转到agentimpl类。 c)appengine-agentimpl.jar文件 我们可以 请参阅使用静态初始化在类加载时填充黑名单变量&它引用白名单以筛选允许的类。

    static {
                initBlackList();
            }
    
        public static Set<String> getBlackList() {
            return blackList;
        }
    
        private static boolean isBlackListed(String className) {
            Set<String> whiteList = WhiteList.getWhiteList();
            return (!whiteList.contains(className))
                    && (!className.startsWith("com.sun.xml.internal.bind."));
        }
    

    终于可以检查了 d)appengine-tools-sdk-1.8.3.jar文件 所有白名单类的列表。

    结论: 作为一个黑客,为了使用任何不属于这个白名单的jre类,需要使用白名单或黑名单。 . 如果你取消 appengine-agentruntime.jar文件 库注释拒绝方法的内容为

    public static void reject(String className) {
        /*throw new NoClassDefFoundError(className + " is a restricted class. Please see the Google " + " App Engine developer's guide for more details.");*/
      }
    

    然后再把它用在你的项目中,希望能有所帮助。

    ————————————————————————————————————————————————————————---

    a) appengine-agentruntime.jar文件 :-它包含实际的 运行时 引发异常的类(从 拒绝 方法)对于不属于上述白名单的类。

    package com.google.appengine.tools.development.agent.runtime;
    
    import com.google.appengine.tools.development.agent.AppEngineDevAgent;
    import com.google.appengine.tools.development.agent.impl.Agent;
    import com.google.apphosting.utils.clearcast.ClearCast;
    //REMOVED OTHER IMPORTS TO KEEP IT SHORT
    
    public class Runtime {
    
        private static Agent agent = (Agent) ClearCast.cast(
                AppEngineDevAgent.getAgent(), Agent.class);
    
        private static Set<String> blackList = agent.getBlackList();
    
        public static ClassLoader checkParentClassLoader(ClassLoader loader) {
            ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
            return (loader != null) && (loader != systemLoader) ? loader
                    : Runtime.class.getClassLoader();
        }
    
        public static void recordClassLoader(ClassLoader loader) {
            agent.recordAppClassLoader(loader);
        }
    
        public static void reject(String className) {
            throw new NoClassDefFoundError(className
                    + " is a restricted class. Please see the Google "
                    + " App Engine developer's guide for more details.");
        }
    
        private static boolean isBlackListed(Class klass) {
            String className = klass.getName().replace('.', '/');
            return blackList.contains(className);
        }
    
        // REMOVED OTHER METHODS TO KEEP IT SHORT
    }
    

    b) appengine-agent.jar文件 -

    package com.google.appengine.tools.development.agent;
    
    import com.google.apphosting.utils.clearcast.ClearCast;
    //REMOVED OTHER IMPORTS TO KEEP IT SHORT
    
    public class AppEngineDevAgent {
        private static final String AGENT_IMPL = "com.google.appengine.tools.development.agent.impl.AgentImpl";
        private static final String AGENT_IMPL_JAR = "appengine-agentimpl.jar";
        private static final Logger logger = Logger.getLogger(AppEngineDevAgent.class.getName());
        private static Object impl;
    
        public static void premain(String agentArgs, Instrumentation inst) {
            URL agentImplLib = findAgentImplLib();
            URLClassLoader agentImplLoader = new URLClassLoader(
                    new URL[] { agentImplLib }) {
                protected PermissionCollection getPermissions(CodeSource codesource) {
                    PermissionCollection perms = super.getPermissions(codesource);
                    perms.add(new AllPermission());
                    return perms;
                }
            };
            try {
                Class<?> implClass = agentImplLoader
                        .loadClass("com.google.appengine.tools.development.agent.impl.AgentImpl");
                impl = ((AgentImplStruct) ClearCast.staticCast(implClass,
                        AgentImplStruct.class)).getInstance();
                AgentImplStruct agentImplStruct = (AgentImplStruct) ClearCast.cast(
                        impl, AgentImplStruct.class);
                agentImplStruct.run(inst);
            } catch (Exception e) {
                logger.log(
                        Level.SEVERE,
                        "Unable to load the App Engine dev agent. Security restrictions will not be completely emulated.",
                        e);
            }
        }
    
        public static Object getAgent() {
            return impl;
        }
    
        //REMOVED OTHER METHODS TO KEEP IT SHORT
    }
    

    c) appengine-agentimpl.jar文件 -

    package com.google.appengine.tools.development.agent.impl;
    
    import com.google.apphosting.runtime.security.WhiteList;
    //REMOVED OTHER IMPORTS TO KEEP IT SHORT
    
    public class BlackList {
        private static final Logger logger = Logger.getLogger(BlackList.class.getName());
        private static Set<String> blackList = new HashSet();
    
        static {
            initBlackList();
        }
    
        public static Set<String> getBlackList() {
            return blackList;
        }
    
        private static boolean isBlackListed(String className) {
            Set<String> whiteList = WhiteList.getWhiteList();
            return (!whiteList.contains(className))
                    && (!className.startsWith("com.sun.xml.internal.bind."));
        }
    
        private static void initBlackList() {
            Set<File> jreJars = getCurrentJreJars();
            for (File f : jreJars) {
                JarFile jarFile = null;
                try {
                    jarFile = new JarFile(f);
                } catch (IOException e) {
                    logger.log(
                            Level.SEVERE,
                            "Unable to read a jre library while constructing the blacklist. Security restrictions may not be entirely emulated. "
                                    + f.getAbsolutePath());
                }
                continue;
    
                Enumeration<JarEntry> entries = jarFile.entries();
                while (entries.hasMoreElements()) {
                    JarEntry entry = (JarEntry) entries.nextElement();
                    String entryName = entry.getName();
                    if (entryName.endsWith(".class")) {
                        String className = entryName.replace('/', '.').substring(0,
                                entryName.length() - ".class".length());
                        if (isBlackListed(className)) {
                            blackList.add(className.replace('.', '/'));
                        }
                    }
                }
            }
            blackList = Collections.unmodifiableSet(blackList);
        }
    
        private static Set<File> getCurrentJreJars() {
            return getJreJars(System.getProperty("java.home"));
        }
    
        //REMOVED OTHER METHODS TO KEEP IT SHORT
    }
    

    d) appengine-tools-sdk-1.8.3.jar文件 :-它有一个名为 白名单 包括所有允许的JRE类。

    package com.google.apphosting.runtime.security;
    
    import java.util.Arrays;
    import java.util.HashSet;
    import java.util.Set;
    
    public class WhiteList {
        private static Set<String> whiteList = new HashSet(
                Arrays.asList(new String[] {
                        "java.beans.Transient",
                        "java.lang.BootstrapMethodError",
                        "java.lang.Character$UnicodeScript",
                        "java.lang.ClassValue",
                        "java.lang.SafeVarargs",
    
                        //Removed other classes to keep this article short
    
                        "java.net.URLClassLoader",
                        "java.security.SecureClassLoader",
                        "sun.net.spi.nameservice.NameService" }));
    
        public static Set<String> getWhiteList() {
            return whiteList;
        }
    }