Fix millisecond part in nonce calculation (fixes #27)

This commit is contained in:
Florian Bach 2022-07-11 18:16:36 +02:00
parent b5978dc7c4
commit 03d4d3e099
3 changed files with 7 additions and 7 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 = "<adept:nonce>8B2aPgg6AAAAAAAA</adept:nonce><adept:expiration>2021-12-18T22:17:15Z</adept:expiration>"
expected_return = "<adept:nonce>FBqaPgg6AAAAAAAA</adept:nonce><adept:expiration>2021-12-18T22:17:15Z</adept:expiration>"
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 = "<adept:nonce>JFUTp046AAAAAAAA</adept:nonce><adept:expiration>2031-07-19T22:25:22Z</adept:expiration>"
expected_return = "<adept:nonce>2lQTp046AAAAAAAA</adept:nonce><adept:expiration>2031-07-19T22:25:22Z</adept:expiration>"
self.assertEqual(nonce_return, expected_return, "Invalid nonce calculation in 2031")