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(meta): values symmetric encryption #51

Merged
merged 10 commits into from
Nov 12, 2024
Merged

feat(meta): values symmetric encryption #51

merged 10 commits into from
Nov 12, 2024

Conversation

fabiobozzo
Copy link
Collaborator

Add encrypted metadata support to UCAN tokens

This PR adds support for encrypting sensitive metadata in UCAN tokens using AES-GCM symmetric encryption. This allows tokens to carry both public and encrypted metadata, where encrypted values can only be read by parties that possess the encryption key.

Changes

  • Added AES encryption/decryption utilities in pkg/crypto/aes.go
  • Extended Meta type to support encrypted values via AddEncrypted and GetEncryptedString/Bytes methods
  • Added comprehensive test coverage for both string and bytes encryption
  • Maintained backward compatibility with existing unencrypted metadata

Example Usage

// Create a token with both public and encrypted metadata
token, err := delegation.New(privKey, aud, cmd, pol,
   delegation.WithMeta("public", "visible to everyone"),
   delegation.WithEncryptedMeta("secret", "sensitive data", encryptionKey),
)

// Later, retrieve the encrypted value
secret, err := token.Meta().GetEncryptedString("secret", encryptionKey)

Security Notes

  • Uses AES-GCM for authenticated encryption
  • Each encryption operation uses a unique nonce
  • Encrypted values are stored in their encrypted form in the token's metadata
  • A nil encryption key results in storing the value unencrypted (for backward compatibility)

pkg/crypto/aes.go Outdated Show resolved Hide resolved
pkg/crypto/aes.go Outdated Show resolved Hide resolved
token/delegation/delegation_test.go Outdated Show resolved Hide resolved
token/invocation/options.go Outdated Show resolved Hide resolved
pkg/meta/meta.go Outdated Show resolved Hide resolved
@fabiobozzo fabiobozzo merged commit 6298fa2 into v1 Nov 12, 2024
4 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.

3 participants