AgeEx

The age v1 file format in pure Elixir. It uses only OTP :crypto (OTP 28.1 or later) and has no dependencies. Files work with the age and rage tools in both directions, binary or ASCII-armored.

Two key types work:

AgeEx.encrypt/3 also accepts YubiKey recipients (age1yubikey1...) from age-plugin-yubikey. AgeEx cannot decrypt these files. Only the YubiKey can, with the age CLI and the plugin.

Not supported: passphrases (scrypt), SSH keys, plugins. All data stays in memory.

Installation

def deps do
  [{:age_ex, "~> 0.1.0"}]
end

Usage

%{identity: identity, recipient: recipient} = AgeEx.generate_identity()
# or AgeEx.generate_identity(post_quantum: true)

{:ok, ciphertext} = AgeEx.encrypt("secret", recipient, armor: true)
{:ok, "secret"} = AgeEx.decrypt(ciphertext, identity)

# A key file from age-keygen, with its comment lines
{:ok, identities} = AgeEx.parse_identities(File.read!("key.txt"))
{:ok, plaintext} = AgeEx.decrypt(File.read!("data.age"), identities)

SOPS files

AgeEx.Sops decrypts SOPS files with age keys. Encryption is not supported.

{:ok, identities} =
  File.read!("key.txt")
  |> AgeEx.parse_identities()

{:ok, %{"db" => %{"password" => password}}} =
  File.read!("secrets.sops.json")
  |> AgeEx.Sops.decrypt_json(identities)

Config provider

AgeEx.Sops.ConfigProvider loads a binary-format file as Elixir config at release boot. The plaintext stays in memory:

releases: [
  my_app: [
    config_providers: [
      {AgeEx.Sops.ConfigProvider,
       path: {:system, "RELEASE_ROOT", "/deploy/my.server/extra_config.exs"},
       identity_file: {:system, "HOME", "/.config/sops/age/keys.txt"}}
    ]
  ]
]

To read the key from an environment variable, for example in a container, use identity_env: "SOPS_AGE_KEY" instead of identity_file. The variable holds the text of an age key file.

age encryption keeps the config secret, but it does not show who wrote the file. Anyone who knows a recipient can make a valid file, and the provider runs it as Elixir code. Protect the encrypted file against writes as well as the release itself.

Tests

mix test

To update the vectors, copy age/testdata from the CCTV repository into test/fixtures/cctv. Then change the commit in test/cctv_test.exs.