Skip to content

feat(data_encryption): support AES-256 keys in the encryption keyring - #13756

Open
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:feat/data-encryption-aes-256
Open

feat(data_encryption): support AES-256 keys in the encryption keyring#13756
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:feat/data-encryption-aes-256

Conversation

@AlinsRan

Copy link
Copy Markdown
Contributor

Description

core.data_encryption.init_iv_tbl only ever built AES-128 ciphers:

tbl.insert(iv_tbl, assert(aes:new(iv, nil, aes.cipher(128, "cbc"), {iv = iv})))

So a 32-byte apisix.data_encryption.keyring key could not be used for AES-256, and any key whose length is not exactly 16 bytes was forced through aes.cipher(128, ...) and errored via the assert.

This selects the cipher by key length: a 16-byte key → AES-128, a 32-byte key → AES-256. Keys of any other length are skipped rather than crashing.

No schema change is needed — the keyring is read from config without a length constraint.

Which issue(s) this PR fixes

Lets operators use a stronger AES-256 keyring for encrypt_fields / SSL key encryption.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change (t/core/data_encryption.t: 16-byte, 32-byte, mixed keyring, unsupported length)
  • I have updated the documentation accordingly
  • I have verified locally (full CI covers the rest)

init_iv_tbl only ever built AES-128 ciphers, so a 32-byte data_encryption
keyring key could not be used for AES-256. A 16-byte key now selects
AES-128 and a 32-byte key selects AES-256; keys of any other length are
skipped instead of being forced through aes.cipher(128, ...), which
previously errored via the assert.

Adds t/core/data_encryption.t covering the 16-byte, 32-byte, mixed-keyring
and unsupported-length cases.

Signed-off-by: AlinsRan <alinsran@apache.org>
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant