apprenticeharper / DeDRM_tools

DeDRM tools for ebooks
14.47k stars 1.49k forks source link

Kindle for PC fails when username has non-ASCII characters #118

Closed apprenticeharper closed 6 years ago

apprenticeharper commented 8 years ago

I have had several reports that Kindle for PC fails when a username has an accented character. I have been able to reproduce this error, but I have unable to fix it - no matter what encoding or processing I do with the username I have been unable to find the right way to generate a working key.

I would like help in two ways

(1) Reports from anyone with a username that contains non-ASCII charcaters where Kindle for PC WORKS. (2) Suggestions from anyone who's traced through the current Kindle for PC on how a non-ASCII username should be processed.

FlyingDutchman12 commented 8 years ago

Probably half-off-topic, moving my profile to a plain-ASCII username worked for me - which might not be an option for everyone ...

apprenticeharper commented 7 years ago

If anyone has further information, I'd be pleased to hear it. I tried all the combinations of utf-8 and ASCII conversion that I could think of, and nothing seemed to do the trick.

Oh. I can't remember now whether I tried specifically a conversion to the local Windows 8-bit character set for utf-8. I'll give it a go when I can.

oneofusoneofus commented 7 years ago

The correct way to filter the user name is to replace non-ASCII characters with unichr(0xfffd) and encode in utf8. But since the DSN is stored in the kinf database and the purpose of the user name in K4PC decryption is to calculate the DSN it isn't really needed at all. The hashed user name is also present in the kinf database and is also not needed.

apprenticeharper commented 7 years ago

Very many thanks indeed!

apprenticeharper commented 7 years ago

Confirmed that that fixes the problem. I've found the DSN in the kinf database too, but not the hashed username. But I'll tweak the code to the the DSN if present as well.

oneofusoneofus commented 7 years ago

The hashed user name kinf key is UsernameHash. It was added to the list of known keys in the 6.5.4 Tools release. That combined with SerialNumber (the key for the hashed volume serial number) and MazamaRandomNumber can be used to calculate the DSN if it is not present.

Some other kinf keys that may be present are: kindle.accounttype.info, krx.flashcardsplugin.data.encryption_key, krx.notebookexportplugin.data.encryption_key, proxy.http.password, proxy.http.username

apprenticeharper commented 7 years ago

Many thanks again.

apprenticeharper commented 7 years ago

I have just uploaded a new version of the code for the plugin. The new plugin can be downloaded here:

https://github.com/apprenticeharper/DeDRM_tools/tree/master/DeDRM_calibre_plugin

I would appreciate feedback about this new version from anyone who's encountered this problem. Thank you.

ElleKayEm commented 7 years ago

Looks like issue #311 still had a problem with this.

apprenticeharper commented 6 years ago

Closing, as I think the problem is now solved.