Skip to content
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 19 commits into from
Apr 20, 2023
Merged

Add Encryption methods. #390

merged 19 commits into from
Apr 20, 2023

Conversation

dd32
Copy link
Member

@dd32 dd32 commented Apr 12, 2023

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_ENCRYPTION_KEY: .... = accessed via wporg_encrypt( $string, (string) $user_id ) & wporg_decrypt( $encrypted_value, (string) $user_id )
  • WPORG_PLUGINS_ENCRYPTION_KEY: ... = accessed via 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

@dd32 dd32 requested review from iandunn and pkevan April 12, 2023 07:46
Copy link
Contributor

@pkevan pkevan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dd32 dd32 marked this pull request as ready for review April 13, 2023 03:09
mu-plugins/encryption/exports.php Outdated Show resolved Hide resolved
mu-plugins/encryption/exports.php Outdated Show resolved Hide resolved
mu-plugins/encryption/class-hiddenstring.php Show resolved Hide resolved
mu-plugins/encryption/index.php Outdated Show resolved Hide resolved
mu-plugins/encryption/index.php Outdated Show resolved Hide resolved
dd32 added a commit to WordPress/wporg-two-factor that referenced this pull request Apr 18, 2023
@dd32
Copy link
Member Author

dd32 commented Apr 18, 2023

Thanks for the review @xknown, I've made changes to reflect that.

Copy link
Member

@xknown xknown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

mu-plugins/encryption/exports.php Outdated Show resolved Hide resolved
mu-plugins/encryption/index.php Outdated Show resolved Hide resolved
@dd32 dd32 merged commit d3fd967 into trunk Apr 20, 2023
@dd32 dd32 deleted the add/encryption-methods branch April 20, 2023 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants