From 03d4d3e099ed86c1100542ebb75c3bedee316187 Mon Sep 17 00:00:00 2001 From: Florian Bach Date: Mon, 11 Jul 2022 18:16:36 +0200 Subject: [PATCH] Fix millisecond part in nonce calculation (fixes #27) --- calibre-plugin/__init__.py | 3 ++- calibre-plugin/libadobe.py | 6 ++---- tests/main.py | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index 5c6f57d..f4ec086 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -39,7 +39,8 @@ # drop dependencies python-cryptography, python-rsa and python-pyasn1. # add a ton of testing code, try to prevent AV false-positives, # experimental support for Python2 / Calibre < 5, -# fix broken URLs with missing protocol, fix loan data for loans without device ID. +# fix broken URLs with missing protocol, fix loan data for loans without device ID, +# fix nonce calculation yet again. PLUGIN_NAME = "DeACSM" PLUGIN_VERSION_TUPLE = (0, 0, 15) diff --git a/calibre-plugin/libadobe.py b/calibre-plugin/libadobe.py index 42bcca2..0b0cea0 100644 --- a/calibre-plugin/libadobe.py +++ b/calibre-plugin/libadobe.py @@ -447,11 +447,9 @@ def addNonce(): # every time a Nonce is needed. dt = datetime.utcnow() - usec = dt.microsecond sec = (dt - datetime(1970,1,1)).total_seconds() - - - Ntime = int(int(sec * 1000) + usec/1000) + Ntime = int(sec * 1000) + # Ntime is now milliseconds since 1970 # Unixtime to gregorian timestamp Ntime += 62167219200000 diff --git a/tests/main.py b/tests/main.py index 7c31b49..824f9c9 100755 --- a/tests/main.py +++ b/tests/main.py @@ -116,16 +116,17 @@ class TestAdobe(unittest.TestCase): '''Check if the nonce calculation is correct, at a given date/time''' nonce_return = libadobe.addNonce() - expected_return = "8B2aPgg6AAAAAAAA2021-12-18T22:17:15Z" + expected_return = "FBqaPgg6AAAAAAAA2021-12-18T22:17:15Z" self.assertEqual(nonce_return, expected_return, "Invalid nonce calculation in 2021") + @freeze_time("2031-07-19 22:15:22.074860") def test_verifyNonceCalculationFuture(self): '''Check if the nonce calculation is still correct in the future''' nonce_return = libadobe.addNonce() - expected_return = "JFUTp046AAAAAAAA2031-07-19T22:25:22Z" + expected_return = "2lQTp046AAAAAAAA2031-07-19T22:25:22Z" self.assertEqual(nonce_return, expected_return, "Invalid nonce calculation in 2031")