Fix username code for ADE key retrieval #1946
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There have been lots of reports of the error message "Failed to decrypt user key key (sic)" in the past. Looking at the source code, this error occurs when the Windows API call to
CryptUnprotectData
fails. This can happen if the entropy data is wrong.ADE uses the Windows user name as part of that entropy data, and the script previously used the Windows API function
GetUserNameW
to retrieve the user's current user name.However, this breaks when the user account has been renamed between ADE install and plugin usage. The key will be encrypted using the old name as entropy, but the python script will try to decrypt the key with the new current name, which will obviously fail.
Thankfully, ADE stores the user name (as it was at authorization time) in the registry - probably because ADE needs that info itself to access the key, so all that's needed to fix this is to read the user name from the registry instead of relying on Windows API.
This should be a proper fix (rather than the current workaround of "reinstall and re-authorize ADE") for #186, #252, #262, #278, #309, #348, #349, #371, #436, #471, #668, #708, #759, #815, #902, #1109, #1144, #1395 and #1938, all of which seem to be duplicates of eachother.