-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add Encryption methods. #390
Merged
Merged
Conversation
This file contains 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
4 tasks
pkevan
approved these changes
Apr 12, 2023
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.
Tested via WordPress/wporg-two-factor#103 (comment)
…ario that should be needed.
…'s return value as a result.
…thrown specifically. Ensures that test functions throwing unexpected Errors are caught.
xknown
reviewed
Apr 17, 2023
…value from a function. This allows them to be stored as HiddenString's.
…e name/slug of a key, rather than the actual key value.
… need to be worried about that being the input.
dd32
added a commit
to WordPress/wporg-two-factor
that referenced
this pull request
Apr 18, 2023
Thanks for the review @xknown, I've made changes to reflect that. |
xknown
approved these changes
Apr 19, 2023
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.
LGTM.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This adds a new set of Encryption methods based off of other implementations of it.
There are two methods to use it, the namespaced methods which throw specific exceptions, or the globally-defined functions that operate as "standard PHP" (which are detailed below)
It uses Additional Data ciphers (AEAD with XChaCha20-Poly1305) via the Sodium library and supports multiple keys
Using
$context
(Additional Data) is required, and should be either set to a per-user/site/post value or to a per-feature unique token.For example, two keys could be defined
wporg_encrypt( $string, (string) $user_id )
&wporg_decrypt( $encrypted_value, (string) $user_id )
wporg_encrypt( $string, (string) $user_id, 'plugins' )
&wporg_decrypt( $encrypted_value, (string) $user_id, 'plugins' )
This is based off a combination of WordPress/two-factor#389 and an Automattic implementations of it.
This has not been unit tested, and does not include any yet.This has not been written with the intention of running on older versions of WordPress or PHP.
This has not been peer-reviewed.This may contain egregious errors on my part.This is being submitted so as to provide the basis of WordPress/wporg-two-factor#103