Skip to content

fix(function): reject SM4 functions in community edition#35406

Open
bestdo77 wants to merge 1 commit into
taosdata:mainfrom
bestdo77:fix/sm4-community-plaintext-35349
Open

fix(function): reject SM4 functions in community edition#35406
bestdo77 wants to merge 1 commit into
taosdata:mainfrom
bestdo77:fix/sm4-community-plaintext-35349

Conversation

@bestdo77

@bestdo77 bestdo77 commented Jul 17, 2026

Copy link
Copy Markdown

Fixes #35349.

Problem

In the community edition, SM4_ENCRYPT/SM4_DECRYPT report success but return the plaintext unchanged: the community build ships a copy-through SM4 implementation (kept for internal storage encryption such as WAL/checkpoint), and the SQL layer did not reject these functions. Users therefore believe their data is encrypted while it is stored in plaintext.

Changes

Reject the two SM4 SQL functions in community builds with TSDB_CODE_OPS_NOT_SUPPORT ("only supported in Enterprise edition"), at both entry points:

  • source/libs/function/src/builtins.c: translateOutSm4/translateOutSm4De return the error during function translation — covers all query paths (SELECT, WHERE, INSERT ... SELECT, ...).
  • source/libs/parser/src/parInsertSql.c: parseBinary rejects TK_SM4_ENCRYPT/TK_SM4_DECRYPT — covers the INSERT ... VALUES(sm4_encrypt(...)) constant-folding fast path, which bypasses function translation.

Enterprise builds (TD_ENTERPRISE/TD_ASTRA) are unchanged; the guard macro follows the existing convention in source/libs/crypt/src/crypt.c.

Tests

  • test/cases/11-Functions/01-Scalar/test_scalar_crypto.py: probe SM4 availability, assert the enterprise-only error on SELECT/INSERT encrypt/decrypt paths in community edition; original positive cases now run only where SM4 is supported.
  • test/cases/11-Functions/09-NoFrom/test_fun_no_from_all.py: SM4 no-FROM cases moved to a separate list and routed to positive/negative assertions based on a runtime probe, so the case passes on both editions. Also pass the test client config dir (-c) to the taos CLI invocations.

Verification (community build)

  • Incremental build and parser unit tests pass.
  • Both Python cases pass.
  • Live node: SELECT sm4_encrypt/decrypt(...), INSERT ... VALUES(sm4_encrypt/decrypt(...)) all fail with 0x80000100 only supported in Enterprise edition; AES functions unaffected; rejected SM4 inserts write no plaintext.
  • Environment: community build 3.4.1.13.alpha.community (base main@df445db5dc), Linux x86_64. Enterprise edition was not run locally; it is unaffected by construction since the rejection is compiled out when TD_ENTERPRISE/TD_ASTRA is defined.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request restricts the SM4 encryption and decryption functions (sm4_encrypt and sm4_decrypt) to the Enterprise and Astra editions. It adds preprocessor checks in the built-in functions and SQL parser to raise an error when these functions are invoked in other editions. The test cases are also updated to dynamically detect SM4 support and verify that the appropriate error messages are returned when unsupported. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logic Flaw: SM4_ENCRYPT/DECRYPT functions return plaintext without warning in Community Edition

1 participant