Search code examples
javaclasssigner

What are signers of a class in Java?


The Class<?> class has a method public Object[] getSigners() whose JavaDoc is not so helpful in explaining what the method does; calling it on a couple of classes returned null for me.

Google only returned information about security exceptions, which did not mention about the signers of a class; I have seen there about this exceptions occurring when the same classes are loaded from multiple jars.

What exactly does the signer of a Java class represent? Is it some unique identifier provided by the JVM or by a tool when a Jar is signed?

There is tag for signer on StackOverflow but it's empty...


Solution

  • When you sign a .jar file in Java, the Toolsigner goes through it and recursively sign every file in the .jar. However, this is not limited to just one signer as you can sign a file with many different certificates. When you are verifying that a file is signed by the correct signer you can call the method getSigners() to return a list of all the signers who signed that class.