mirror of
https://github.com/Leseratte10/acsm-calibre-plugin.git
synced 2024-12-22 17:29:56 +06:00
Fix millisecond part in nonce calculation (fixes #27)
This commit is contained in:
parent
b5978dc7c4
commit
03d4d3e099
@ -39,7 +39,8 @@
|
|||||||
# drop dependencies python-cryptography, python-rsa and python-pyasn1.
|
# drop dependencies python-cryptography, python-rsa and python-pyasn1.
|
||||||
# add a ton of testing code, try to prevent AV false-positives,
|
# add a ton of testing code, try to prevent AV false-positives,
|
||||||
# experimental support for Python2 / Calibre < 5,
|
# 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_NAME = "DeACSM"
|
||||||
PLUGIN_VERSION_TUPLE = (0, 0, 15)
|
PLUGIN_VERSION_TUPLE = (0, 0, 15)
|
||||||
|
@ -447,11 +447,9 @@ def addNonce():
|
|||||||
# every time a Nonce is needed.
|
# every time a Nonce is needed.
|
||||||
|
|
||||||
dt = datetime.utcnow()
|
dt = datetime.utcnow()
|
||||||
usec = dt.microsecond
|
|
||||||
sec = (dt - datetime(1970,1,1)).total_seconds()
|
sec = (dt - datetime(1970,1,1)).total_seconds()
|
||||||
|
Ntime = int(sec * 1000)
|
||||||
|
# Ntime is now milliseconds since 1970
|
||||||
Ntime = int(int(sec * 1000) + usec/1000)
|
|
||||||
|
|
||||||
# Unixtime to gregorian timestamp
|
# Unixtime to gregorian timestamp
|
||||||
Ntime += 62167219200000
|
Ntime += 62167219200000
|
||||||
|
@ -116,16 +116,17 @@ class TestAdobe(unittest.TestCase):
|
|||||||
'''Check if the nonce calculation is correct, at a given date/time'''
|
'''Check if the nonce calculation is correct, at a given date/time'''
|
||||||
|
|
||||||
nonce_return = libadobe.addNonce()
|
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")
|
self.assertEqual(nonce_return, expected_return, "Invalid nonce calculation in 2021")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2031-07-19 22:15:22.074860")
|
@freeze_time("2031-07-19 22:15:22.074860")
|
||||||
def test_verifyNonceCalculationFuture(self):
|
def test_verifyNonceCalculationFuture(self):
|
||||||
'''Check if the nonce calculation is still correct in the future'''
|
'''Check if the nonce calculation is still correct in the future'''
|
||||||
|
|
||||||
nonce_return = libadobe.addNonce()
|
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")
|
self.assertEqual(nonce_return, expected_return, "Invalid nonce calculation in 2031")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user