Question

How do I check if a .jar-File has a signature and how do I verify this signature in my code in order to make sure that my code is only executed with a specific library?

Was it helpful?

Solution

Not sure if your question is how to programatically check it yourself or if you refer to how make Java check it automatically for you.

For the second one, you can use the security features provided with Java. First, you must digitally sign your jar file (using jarsigner tool).

Then, you have to run your program with a security manager (System.setSecurityManager(new SecurityManager()).

Finally, you have to configure your security policy file to permit that only code signed by certain entity be run by your program.

grant signedBy "mrm" {
    permission ...
};

There is a tutorial in the Java Tutorial to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top