views:

124

answers:

7

Hi,

I was reading about the licensing of software and one question that came to my mind is that "how software detect the change in system time and block themselves if someone changes system time?". Since there is no other reference available(provided we don't have internet connection, otherwise we can use time servers as reference), how such software manages to do it? Are there standard algorithms or any standard libraries(C/C++) available for implementing the same. Please suggest.

Thanks in advance, Ravi Gupta

A: 

You can set up a timer that checks every n ticks (one tick = one (multitude of) cpu clock tick) if the system time difference is positive... Should be enough to check every second or even once a minute. Usually a timer shouldn't use up that much resources. You must make sure though that the timer uses the ticks, not the system clock...

Martin
What happens when the ticks reach the greatest possible value and go back to 0 ?
ereOn
I don't understand your question - if I have a timer that uses the cpu cycles as a counter, I expect it to deal with any of these possible oddities - after all: What sense would it make to call it a timer then?
Martin
But this would only work over the lifetime of the application or service, wouldn't it?
detly
That's correct - and it's how I understand the question "how software detect the change in system time and block themselves if someone changes system time?". Feel free to correct me there.
Martin
@Martin: My apologies. I read this too quickly. Thought you were suggesting to use the system ticks count as a reference to check for time change.
ereOn
+1  A: 

Your software can regularly ask for system time (using boost::posix_time::second_clock::local_time()) and compare it with the last stored value. If you observe a significant negative difference, someone probably changed the system time.

Beware that time can be changed on a system for legitimate reasons : the computer can be moved to another timezone, the system can be using NTP and the computer clock is ticking too fast so NTP very often sets time to an earlier value or when daylight saving time change occurs.

Keep also in mind that those kind of "protection" aren't really effective in practice. If you have to store the last system date somewhere, you take the risk that someone will find where and change it to something in a far future to grant himself new licensing rights.

As far as I know, there is no elegant and reliable solution to this problem.

ereOn
There's no risk that someone will find it; it is a certainty that if they want to use the software despite the restriction, they *will* find it. And the keys used to encrypt it if that's what you do.
Jonathan Leffler
A: 

clock_gettime(CLOCK_MONOTONIC, &ts) gives you a timespec independent of the system time. You can use it to calc an offset between CLOCK_REALTIME and if that changes, your systemtime has changed

falloutboy
This only works during a single boot though. `CLOCK_MONOTONIC` can reset at boot.
caf
right, I misread the question a bit. The only way I can think of, is to store an UTC timestamp somewhere in an unalterable way (somehow) and compare it to the current one
falloutboy
A: 

Generally you can't detect such things consistently, since people may just reboot the machine in question.

In an ancient place I was working once an admin changed the clock because he had forgotten to renew the license for a compiler. Not really a brilliant idea. Basically the machine soon became completely unusable: NFS was messed up, make didn't work, a lot of trouble.

So my guess is that your problem is more of theoretical nature. In real life, nobody sane will probably do that.

Jens Gustedt
`make` not working after a clock change ?! That seems weird.
ereOn
@ereOn: "not working" is perhaps the wrong term. But `make` is much sensible on file dates, so it gets much confused when you have NFS mounts with completely inconsistent dates.
Jens Gustedt
A: 

You could always set the timestamp on a file to the current system time every time your application starts.

Check the time first before setting it - if it's in the future, then the clock has gone backwards since you last set it.

caf
+3  A: 

You cannot assume that because the clock goes backwards, it is caused by someone trying to circumvent your licensing.

Consider, for example, the situation where someone accidentally sets the clock way into the future, then resets it to the correct time?

Crippling your software by attempting to time-restrict it is not the right thing to do. Consider making decent software instead.

MarkR
A: 

One strategy I have read about in the past is to create, update and check a file in a folder. You can update the date as it changes and if it goes backwards you leave it alone and can get suspicious.

However there is no 100% method of proving time shifting, in my limited experience any piracy feature usually hurts the helpdesk and your customers more than it hurts the pirates.

It is a far better strategy to get to know your trial users than to criminalise them.

Phil Hannent