I have the need to detect if the clock of a PC is drifting or is being manipulated in a standalone Java application, in an offline situation. How can I detect this?
The application will be in the hands of the users for least of 3 hours in a crowded room, I don't expect them to be skilled attackers and able to setup hacking environments. Mostly I wish to detect jumps at least of the magnitude of seconds.
I need to find a technique to keep track of time in a Java application, on a standalone workstation, that allows to detect significative "jumps" in the system clock, but at the same time to don't cause "false positives" on casual slowdonws.
It's not necessary for the solution to be resistant to skilled manipulations of source code or of the system clock. The application will be installed in thousands of workstations, but for a very limited amount of time (hours) and in a public situation. It's just a computer based testing sofware.
In the past we tried to set up an internal measurement of time using the System.nanoTime() and calculating elapsed time from repeated periodic System.nanoTime() calls. In that way we tought we could completely ignore any clock modification or problem. But it was a failure because on some machines (multicores) subsequent requests of the API returned values from random cores, making the measure impossibile.
So, now we try just to detect a sudden change in time, because some workstations have faulty clocks that reset themselves (yes it happens), some other do doimain clock updates during tests (the workstations should be not be networked but someone doesn't listen to our indications), and maybe some candidates will try to change system time.