-
Notifications
You must be signed in to change notification settings - Fork 31
Provide catch-able exceptions for 2 dpapi errors #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,15 @@ def raw(self): | |
_MEMCPY(blob_buffer, pb_data, cb_data) | ||
return blob_buffer.raw | ||
|
||
_err_description = { | ||
# Keys came from real world observation, values came from winerror.h (http://errors (Microsoft internal)) | ||
-2146893813: "Key not valid for use in specified state.", | ||
-2146892987: "The requested operation cannot be completed. " | ||
"The computer must be trusted for delegation and " | ||
"the current user account must be configured to allow delegation. " | ||
"See also https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/enable-computer-and-user-accounts-to-be-trusted-for-delegation", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think common users can understand this enigma. They are still non-actionable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is arguably true. (TBH, that link was a TL;DR for me. LOL.) But my thoughts were:
|
||
13: "The data is invalid", | ||
} | ||
|
||
# This code is modeled from a StackOverflow question, which can be found here: | ||
# https://stackoverflow.com/questions/463832/using-dpapi-with-python | ||
|
@@ -82,7 +91,7 @@ def protect(self, message): | |
_LOCAL_FREE(result.pbData) | ||
|
||
err_code = _GET_LAST_ERROR() | ||
raise OSError(256, '', '', err_code) | ||
raise OSError(None, _err_description.get(err_code), None, err_code) | ||
|
||
def unprotect(self, cipher_text): | ||
# type: (bytes) -> str | ||
|
@@ -111,4 +120,4 @@ def unprotect(self, cipher_text): | |
finally: | ||
_LOCAL_FREE(result.pbData) | ||
err_code = _GET_LAST_ERROR() | ||
raise OSError(256, '', '', err_code) | ||
raise OSError(None, _err_description.get(err_code), None, err_code) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,7 @@ envlist = py27,py35,py36,py37,py38 | |
deps = pytest | ||
passenv = | ||
TRAVIS | ||
GITHUB_ACTIONS | ||
|
||
commands = | ||
pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have some knowledge on WinError 0 (Azure/azure-cli#20278)?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. The "error 0" is particularly strange. The zero is supposed to mean success.
Regardless, like I admitted here, these error description are still more like troubleshooting trace. I should probably change this PR's title to "Provide catch-able exceptions for all dpapi errors". Eventually Azure CLI might still need to catch them and then tell end user "just turn off encryption by configuring ~/.azure/..." (such a very actionable sentence can not be provided by this MSAL EX package, anyway.)