Skip to content

security: upgrade credential encryption from AES/CBC to AES/GCM#610

Merged
yasithdev merged 7 commits intomasterfrom
feat/aes-gcm-encryption
Mar 31, 2026
Merged

security: upgrade credential encryption from AES/CBC to AES/GCM#610
yasithdev merged 7 commits intomasterfrom
feat/aes-gcm-encryption

Conversation

@yasithdev
Copy link
Copy Markdown
Contributor

@yasithdev yasithdev commented Mar 30, 2026

Extracted from #556. Upgrades credential store encryption from AES/CBC/PKCS5Padding with a static zero IV to AES/GCM/NoPadding with random IVs.

What changed

  • SecurityUtil: New encrypt(byte[], Key) / decrypt(byte[], Key) API using GCM with 12-byte random IV prepended to ciphertext. Legacy decryptLegacy() retained for migration use only.
  • CredentialsDAO: Updated to use new API (get key once, then encrypt/decrypt)
  • MigrateCredentialEncryption: One-time migration script to re-encrypt existing CBC credentials to GCM
  • Removed old encryptString/decryptString methods that baked in keystore access

Why

  • AES/CBC with static new byte[16] IV is insecure — identical plaintexts produce identical ciphertexts
  • GCM provides authenticated encryption (integrity + confidentiality)
  • Random IV per encryption ensures semantic security

Migration

Run before deploying:

java MigrateCredentialEncryption <jdbcUrl> <dbUser> <dbPass> <keystorePath> <keyAlias> <keystorePass>

The script decrypts each CREDENTIALS row with legacy CBC, re-encrypts with GCM, and updates in-place. Already-migrated rows are skipped.

All 9 modules build, all tests pass (5 SecurityUtil tests including legacy round-trip and CBC→GCM migration).

Replace AES/CBC/PKCS5Padding with AES/GCM/NoPadding for credential
store encryption. The old code used a static zero IV which is insecure.
GCM provides authenticated encryption with random IVs prepended to
the ciphertext.

Extracted from #556.
On decrypt, try GCM first. If the auth tag fails (AEADBadTagException),
fall back to the old AES/CBC/PKCS5Padding with static zero IV. This
allows existing credentials to be read without re-encryption.

Credentials will migrate to GCM format on next update/rotation —
writes always use AES/GCM.
- testFallbackDecryptsLegacyCBC: CBC-encrypted data decrypted via fallback
- testFallbackDecryptsNewGCM: GCM-encrypted data decrypted via fallback
- testGcmDecryptRejectsLegacyData: GCM decrypt throws on CBC data
Replace transparent fallback with a one-time migration script
(MigrateCredentialEncryption) that re-encrypts all CREDENTIALS rows
from legacy AES/CBC to AES/GCM. Run before deploying the GCM-only code.

Usage:
  java MigrateCredentialEncryption <jdbcUrl> <dbUser> <dbPass> \
    <keystorePath> <keyAlias> <keystorePass>

The script skips rows already in GCM format.
Comment thread airavata-api/src/main/java/org/apache/airavata/security/util/SecurityUtil.java Dismissed
Comment thread airavata-api/src/main/java/org/apache/airavata/security/util/SecurityUtil.java Dismissed
yasithdev and others added 2 commits March 31, 2026 00:44
…ky cryptographic algorithm

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@yasithdev yasithdev merged commit ed2986f into master Mar 31, 2026
8 checks passed
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.

2 participants