Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get system date/time via USB

Is there any way to query the system's date/time via USB without installing anything on the host computer (maybe just drivers)?


Background of the original problem

To avoid the XY problem, let me explain a bit what I'm trying to do.

To be able to calculate a TOTP token for 2FA (e.g. like Google Authenticator app does) you need a real-time clock to get the date and time.

There's this USB device called SC4-HSM that I would like to use to calculate the tokens, however it doesn't have a clock and according to the designer, adding one would be too expensive (needs a battery, etc).

Possible solution to the original problem

This device is going to be used with a computer which already has an RTC of course. Thus I had the idea of querying the system for a date/time which would solve the issue.

(Note: I know that a USB device can be connected to all sorts of hosts and not all hosts will have an RTC, but since this only needs to work with a computer, I thought this shouldn't be an issue)

My first thought was that there might be some USB device class that had date/time needs, so I could register the device as that type and then I would be able to query the values.

After going through the device class codes list (Internet Archive) nothing jumped at me as needing date/time. The closest ones I could think of were:

  • Content Security (PDF)
  • Personal Healthcare
  • Smart Card Class (PDF)

I skimmed the device class documents in the USB Implementers Forum but there's nothing in there even remotely related to date or time.

Current problem

Since the USB specs seemed like a dead-end I thought that maybe there was a way to write a very simple USB driver that can be auto-loaded when the device is plugged in to a computer and then we can use the driver to return the date/time when the device asks for it (unless I'm misunderstanding something).

I am now looking through USB development docs like Michael Opdenacker's Linux USB drivers course, I tried the Linux USB Project which seems dead. Skimmed through Driver Development for Windows NT just to get an idea, however I am still not able to figure out if this is possible or not, and how hard it would be.

I'm a complete beginner at this and maybe this is something out of my skill level, but I would like to figure out if will I need weird hacks and workarounds or is there a much more straightforward way to do this?

There seems to be little information about it or I'm just searching the wrong places.

Any ideas/or pointers on either solving the original problem or the current one?

like image 983
Acapulco Avatar asked Nov 26 '16 14:11

Acapulco


1 Answers

system time is not necessarily the general time i.e. the 'atomic' time you get from a NTP server

the most obvious solution is to use autorun, this is also possible on linux but normally autorun is blocked so the user explicitely has to activate it

https://askubuntu.com/questions/642511/how-to-autorun-files-and-scripts-in-ubuntu-when-inserting-a-usb-stick-like-autor

the linux command to get the time is date or hwclock or if the computer is connected to the net it may be possible to contact a NTP server (if the firewall does not block this)

then your autorun program has to send the data to the SC4-HSM. i do not know what USB classes the SC4-HSM implements if it implements CDC ACM (virtual COM port) this is easy: Unable to sync computer time to Arduino via USB

(something like echo "T$(($(date +%s)+60*60*$TZ_adjust))" >/dev/tty.usbmodemfa131)

maybe it is possible to access system time over the USB drivers, i do not know this right now

like image 151
ralf htp Avatar answered Sep 24 '22 01:09

ralf htp