Skip to content

Commit 3825fac

Browse files
committed
variables: Document encrypt and decrypt filters
1 parent 19bb9f2 commit 3825fac

File tree

2 files changed

+58
-63
lines changed

2 files changed

+58
-63
lines changed

docs/core/plugins/var_expand_crypt.md

Lines changed: 0 additions & 56 deletions
This file was deleted.

docs/core/settings/variables.md

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ dovecotlinks:
1818
conditionals:
1919
hash: conditionals
2020
text: Conditionals
21+
cryptography_support:
22+
hash: cryptography-support
23+
text: Cryptography support
2124
---
2225

2326
# Settings Variables
@@ -97,8 +100,12 @@ Bytes output type indicates that the output will be tagged as binary output. Sub
97100
| base64(pad=boolean, url=boolean) | Bytes | String | Base64 encode given input, defaults to pad and not url scheme. |
98101
| benumber | Bytes | Number | Convert big-endian encoded input into a number. |
99102
| concat(any, any...) | Bytes | Bytes | Concatenates input with value(s). Numbers are coerced to strings. Input is optional. |
103+
| decrypt(key=bytes,iv=bytes,raw=boolean,algorithm=string) | Any | Any | Decrypts given input, see [cryptography support](#cryptography-support). |
104+
| decrypt(key=string,salt=string,rounds=number,raw=boolean,hash=string,algorithm=string) | Any | Any | Decrypts given input, see [cryptography support](#cryptography-support). |
100105
| default(value) | String | String | Replace empty or missing input with value. Clears missing variable error. If no value is provided, empty string is used. |
101106
| domain | String | String | Provides domain part of user@domain value. |
107+
| encrypt(key=bytes,iv=bytes,raw=boolean,algorithm=string) | Any | Any | Encrypts given input, see [cryptography support](#cryptography-support). |
108+
| encrypt(key=string,salt=string,rounds=number,raw=boolean,hash=string,algorithm=string) | Any | Any | Encrypts given input, see [cryptography support](#cryptography-support). |
102109
| hash(method, rounds=number, salt=string) | Bytes | Bytes | Returns raw hash from input using given hash method. Rounds and salt are optional. |
103110
| hexlify(width) | Bytes | String | Convert bytes into hex with optional width, truncates or pads up to width. |
104111
| hex(width) | Number | Number | Convert base-10 number to base-16 number. If width is specified the result is truncated or padded with 0 to width. Negative width is applied after number. |
@@ -129,13 +136,6 @@ Bytes output type indicates that the output will be tagged as binary output. Sub
129136
| upper | String | String | Uppercases input. |
130137
| username | String | String | Provides user part of user@domain value. |
131138

132-
If [[plugin,var-expand-crypt]] is loaded, these filters are registered as well.
133-
134-
| Filter | Input | Output | Description |
135-
| ------ | ----- | ----- | ----------- |
136-
| decrypt(algorithm=string,key=string,iv=string,raw=boolean) | Bytes/String | Bytes | Decrypts input with given parameters. If raw is `0`, expects '$' separated value of IV and encrypted data. |
137-
| encrypt(algorithm=string,key=string,iv=string,raw=boolean) | Bytes | Bytes/String | Encrypts input with given parameters. If raw is `0`, outputs `$` separated value of IV and encrypted data. |
138-
139139
## Global providers
140140

141141
Global providers that work everywhere are:
@@ -356,3 +356,54 @@ Examples:
356356
# If %{user} is "testuser", return "INVALID". Otherwise return %{user} uppercased.
357357
%{user | if ("=", "testuser, "invalid", user) | upper }
358358
```
359+
360+
## Cryptography support
361+
362+
### Parameters
363+
364+
| Key | Value |
365+
| ------------------ | --------------------------------------------------------------------------------|
366+
| key | The encryption key. |
367+
| iv | Initialization vector. |
368+
| salt | Salt to use in PBKDF2 algorithm. |
369+
| hash | Hash to use in PBKDF2. Defaults to `sha-256`. |
370+
| rounds | Number of rounds to use in PBKDF2. Defaults to 10 000. |
371+
| algorithm | Encryption algorithm. Expects OpenSSL naming. Defaults to `aes-256-cbc`. |
372+
| raw | When set to 1, will return encrypted result in raw output format. Default is 0. |
373+
374+
### Key, initialization vector and salt.
375+
376+
For legacy reasons, this function supports direct keying and salted keying.
377+
In direct keying, the `key` and `iv` must be provided hex encoded, and must match the algorithm's requirements.
378+
379+
If `key` and `salt` are provided, then the actual encryption key and initialization vector are generated with [PBKDF2 algorithm](https://en.wikipedia.org/wiki/PBKDF2).
380+
381+
If only `key` is provided a random salt is generated. Random salt cannot be generated in raw mode, because it would not get stored,
382+
so it must be always provided.
383+
384+
### Structured output format
385+
386+
Dovecot supports structured encrypted data.
387+
If initialization vector is directly provided, the output syntax is `iv$data$`.
388+
With salt based keying material generation, the format is `s=salt,r=rounds$data$`.
389+
390+
### Raw output format
391+
392+
If raw is used, the raw encryption result is emitted with no salt, rounds or IV included.
393+
394+
### Recommended usage
395+
396+
For best results, you should leave salt and IV management to Dovecot.
397+
398+
### Examples
399+
400+
```[dovecot.conf]
401+
import_environment = {
402+
SECRET_KEY = %{env:SECRET_KEY}
403+
}
404+
imapc_password = "%{literal('s=3-?I&-a|,r=10000$e80e6ab3c18c0da69b20bf201eaf6269$') | decrypt(key=env:SECRET_KEY)}"
405+
```
406+
407+
Stores imap client password securely so that it can be decrypted only if `SECRET_KEY` environment variable is provided.
408+
409+
To easily generate an encrypted value, you can use [[doveadm,user,user -e "%{literal('value') | encrypt(key='secret')}"]].

0 commit comments

Comments
 (0)