0

I am building some java jar building through Maven but I need to put certain time stamp that should make that JAR expired with certain date that is fixed/provided in the JAR.

Thanks Kumar Shorav

Kumar
  • 955
  • 5
  • 20
  • 50
  • 2
    if ( currentDate >= expectedDate ) crash(); But that would be very easy to cheat out of. just unzip the jar, alter the condition or remove it alltogether, and presto – Stultuske Sep 12 '19 at 07:24
  • @Stultuske Thank U for your quick response. I have to distribute it like trail version, say for 30 days and then it should be expired. – Kumar Sep 12 '19 at 07:27
  • @Stultuske How to build or is there any maven lib? – Kumar Sep 12 '19 at 07:27
  • 1
    there are no easy ways to do so that can not be tampered with. after all, a simple: "change system date" would trick it – Stultuske Sep 12 '19 at 07:28
  • @Stultuske any other way to handle the expiry of JAR after a certain date? – Kumar Sep 12 '19 at 07:29
  • Does it have to be distributed as a stand-alone application? – Stultuske Sep 12 '19 at 07:29
  • @Yes, It should be standalone JAR – Kumar Sep 12 '19 at 07:30
  • here are a few links that might help you: https://stackoverflow.com/questions/2769384/how-to-create-a-trial-version-of-a-java-program https://jfxstore.com/stringer/blog/creating-time-limited-trial-java-applications-stringer-java-obfuscator – Stultuske Sep 12 '19 at 07:32
  • @Stultuske I have seen this. :). But we need some free tool. – Kumar Sep 12 '19 at 07:33
  • Do it in code, and get the actual time from the internet, if connected ? – jr593 Sep 12 '19 at 07:38
  • @jr593 This is still easy to cheat by unzipping the jar and removing the `if time has expired` condition. – byxor Sep 12 '19 at 08:13
  • 1
    If you want 100% control over the expiry of a piece of code, you can run the jar file in a server somewhere and let people interact with it via HTTP or some other communication protocol. This cannot be cheated easily, although it won't work very well if many people need to use the service you're providing. And it won't work if your service needs to interact with the filesystem etc. – byxor Sep 12 '19 at 08:15

1 Answers1

-1

There are several ways:

  • The easy way: hardcoded.
  • Properties
  • The distributed way
  • Buy a tool
  • Search a free tool
  • Build a tool

Hardcoded

Somewhere in your code, you'll have

if (currentDate > hardcodedDate) System.exit(0);
runYourCode();

This is pointless. For everybody who knows about decompilation, it's an easy trick to change that to:

// if (currentDate > hardcodedDate) System.exit(0);
runYourCode();

Properties

In a properties file, you keep the number of days it should work. On startup of your application, you check whether or not a certain file exists. If it doesn't -> create it, and put nothing in it but your current system date. On every next startup:

Date check = readDateFromFile();
if ( currentDate > check + numberOfDays ) System.exit(0);

Again, easily faked. All you need to do is delete the created file, turn back the system date, ...

Distributed

This is what I would at least consider. Distributing all your code means it can be copied as much as the user wants. Tricky business, since if they know your code, they can alter it.

Create a client that contacts the service that handles your business logic. Make sure each client has a 'key', whether it's hardcoded or in a properties file, this is irrelevant. In your db, keep a list of all the keys, both trial and real ones. For the trial keys, at the moment of first use, you add a value in the DB -> current system date + numberOfDaysAllowed. On every other use, check that value against the system date (not the system date of the client, but of your server). Date reached? delete the trial key from the db, or set a flag 'Expired' to true. Then, check if it the serial is in the DB, if it is, whether the flag is expired. If the serial is not in the DB, or the flag is expired, terminate program. The client might try to tamper with the key, but if he does, the key won't be recognized in your system (map it to a user, if you want to be more sure), and 'll fail anyway.

Buy a tool

Let's face it, people who create software to do this, also need to earn their income

Search a free tool

In the thread I linked to, there's a link to this page: trial maker, which seems to be free.

Build a tool

If you don't want to buy a tool, and you aren't satisfied with any existing free tool, feel free to build your own.

Stultuske
  • 9,296
  • 1
  • 25
  • 37