有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安全Java应用程序同时包含未签名和已签名代码

我使用的是运行Java 1.7.0_21的Mac 10.7。我正在尝试运行一个已签名的Java小程序应用程序,在应用程序结束时,我会看到一个混合模式的安全弹出窗口,上面写着“阻止运行可能不安全的组件?”。我使用的所有罐子都有签名

我可以在运行Java 6的Mac 10.6上运行相同的小程序应用程序,但没有收到混合模式警告。我还可以在windows上运行该应用程序,而不会出现混合模式警告

当我所有的罐子都签名了,为什么我会一直收到这个错误

我在谷歌上搜索了混合模式警告,找到了这个链接

http://docs.oracle.com/javase/6/docs/technotes/guides/jweb/mixed_code.html#manifest

读完这个链接后,我有点困惑。根据这个链接,看起来我需要在清单文件中提到“仅受信任”或“受信任库”属性。我查看了我的清单文件,它们没有这些属性,所以我应该把它们放进去,还是仅仅是JAR被签名就足够了

有人能帮我理解为什么我在所有东西都签名的情况下也会出现这个错误吗


共 (4) 个答案

  1. # 1 楼答案

    谢谢大家的回复。我尝试在一个小样本上添加Trusted Library=true,结果似乎奏效了。所以现在我将尝试更新我所有JAR的清单文件。由于我们使用ant,我将执行以下操作

            <jar update="true" jarfile="${deploy.dir}/javaApp.jar">
                <manifest>
                    <attribute name="Trusted-Library" value="true" />
                </manifest>
            </jar>
    

    更新清单文件

  2. # 2 楼答案

    我还有一个小程序,它从JRE 1.7.0_21开始生成了这个安全警告

    以下是我学到的。如果不想让用户被询问是否允许调用另一个已签名的jar,则可以将“Trusted Only:true”放在小程序清单中。在没有安全警告的情况下,呼叫将被阻止。将“Trusted Library:true”添加到正在调用的jar中。如果这在jar的清单中,并且jar已签名,那么当小程序调用它时,不会出现安全警告,调用也不会被阻止

    我的小程序使用swing-layout-1.0.4。罐子为了解决这个问题,我不得不在swing-layout-1.0.4中添加“Trusted Library:true”。罐子你应该可以通过使用罐子来做到这一点。JDK中的exe应用程序

    jar vcmf swing-layout-1.0.4a。jar我的清单。mf swing-layout-1.0.4。罐子

    我的舱单。mf是一个包含“Trusted Library:true”的文本文件。:和true之间的空格很重要,必须在行尾有回车符

    由于某些原因,我无法实现这一点,所以我使用netbeans重建了swing布局。swing-layout-1.0.4的源代码是netbeans安装的一部分(在平台下)。我把它解压成了一个项目。在“文件”下,我更改了清单文件,使其具有魔术行(同样重要的是:后面有空格,清单文件末尾有空行),并点击构建。然后我在罐子上签名,不再发出安全警告

    我希望这对你有所帮助,或者至少为你指明了正确的方向

  3. # 3 楼答案

    最好的解决方法是使用Trusted-Library=true,但是,如果由于某种原因无法使其工作,也可以更改计算机处理混合安全小程序的方式

    http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/properties.html

    在用户工作站上创建follow文件C:\Windows\Sun\Java\Deployment\deployment.properties

    在文件中添加以下行: deployment.security.mixcode="HIDE_RUN"

    这将告诉Java隐藏安全警告,并在出现混合代码情况时运行小程序。此外,在发行说明上还写道:

    As of JDK 7u21, JavaScript code that calls code within a privileged applet is treated as mixed code and warning dialogs are raised if the signed JAR files are not tagged with the Trusted-Library attribute.

    For more information, see Mixing Privileged Code and Sandbox Code documentation.

    The JDK 7u21 release enables users to make more informed decisions before running Rich Internet Applications (RIAs) by prompting users for permissions before an RIA is run. These permission dialogs include information on the certificate used to sign the application, the location of the application, and the level of access that the application requests. For more information, see User Acceptance of RIAs.

    供参考,JRE 6u19如果小程序同时包含特权组件和沙盒组件,则会显示警告对话框

  4. # 4 楼答案

    Java 7的更新21是一个强大的安全更新,带来了一定数量的破坏性变化

    你应该看看它的release notes,有两个段落和两个已知问题与签名JAR有关

    你的问题在于:

    Area: deploy/plugin

    Synopsis: Security popup while closing application

    Starting in JDK 7u21, JavaScript code that calls code within a signed applet running with all permissions is treated as mixed code and warning dialogs are raised if the signed JAR files are not tagged with the Trusted-Library=true attribute. See Mixing Code With Permissions and Code Without Permissions(doc link)'.

    For a signed applet running with all permissions to JavaScript call, no security dialog (with mixed code warning) should pop up. However mixed code warning is being shown in some scenarios.

    好消息是:有一个解决办法:

    As a workaround, if the applet jar is running with all-permissions and uses "Trusted-library:true" attribute as manifest entry, the mixed code warning will not popup.