10

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:

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?

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
Acapulco
  • 3,373
  • 8
  • 38
  • 51
  • what did you end up having to do in the end? I want to build a notification system, ideally it'd just plug into USB and somehow request timestamp from host – Ryan Jun 24 '19 at 01:14
  • 1
    I kind of hit a dead end. After extensive searching, it seems like there is no way to do this unfortunately, except by installing some sort of script or driver which in my case defeated the purpose of what I wanted to do, so I need to go find another route. – Acapulco Jun 25 '19 at 15:27

1 Answers1

2

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

Community
  • 1
  • 1
ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • Yes, that was actually something the designer suggested.Using a little script on the host to send the time to the device. That could work but I was wodnering if there was any other way possible. By the way, you have good point where system time is not the "NTP time". So most likely a script will be the answer – Acapulco Nov 28 '16 at 15:01
  • 1
    for the script solution see http://askubuntu.com/questions/284224/autorun-a-script-after-i-plugged-or-unplugged-a-usb-device. if the HSM device does not implement a virtual COM port (what i think is the case) you can either use *libusb* to send the date to one of the endpoints of the SC4-HSM (asynchronous transfer,...) or in windows you may have to write a driver for this because up from Win8 libusb is not working for windows anymore. – ralf htp Nov 28 '16 at 17:18