简体   繁体   English

注入 java 代理时出现 java.lang.SecurityException

[英]java.lang.SecurityException when injecting java agent

I am trying to create a dynamic java agent, but when the agent is loaded this error is thrown:我正在尝试创建一个动态 java 代理,但是当加载代理时,会抛出此错误:

com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize
    at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:165)
    at jdk.attach/com.sun.tools.attach.VirtualMachine.loadAgent(VirtualMachine.java:538)
    at injector.main(injector.java:20)

And this is the error that is shown on the target application:这是目标应用程序上显示的错误:

java.lang.SecurityException: class "agent"'s signer information does not match signer information of other classes in the same package
  at java.base/java.lang.ClassLoader.checkCerts(ClassLoader.java:1151)
  at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:906)
  at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1015)
  at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
  at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
  at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
  at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:431)
  at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallAgentmain(InstrumentationImpl.java:535)

The agent has no code that could possibly trigger the error because right now it is a single System.out.println statement for testing.代理没有可能触发错误的代码,因为现在它是用于测试的单个 System.out.println 语句。 I use this code to inject the agent:我使用此代码注入代理:

VirtualMachine vm = VirtualMachine.attach(vmd);
vm.loadAgent("myagentpath");
vm.detach();

The target application is running a normal distribution of java.目标应用程序正在运行 Java 的正态分布。 I do not believe that it is an issue with my code.我不相信这是我的代码的问题。 Does anyone know what could be causing this?有谁知道是什么原因造成的?

signer information does not match signer information of other classes in the same package签名者信息与同一包中其他类的签名者信息不匹配

This happens when classes belonging to the same package are loaded from different JAR files present on the classpath, 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.当属于同一包的类从存在于类路径中的不同 JAR 文件中加载,并且这些 JAR 文件具有使用不同证书签名的签名时,就会发生这种情况 - 或者,可能更常见的是,至少一个已签名而一个或多个未签名。 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 文件的清单中删除签名。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM