views:

429

answers:

7

I wrote a software application in Java. Now I want to deliver it to my clients. But before that, I want to do something on that software which are mentioned below. You can answer any or all of the below questions:

I want to:

  1. Encrypt all the .class files so that no one can decompile it. How can I encrypt it?
  2. After encryption I want to obfuscate that code to add extra safety. How can I do that?
  3. Add some "serial-key" functionality so that the software works only after registering it with the key provided by me. This is very important so as to prevent multi-user usage of my software. How can I add that key functionality and how can I generate keys. And how can I restrict that software to work only on a single computer.
  4. The jar file can be unzipped and the .class file can be seen. Is there any way to wrap jar file into something so that no one can unzip that file.
  5. I don't want to tell the client to first install java to run my application. So is there any way by which if anyone installs my software, the java automatically gets installed on his/her computer without informing him that java is being installed to his computer. If it is possible, then Is it legal to use Java software in this way.
  6. Change the icon of the jar file permanently.
  7. Implement a code which checks my site for any available updates.

If you want any other suggestions to increase the security of the softwre, then you are welcomed too.

+6  A: 

Encrypt all the .class files so that no one can decompile it. How can I encrypt it?

You can't. If no one can decompile it, how do you expect the target JVM to?

After encryption I want to obfuscate that code to add extra safety. How can I do that?

I want to add some "serial-key" functionality so that the software works only after registering it with the key provided by me. This is very important so as to prevent multi-user usage of my software. How can I add that key functionality and how can I generate keys. And how can I restrict that software to work only on a single computer.

There are a couple of ways to do this but a simple one is with public key cryptography:

  • Your software generates a random request ID or a request ID based on the machine attributes and your user submits this to you.
  • You sign the request ID with your private key and send it back to the user.
  • The user provides the signed request ID to the software which validates that it was signed by you.

The jar file can be unzipped and the .class file can be seen. Is there any way to wrap jar file into something so that no one can unzip that file.

No

I don't want to tell the client to first install java to run my application. So is there any way by which if anyone installs my software, the java automatically gets installed on his/her computer without informing him that java is being downloaded to his computer. If it is possible, then Is it legal to use Java software in this way.

Try building an NSIS installer for your application that detects/installs Java and your program.

Kevin
Links to LMGTFY are frowned upon, warranted as they sometimes may be.
Rob Hruska
@Rob Sorry, even basic groundwork on that subject would have eliminated my snarky response. Perhaps if he asked for a comparison of the tools available or even search SO for java obfuscation he would have been better off.
Kevin
After encrytpting all the class files, I will decrypt it just before loading that class file at runtime so JVM will get decrypted .class files.
Yatendra Goel
+9  A: 

In no particular order:

2 - There are products that perform obfuscation. They typically rename classes / variables / methods to single letter names. This makes determining user reported errors rather difficult. Stack traces showing the exception occurs in a.b.c are not particularly helpful.

1,3,4 - You can't fully avoid this risk if your are distributing java. Your code needs to be unpacked and loaded at some point. If someone replaces rt.jar in the jvm then they can replace the top-level class loader and dump out your classes like that. Obfuscation makes this less useful for them, but see the above caveat.

5 - Distribute a "private jre". Basically, you have a jre in your program folder. Your launcher script runs it. Increases the size of your distribution though.

6 - On windows, this would be a file association issue. But that would also affect all other jar files. Unless as part of 4 (however you manage that) you also use a different extension. Not sure about other operating systems.

7 - Use Java Web Start? Failing that, just have a file on your server listing the most recent version, fetch the file and compare with the installed version.

For 1,2,4 and 5 you could also look into compiling to native code using gcj or similar. Beware of compatibility issues if you do that though.

developmentalinsanity
A: 

Just adding on to the other answers here:

1 and 4: You could actually do this if you modify the JVM and pre-package it with your installation, but it's against Java's license agreement to distribute a modified JVM without paying Sun like a billion dollars.

Alex Beardsley
+3  A: 

You can compile it with GCJ, which will compile your application to a normal Windows/Linux native executable (.exe). Then you can create an installation, using a program like InstallShield.

TTT
Beware that GCJ is an (incomplete? and not fully compatible) implementation of Java 1.4, it will not work if you used Java 5 syntax or libraries. I would not recommend using GCJ for serious software.
Jesper
+1  A: 

The company where I work actually ships unobfuscated jar files, with all debug information in place. That way, if an error occurs at a client's site, they can send us the full stacktrace which helps enormously in analyzing and localizing bugs in the code.

Trying to obfuscate your code will lead you into an arms race with potential crackers and consume huge amounts of time with little or no real benefit. Instead, I'd advise you to try and find other ways to make buying (and not pirating) your software worthwhile to your clients. For example, you could offer them free updates, or tech support, or something like that.


As for 6: You can use JSmooth or a similar tool to create an exe wrapper for your app. It will allow you to change the icon, and your clients will have an exe file that they can doubleclick without having to mess with file associations for jar files.
Note, however, that the generated exe won't contain Java or your jar files. It will, however, print a nice error message if Java isn't available.

jqno
+1 for the full stacktrace.
Francesco
+4  A: 

Build a better trust relationship with your clients.

Then you can spend extra time ( not doing tasks 1-5 ) to make improvements, fix bugs, etc., which in turn improves relationship with your clients.

Alexander Pogrebnyak
A: 

Who is your client? Piratebay.org? Seriously, every major company in the US pays for software. The risk of a client quitting and calling them in is just too high. You need enough protection to make it easier for a programmer to get purchasing to pay for the product than to circumvent your copy protection.

brianegge