forked from CenterForOpenScience/gravyvalet
-
Notifications
You must be signed in to change notification settings - Fork 0
wip/proposal #1
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
Closed
Closed
wip/proposal #1
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import typing | ||
|
|
||
| from django.core.exceptions import ValidationError | ||
| from django.db import models | ||
|
|
||
| from addon_service.common import encryption | ||
| from addon_service.common.base_model import AddonsServiceBaseModel | ||
| from addon_service.common.dibs import dibs | ||
| from addon_toolkit.json_arguments import json_for_dataclass | ||
|
|
||
|
|
||
| _DATACLASS = typing.TypeVar("_DATACLASS") | ||
|
|
||
|
|
||
| class EncryptedDataclassModel(AddonsServiceBaseModel, typing.Generic[_DATACLASS]): | ||
| class Meta: | ||
| abstract = True | ||
|
|
||
| encrypted_json = models.BinaryField() | ||
| _salt = models.BinaryField() | ||
| _scrypt_block_size = models.IntegerField() | ||
| _scrypt_cost_log2 = models.IntegerField() | ||
| _scrypt_parallelization = models.IntegerField() | ||
|
|
||
| @classmethod | ||
| def new(cls): | ||
| # initialize key-parameter fields with fresh defaults | ||
| _new = cls() | ||
| _new.encryption_key_parameters = encryption.KeyParameters() | ||
| return _new | ||
|
|
||
| @property | ||
| def dataclass_type(self) -> type[_DATACLASS]: | ||
| raise NotImplementedError( | ||
| f"{self.__class__} requires a `dataclass_type` attribute or property" | ||
| ) | ||
|
|
||
| def rotate_encryption(self): | ||
| with dibs(self): | ||
| self.encrypted_json, self.encryption_key_parameters = ( | ||
| encryption.pls_rotate_encryption( | ||
| encrypted=self.encrypted_json, | ||
| stored_params=self.encryption_key_parameters, | ||
| ) | ||
| ) | ||
| self.save() | ||
|
|
||
| @property | ||
| def decrypted_dataclass(self) -> _DATACLASS: | ||
| return self.dataclass_type(**self.decrypted_json) | ||
|
|
||
| @decrypted_dataclass.setter | ||
| def decrypted_dataclass(self, value: _DATACLASS): | ||
| if not isinstance(value, self.dataclass_type): | ||
| raise ValidationError( | ||
| f"expected instance of {self.dataclass_type}, got {value}" | ||
| ) | ||
| self.decrypted_json = json_for_dataclass(value) | ||
|
|
||
| @property | ||
| def decrypted_json(self): | ||
| return encryption.pls_decrypt_json( | ||
| self.encrypted_json, self.encryption_key_parameters | ||
| ) | ||
|
|
||
| @decrypted_json.setter | ||
| def decrypted_json(self, value): | ||
| self.encrypted_json = encryption.pls_encrypt_json( | ||
| value, self.encryption_key_parameters | ||
| ) | ||
|
|
||
| @property | ||
| def encryption_key_parameters(self) -> encryption.KeyParameters: | ||
| return encryption.KeyParameters( | ||
| salt=self._salt, | ||
| scrypt_block_size=self._scrypt_block_size, | ||
| scrypt_cost_log2=self._scrypt_cost_log2, | ||
| scrypt_parallelization=self._scrypt_parallelization, | ||
| ) | ||
|
|
||
| @encryption_key_parameters.setter | ||
| def encryption_key_parameters(self, value: encryption.KeyParameters) -> None: | ||
| self._salt = value.salt | ||
| self._scrypt_block_size = value.scrypt_block_size | ||
| self._scrypt_cost_log2 = value.scrypt_cost_log2 | ||
| self._scrypt_parallelization = value.scrypt_parallelization |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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.
this won't work as token from
request.GET["oauth_token"]is different totemporary_oauth_tokenobtained before forming auth url. I tested it. If this wasn't a case, I would've implemented it in the same way as youThere 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.
hmm ok that seems to agree with example code in zotero docs, which uses the new token for the next request...
...but i've been confused because that seems to disagree with oauth1, both rfc-5849
and 1.0a
so i'd assumed the temporary token was meant to be shared across all the requests in a given auth attempt -- implementing zotero's way (with account id in the session) seems fine, since it supports services whether they use the temporary token once or twice
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 guess it indeed was, Zotero's just an exemption and the only OAuth1.0a service we have (as of now)