KeyCheck should be verified when attempting user keys from vault storage (currently only from initial passphrase) #51
Description
The KeyCheck is correctly verified in DecryptUserKey()
:
readium-lcp-client/src/lcp-client-lib/CryptoppCryptoProvider.cpp
Lines 232 to 276 in e4c02fd
However, it should also be verified in DecryptContentKey()
:
readium-lcp-client/src/lcp-client-lib/CryptoppCryptoProvider.cpp
Lines 278 to 310 in e4c02fd
The only reason why the current code "works" is because of a fortunate side effect from the CryptoPP lib, which emits an error when an attempt to decrypt a cypher using the wrong key is made, because of incorrect padding number parsing:
The source of the problem is DecryptLicenseByStorage()
:
readium-lcp-client/src/lcp-client-lib/LcpService.cpp
Lines 410 to 459 in e4c02fd
...more specifically m_storageProvider->EnumerateVault
which will find the first existing user key that "works", without actually verifying the KeyCheck!
This is the call chain:
OpenLicense()
=> CheckDecrypted()
=> DecryptLicenseOnOpening()
=> DecryptLicenseByStorage()
Then DecryptLicenseByUserKey()
=> DecryptContentKey()
where the KeyCheck verification is missing. Thankfully, we have the CryptoPP "crash" to simulate the KeyCheck verification, but this is VERY hacky!
The line that crashes:
...is caught here:
readium-lcp-client/src/lcp-client-lib/CryptoppCryptoProvider.cpp
Lines 306 to 309 in e4c02fd
...which allows graceful continuation of the m_storageProvider->EnumerateVault
iteration, here:
readium-lcp-client/src/lcp-client-lib/LcpService.cpp
Lines 454 to 456 in e4c02fd