180 Commits

Author SHA1 Message Date
Jaime van Kessel
b7ee3298c2
Add extra logging to auth server 2021-07-23 10:40:30 +02:00
Konstantinos Karmas
ceca0c417a Catch the KeyringLocked also when setting the token in the keyring
CURA-8332
2021-06-23 11:22:12 +02:00
Konstantinos Karmas
8ade68dbef Catch the KeyringLocked error instead of the MacOS specific
Turns out that when the KeychainDenied error is raised, it is being caught by the macOS keyring api and the non-macOS-specific KeyringLocked error is raised instead, so we need to catch this one.

CURA-8332
2021-06-23 11:20:35 +02:00
Konstantinos Karmas
f62a403f28 Really fix the mypy issue
Hopefully

CURA-8332
2021-06-21 17:20:36 +02:00
Konstantinos Karmas
4a8b5ae61e Fix mypy issue
CURA-8332
2021-06-21 17:07:36 +02:00
Konstantinos Karmas
9fd0ac333e Don't check against generic exception
Define the KeychainDenied exception locally in non-Mac operating systems.

CURA-8332
2021-06-21 16:47:47 +02:00
Konstantinos Karmas
7785142831 Log info instead of exception when keyring is denied on Mac
CURA-8332
2021-06-21 16:14:48 +02:00
Konstantinos Karmas
c3782c9468 Check for KeychainDenied Exception only on OSX
CURA-8332
2021-06-21 15:40:18 +02:00
Konstantinos Karmas
951c656096 Import they KeychainDenied exception only on Mac
CURA-8332
2021-06-21 10:55:22 +02:00
Konstantinos Karmas
c1618565ea Don't crash if keyring access is denied on MacOS
CURA-8332
2021-06-21 10:47:53 +02:00
Ghostkeeper
e60e44b919
Interpret timeouts as general connection errors
It's a similar problem for us.
We should really have used the HttpRequestManager for these things.

Fixes Sentry issue CURA-295.
2021-06-07 15:03:46 +02:00
fieldOfView
be06108f36 Fix an crash when starting Cura without a network connection 2021-05-24 18:43:05 +02:00
Kostas Karmas
07594f17a7 Fix setting empty auth tokens in the keyring on startup
When Cura is starting up, it reads the authentication data from the preferences (cura.cfg). If
the auth tokens have previously been stored in the keyring, it means that their values will be null
in the cura.cfg file. Therefore, on startup, Cura reads the tokens as none from the preferences and
then sets the empty values in the keyring as tokens. This leads to the user being signed off every
time Cura restarts on Mac.

On Windows, the access token was still stored in the preferences, so on startup it was safe. The
refresh token, on the other hand, had the same issue as on Mac, which means that on startup it was
read as None from the cura.cfg and was stored in the keyring as an empty string. This meant that,
even though on startup (on windows) the user was kept signed in, the next time Cura was attempting
to refresh the access token (after 7-8 minutes), it wouldn't be able, since its refresh token was
read as "" from the keyring. Also, if the user would close Cura and reopen it after 10 minutes
(so after the access token had expired) then they would be signed off on windows too.

This commit fixes that by making sure that if the given value of the refresh and access tokens are
empty, then they will not be stored in the keyring.

CURA-8178
2021-04-16 17:05:08 +02:00
Konstantinos Karmas
fe2d554ec0
Change the OS_X keyring backend module to macOS
Since the OS_X has been deprecated since keyring v22.0.0 and has been replaced by the macOS.

CURA-7180
2021-04-09 17:14:32 +02:00
Remco Burema
1c806199a4
Explicitly give keyring backend on Mac too.
CURA-7180
2021-04-08 14:08:35 +02:00
jelle Spijker
4b1087a138
Put BaseModel in quotes
Contributes to CURA-7180
2021-04-07 11:25:39 +02:00
jelle Spijker
33a812d696
Added typing fof KeyringAttributes
This should hopefully shut mypy up.

Contributes to CURA-7180
2021-04-07 11:06:06 +02:00
jelle Spijker
23ba1745a4
Handle storing None values in keyring
Write an empty string as value to the keyring if None is parsed and
return a None value if an empty string was parsed from the keyring.

CURA-7180_keyring_none_value
2021-04-04 12:27:43 +02:00
Remco Burema
e1490a68df
Also need to import this.
CURA-7180
2021-03-30 21:46:19 +02:00
Remco Burema
72248d47e1
Windows workaround for keyring issue.
So there is an issue with keyring w.r.t. frozen installs (maybe also local). If you have pywin32 installed, it works fine locally. Take a note here, that a variant of this package, pywin32-ctypes, a rudimentary version of that package that works wholly within python, is already installed as its a dependency for keyring on windows. Due to an unknown reason, when running it fails to detect this, so some workaround is needed, _or_ the 'normal' pywin32 package should be installed. However, problems occurred when attempts where made to install pywin32 via cx_freeze. Then the actual workaround was encountered (https://github.com/jaraco/keyring/issues/468), which _should_ hopefully let use use the keyring on windows without needing the 'full' version of pywin32.

CURA-7180
2021-03-30 20:40:33 +02:00
Remco Burema
bde88d7875
Don't store cerain keys ever.
CURA-7180
2021-03-30 17:24:25 +02:00
Kostas Karmas
fb5d59db32 Fix comment
The Windows Credential Manager actually fails if the password is more than 1024 bits long.

CURA-7180
2021-03-29 17:03:09 +02:00
Kostas Karmas
dbb15b7c71 Account for exception occured when storing long tokens on Windows
The Windows Credential Manager allows for up to 256bits passwords. If a password longer than that
is attempted to be written, it will throw a BaseException.

CURA-7180
2021-03-29 16:33:59 +02:00
Jelle Spijker
387fc36dc6
Small aesthetic code changes
CURA-7180 keyring storage
2021-03-17 09:30:31 +01:00
Jelle Spijker
c462b62edc
Handle raised error when there is no keyring backend present
CURA-7180 keyring storage
2021-03-17 09:22:24 +01:00
Jelle Spijker
b6b9dd1864
Fixed wrong typing
CURA-7180 keyring storage
2021-03-17 07:34:28 +01:00
Jelle Spijker
f51c466155
Use a descriptor to optionally store to Keyring
CURA-7180 keyring storage
2021-03-17 06:16:01 +01:00
Jelle Spijker
d06a25595a
Use a descriptor to optionally store to Keyring
CURA-7180 keyring storage
2021-03-16 19:28:56 +01:00
Jelle Spijker
6372fbed54
Added copyright notice
CURA-7180 keyring storage
2021-03-16 11:57:58 +01:00
Jelle Spijker
96e39810f2
Sync after log in works again
Needed to restore the access token after the
auth data was written to the preference file.

CURA-7180 keyring storage
2021-03-15 14:35:00 +01:00
Jelle Spijker
fcf698f00b
Added documentation and refactored
CURA-7180 keyring storage
2021-03-15 14:16:27 +01:00
Jelle Spijker
2796b9bef3
Store new keys to preference
CURA-7180 keyring storage
2021-03-15 13:06:42 +01:00
Jelle Spijker
b604bbd255
Store secrets as securely as possible
Use the keyring if allowed, available, otherwise use preference

CURA-7180 keyring storage
2021-03-15 11:48:42 +01:00
Jelle Spijker
47df060bee
Added fundaments of SecretStorage vault
This class will handle the storing and processing
of secrets. Such as tokens. It will try to use the system
keyring by default. Falling back to less secure methods,
if the user doesn't allow access to the keyring or if
the back-end is unsupported.

CURA-7180 keyring storage
2021-03-11 14:21:51 +01:00
Jelle Spijker
720b356221
Merge remote-tracking branch 'origin/master' into CURA-7180_keyring_storage 2021-03-08 15:23:46 +01:00
Jaime van Kessel
f85cad37cf
Expand the logging for the auth data a bit more
We're getting some reports that people are suddenly logged out. The working
theory is that they are mixing staging & production builds. This logging
should tell us enough to find out if that is the case!
2021-01-28 10:31:47 +01:00
Ghostkeeper
4380cdbd86
Don't crash on malformed JSON structures
JSON dictionaries need to have a certain structure such as strings as keys. If that's not correct it gives a TypeError. Don't crash on those; give a similar error message as when the values in the JSON are invalid.
2021-01-19 16:31:31 +01:00
Ghostkeeper
640e038ce7
Catch OSError when authorizing connection
Fixes Sentry issue CURA-1GW.
2021-01-19 11:05:55 +01:00
Remco Burema
a25a51eddb
Windows workaround for OAuth data removal from config.
Windows won't allow long keys in the backend the keyring python package uses as a backend. This means the access_token part can't be stored in the obvious way. Timeboxed some attempts at working around this limitation, but couldn't make it work within the time set. As this is mostly an extra precaustion protecting users that share config folders around against themselves (in other words, if this goes wrong it's not unreasonable to blame the user) it's not top critical, and the important part of that (the refresh_token) can proceed, giving any potential attacker only a 10 minute window from the moment any user shares their %appdata%/cura files (again, this is not how we intent for users to behave, but they can and will do it this way).

CURA-7180
2020-12-24 14:39:22 +01:00
Jaime van Kessel
bff3ba577b
Store auth & refresh key in keyring instead of in preferences
People tend to share configuration folders, which just isn't secure.

CURA-7180
2020-12-21 14:02:45 +01:00
Kostas Karmas
881e4406a4 Ensure the organization_id is None 2020-11-04 09:21:28 +01:00
Kostas Karmas
1521430d42 Include all subscription information in the slice data
CURA-7717
2020-10-14 11:43:22 +02:00
Kostas Karmas
ceda3e70bd Include organization id and type of enterprise plan in slice data
CURA-7717
2020-10-13 16:30:29 +02:00
Kostas Karmas
6d7d7bdb95 Fix local authorization server crashing
The thread handling the web_server was crashing. This in turn ended in
the web_server not being able to start again, thus being impossible to
login again if you logged out.
2020-06-11 15:27:29 +02:00
Nino van Hooff
f66e723866 Fix Authorization server not properly stopping after flow completes.
CURA-7490
2020-06-09 15:12:26 +02:00
Kostas Karmas
ea6a73e76d Fix mypy complains 2020-06-05 13:18:48 +02:00
Kostas Karmas
22b9bb77ef Fix reporting the [WinError 10038] exception traceback on sign-in
Surround the serve_forever function of the web server with a try-catch
on Windows, in order to avoid printing the entire (useless) traceback.
Now a warning message is be displayed in the log instead.

The behavior is untouched in other platforms
2020-06-05 12:59:31 +02:00
Nino van Hooff
89f0970a88 Remove trailing whitespace from Python files 2020-05-29 14:30:33 +02:00
Nino van Hooff
8e347c1034 Merge remote-tracking branch 'origin/doxygen_to_restructuredtext_comments' into doxygen_to_restructuredtext_comments
# Conflicts:
#	cura/OAuth2/AuthorizationService.py
2020-05-15 13:40:22 +02:00
Kostas Karmas
898ca852f0 Fix mypy complaint about Optional type
CURA-7427
2020-05-12 13:40:27 +02:00