简体   繁体   English

Java SecurityException:签名者信息不匹配

[英]Java SecurityException: signer information does not match

I recompiled my classes as usual, and suddenly got the following error message.我像往常一样重新编译我的类,突然收到以下错误消息。 Why?为什么? How can I fix it?我该如何解决?

java.lang.SecurityException: class "Chinese_English_Dictionary"'s signer information does not match signer information of other classes in the same package
    at java.lang.ClassLoader.checkCerts(ClassLoader.java:776)

This happens when classes belonging to the same package are loaded from different JAR files, and those JAR files have signatures signed with different certificates - or, perhaps more often, at least one is signed and one or more others are not (which includes classes loaded from directories since those AFAIK cannot be signed).当属于同一个包的类从不同的 JAR 文件加载,并且这些 JAR 文件具有使用不同证书签名的签名时,就会发生这种情况 - 或者,可能更常见的是,至少一个已签名而一个或多个未签名(包括加载的类)来自目录,因为那些 AFAIK 无法签名)。

So either make sure all JARs (or at least those which contain classes from the same packages) are signed using the same certificate, or remove the signatures from the manifest of JAR files with overlapping packages.因此,要么确保所有 JAR(或至少那些包含来自相同包的类)都使用相同的证书进行签名,或者从具有重叠包的 JAR 文件的清单中删除签名。

A simple way around it is just try changing the order of your imported jar files which can be done from (Eclipse).一个简单的方法是尝试更改导入的 jar 文件的顺序,这可以从(Eclipse)完成。 Right click on your package -> Build Path -> Configure build path -> References and Libraries -> Order and Export.右键单击您的包 -> 构建路径 -> 配置构建路径 -> 引用和库 -> 订购和导出。 Try changing the order of jars which contain signature files.尝试更改包含签名文件的 jar 的顺序。

A. If you use maven, an useful way to debug clashing jars is: A. 如果您使用 maven,调试冲突 jar 的一种有用方法是:

mvn dependency:tree

For example, for an exception:例如,对于异常:

java.lang.SecurityException: class "javax.servlet.HttpConstraintElement"'s signer information does not match signer information of other classes in the same package

we do:我们的确是:

mvn dependency:tree|grep servlet

Its output:它的输出:

[INFO] +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] |  +- org.eclipse.jetty.orbit:javax.servlet.jsp:jar:2.2.0.v201112011158:compile
[INFO] |  +- org.eclipse.jetty.orbit:javax.servlet.jsp.jstl:jar:1.2.0.v201105211821:compile
[INFO] |  +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile
[INFO] +- org.eclipse.jetty:jetty-servlet:jar:9.0.0.RC2:compile

shows clashing servlet-api 2.5 and javax.servlet 3.0.0.x.显示了 servlet-api 2.5 和 javax.servlet 3.0.0.x 的冲突。

B. Other useful hints (how to debug the security exception and how to exclude maven deps) are at the question at Signer information does not match . B. 其他有用的提示(如何调试安全异常以及如何排除 maven deps)位于Signer information does not match 的问题

就我而言,我在我的库路径中复制了 BouncyCastle 的 JAR 版本:S

I had a similar exception:我有一个类似的例外:

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package

The root problem was that I included the Hamcrest library twice.根本问题是我两次包含 Hamcrest 库。 Once using Maven pom file.一旦使用 Maven pom 文件。 And I also added the JUnit 4 library (which also contains a Hamcrest library) to the project's build path.我还在项目的构建路径中添加了 JUnit 4 库(它还包含一个 Hamcrest 库)。 I simply had to remove JUnit from the build path and everything was fine.我只需要从构建路径中删除 JUnit,一切都很好。

使用 cglib 检测的代理可能会发生这种情况,因为 CGLIB 使用他自己的签名者信息而不是应用程序目标类的签名者信息。

  1. After sign, access: dist\\lib签名后,访问:dist\\lib
  2. Find extra .jar查找额外的 .jar
  3. Using Winrar, You extract for a folder (extract to "folder name") option使用 Winrar,您可以提取文件夹(提取到“文件夹名称”)选项
  4. Access: META-INF/MANIFEST.MF访问: META-INF/MANIFEST.MF
  5. Delete each signature like that:像这样删除每个签名:

Name: net/sf/jasperreports/engine/util/xml/JaxenXPathExecuterFactory.c lass SHA-256-Digest: q3B5wW+hLX/+lP2+L0/6wRVXRHq1mISBo1dkixT6Vxc=名称:net/sf/jasperreports/engine/util/xml/JaxenXPathExecuterFactory.class SHA-256-Digest:q3B5wW+hLX/+lP2+L0/6wRVXRHq1mISBo1dkixT6Vxc=

  1. Save the file保存文件
  2. Zip again再次压缩
  3. Renaime ext to .jar back重命名 ext 到 .jar 回来
  4. Already已经

I am having this problem with Eclipse and JUnit 5. My solution is inspired by the previous answer by user2066936 It is to reconfig the ordering of the import libraries:我在使用 Eclipse 和 JUnit 5 时遇到了这个问题。我的解决方案的灵感来自 user2066936 之前的回答,它是重新配置导入库的顺序:

  1. Right click the project.右键单击项目。
  2. Open [Java Build Path].打开[Java 构建路径]。
  3. Click Order and Export.单击订购和导出。
  4. Then push JUNIT to upper priority.然后将 JUNIT 推到更高的优先级。

If you're running it in Eclipse, check the jars of any projects added to the build path;如果您在 Eclipse 中运行它,请检查添加到构建路径的任何项目的 jar; or do control-shift-T and scan for multiple jars matching the same namespace.或者执行 control-shift-T 并扫描匹配相同命名空间的多个 jar。 Then remove redundant or outdated jars from the project's build path.然后从项目的构建路径中删除多余或过时的 jar。

In my case it was a package name conflict.就我而言,这是包名称冲突。 Current project and signed referenced library had one package in common package.foo.utils .当前项目和签名引用库在公共package.foo.utils有一个包。 Just changed the current project error-prone package name to something else.只是将当前项目容易出​​错的包名称更改为其他名称。

A bit too old thread but since I was stuck for quite some time on this, here's the fix (hope it helps someone)有点太旧了,但由于我在这方面被困了很长一段时间,这是修复程序(希望它可以帮助某人)

My scenario:我的场景:

The package name is : com.abc.def.包名是:com.abc.def。 There are 2 jar files which contain classes from this package say jar1 and jar2 ie some classes are present in jar1 and others in jar2.有 2 个 jar 文件包含来自这个包的类,比如 jar1 和 jar2,即一些类存在于 jar1 中,而另一些类存在于 jar2 中。 These jar files are signed using the same keystore but at different times in the build (ie separately).这些 jar 文件使用相同的密钥库进行签名,但在构建中的不同时间(即单独使用)。 That seems to result into different signature for the files in jar1 and jar2.这似乎导致 jar1 和 jar2 中的文件具有不同的签名。

I put all the files in jar1 and built (and signed) them all together.我将所有文件放在 jar1 中并将它们全部构建(并签名)在一起。 The problem goes away.问题消失了。

PS: The package names and jar file names are only examples PS:包名和jar文件名只是示例

If you added all the jars from bouncycastle.org (in my case from crypto-159.zip), just remove the ones for the JDKs that do not apply to you.如果您添加了来自 bouncycastle.org 的所有 jar(在我的例子中来自 crypto-159.zip),只需删除那些不适用于您的 JDK。 There are redundancies.有冗余。 You probably only need the "jdk15on" jars.您可能只需要“jdk15on”罐子。

This question has lasted for a long time but I want to pitch in something.这个问题已经持续了很长时间,但我想说点什么。 I have been working on a Spring project challenge and I discovered that in Eclipse IDE.我一直在处理 Spring 项目挑战,我在 Eclipse IDE 中发现了这一点。 If you are using Maven or Gradle for Spring Boot Rest APIs, you have to remove the Junit 4 or 5 in the build path and include Junit in your pom.xml or Gradle build file.如果您将 Maven 或 Gradle 用于 Spring Boot Rest API,则必须删除构建路径中的 Junit 4 或 5,并在 pom.xml 或 Gradle 构建文件中包含 Junit。 I guess that applies to yml configuration file too.我想这也适用于 yml 配置文件。

如果您两次包含一个具有不同名称或来自不同位置的文件,也会发生这种情况,尤其是当它们是同一文件的两个不同版本时。

I could fix it.我可以解决它。

Root Cause: This is a common issue when using the Sun JAXB implementation with signed jars.根本原因:这是使用带有签名 jar 的 Sun JAXB 实现时的常见问题。 Essentially the JAXB implementation is trying to avoid reflection by generating a class to directly access the properties without using reflection.本质上,JAXB 实现试图通过生成一个类来直接访问属性而不使用反射来避免反射。 Unfortunately, it generates this new class in the same package as the class being accessed which is where this error comes from.不幸的是,它在与被访问的类相同的包中生成了这个新类,这就是这个错误的来源。

Resolution: Add the following system property to disable the JAXB optimizations that are not compatible with signed jars: -Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true解决方案:添加以下系统属性以禁用与签名 jar 不兼容的 JAXB 优化:-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true

Ref: https://access.redhat.com/site/solutions/42149参考: https : //access.redhat.com/site/solutions/42149

根据@Mohit Phougat 的响应,如果您正在运行带有 @Grab 注释的 Groovy,您可以尝试重新排序此类注释。

this happened to me when using JUnit + rest assured + hamcrest, in this case, dont add junit to build path, if you have the maven project, this resolved me, below is the pom.xml这发生在我使用JUnit +放心+ hamcrest时,在这种情况下,不要添加junit来构建路径,如果您有maven项目,这解决了我,下面是pom.xml

<dependencies>

    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>3.0.0</version>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>

    </dependency>


</dependencies>

I was running JUNIT 5 and was also referencing Hamcrest external jar.我正在运行JUNIT 5并且还引用了 Hamcrest 外部 jar。 But Hamcrest is also part of JUNIT 5 library.但 Hamcrest 也是JUNIT 5库的一部分。 So, I have to change the order of external Hamecrest jar file up the JUNIT 5 library in build path.因此,我必须在构建路径中更改JUNIT 5库中外部 Hamecrest jar 文件的顺序。

在此处输入图片说明

I was getting a similar error when trying to use Mockito:我在尝试使用 Mockito 时遇到了类似的错误:

"$$FastClassByMockitoWithCGLIB$$abb8f5a0"'s signer information does not match signer information of other classes in the same package"

I was using an old version of Mockito, and upgrading to the latest Mockito version solved this problem.我用的是老版本的Mockito,升级到最新的Mockito版本解决了这个问题。 The issue was with CGLIB as mentioned in one of the other answers.如其他答案之一所述,问题出在 CGLIB 上。 In newer versions, Mockito replaces CGLIB with ByteBuddy, and so the problem goes away.在较新的版本中,Mockito 将 CGLIB 替换为 ByteBuddy,因此问题消失了。 I also had to add the new ByteBuddy jars to the classpath in Eclipse to get Mockito working again.我还必须将新的 ByteBuddy jars 添加到 Eclipse 的类路径中,以使 Mockito 再次工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.SecurityException AWSCredentialsProvider 签名者信息不匹配 - java.lang.SecurityException AWSCredentialsProvider Signer Information Does Not Match java.lang.SecurityException: signer information does not match other classes in the same package in PowerMock 中的签名者信息与其他类的签名者信息不匹配 - java.lang.SecurityException: signer information does not match signer information of other classes in the same package in PowerMock java.lang.SecurityException:签名者信息与同一包中其他类的签名者信息不匹配 - java.lang.SecurityException: signer information does not match signer information of other classes in the same package java.lang.SecurityException:类“XYZ”的签名者信息与同一包中其他类的签名者信息不匹配 - java.lang.SecurityException: class “XYZ”'s signer information does not match signer information of other classes in the same package java.lang.SecurityException:类“ org.eclipse.core.runtime.PlatformObject”的签名者信息与签名者信息不匹配 - java.lang.SecurityException: class “org.eclipse.core.runtime.PlatformObject”'s signer information does not match signer information Applet:Java.lang.SecurityException:类“…”的签名者信息与同一包中其他类的歌手信息不匹配 - Applet: Java.lang.SecurityException: class “…”'s signer information does not match singer information of other classes in the same package 签名者信息不匹配 - Signer information does not match 签名者信息与同一个其他类的签名者信息不匹配 package - Signer information does not match signer information of other classes in the same package JMockIt安全异常签名者信息不匹配 - JMockIt security exception signer information does not match 启动程序后CGLIB错误(签名者信息与同一软件包中其他类的签名者信息不匹配) - CGLIB error after launching program (signer information does not match signer information of other classes in the same package)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM