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

feat: support sql func encrypt/decrypt #14717

Merged
merged 19 commits into from
Feb 1, 2024
Merged

feat: support sql func encrypt/decrypt #14717

merged 19 commits into from
Feb 1, 2024

Conversation

tabVersion
Copy link
Contributor

@tabVersion tabVersion commented Jan 22, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

add raw encrypt / decrypt functions

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

algorithm [ - mode ] [ /pad: padding ]

where algorithm is one of:

* bf — Blowfish

  • aes — AES (Rijndael-128, -192 or -256)

and mode is one of:

  • cbc — next block depends on previous (default)
  • ecb — each block is encrypted separately (for testing only)

and padding is one of:

  • pkcs — data may be any length (default)
  • none — data must be multiple of cipher block size

the given encryption/decryption key MUST match length 16/24/32 bytes as required by aes-128/192/256
follow up work: do key padding for key length does not match 16/24/32, then we no longer need the above constraint. cancel this item for postgres just pads all zero, which is not secure I think.

examples

  • aes-cbc/pad:pkcs => AES algorithm, cbc mode, enabling padding
  • aes => AES algorithm, cbc mode, enabling padding
  • aes-ecb => AES algorithm, ecb mode, enabling padding

@lmatz
Copy link
Contributor

lmatz commented Jan 22, 2024

if time is allowed, let's merge this feature into v1.6.1

@tabVersion
Copy link
Contributor Author

if time is allowed, let's merge this feature into v1.6.1

I am afraid we cannot make it.😥 It's a little too rushed.

src/expr/impl/src/scalar/encrypt.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/encrypt.rs Outdated Show resolved Hide resolved
@tabVersion tabVersion marked this pull request as ready for review January 26, 2024 03:41
@tabVersion tabVersion requested a review from a team as a code owner January 26, 2024 03:41
@tabVersion tabVersion added the user-facing-changes Contains changes that are visible to users label Jan 26, 2024
Copy link
Contributor

@lmatz lmatz left a comment

Choose a reason for hiding this comment

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

There are a few regress test cases from Postgres pgcrypto that can be used to test e2e: https://github.com/postgres/postgres/blob/master/contrib/pgcrypto/expected/rijndael.out

LGTM

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

Wow, it's really complicated. 😄

src/workspace-hack/Cargo.toml Show resolved Hide resolved
Copy link
Contributor

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

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

Generally LGTM. We should also add some e2e tests.

src/expr/impl/src/scalar/encrypt.rs Outdated Show resolved Hide resolved
proto/expr.proto Outdated Show resolved Hide resolved
src/frontend/src/expr/pure.rs Outdated Show resolved Hide resolved
src/expr/core/src/error.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/encrypt.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/encrypt.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/encrypt.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/encrypt.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/encrypt.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@xiangjinwu xiangjinwu left a comment

Choose a reason for hiding this comment

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

Other proposed changes are here: #14869 (we can merge it into this branch/PR)

Seems blowfish support is still included. Are we confident in releasing it? Let's remove blowfish support as it is already considered legacy by openssl 3 and not enabled by default.

src/expr/core/src/error.rs Outdated Show resolved Hide resolved
src/frontend/src/expr/pure.rs Outdated Show resolved Hide resolved
Copy link

gitguardian bot commented Feb 1, 2024

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9425213 Triggered Generic Password defcab8 ci/scripts/regress-test.sh View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

Comment on lines +48 to +56
-- key padding
SELECT encrypt(
'\x0011223344',
'\x000102030405',
'aes-cbc');
encrypt
------------------------------------
\x189a28932213f017b246678dbc28655f
(1 row)
Copy link
Contributor

@xiangjinwu xiangjinwu Feb 1, 2024

Choose a reason for hiding this comment

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

PostgreSQL simply pads zero bytes for shorter key as these functions are supposed to be raw encryption. Key derivation is supposed to be handled by higher level utilities.

Our lack of such insecure (zero-pad-at-end) usage would not be a limitation in practice.

@tabVersion tabVersion added this pull request to the merge queue Feb 1, 2024
Merged via the queue into main with commit 344cf99 Feb 1, 2024
12 of 22 checks passed
@tabVersion tabVersion deleted the tab/decrypt-func branch February 1, 2024 06:56
lmatz pushed a commit that referenced this pull request Feb 4, 2024
lmatz added a commit that referenced this pull request Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature user-facing-changes Contains changes that are visible to users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants