<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
Technically creating and encrypting folder key does not require decrypting user's private key. All folder keys are encrypted with user's public key.
</div>
<div>
<br>
</div>
<div>
Aki
</div>
<blockquote type="cite">
<div>
On 08/12/2019 09:42 uxqex4efpu--- via dovecot <
<a href="mailto:dovecot@dovecot.org">dovecot@dovecot.org</a>> wrote:
</div>
<div>
<br>
</div>
<div>
<br>
</div>
<div>
What it is way most best for causing bash script run (as root) of time
</div>
<div>
mailbox created (lda_mailbox_autocreate)?
</div>
<div>
<br>
</div>
<div>
I use dovecot 2.3.4.1 in Debian 10.
</div>
<div>
<br>
</div>
<div>
And I use of mail-crypt-plugin
</div>
<div>
<a href="https://doc.dovecot.org/configuration_manual/mail_crypt_plugin/" rel="noopener" target="_blank">https://doc.dovecot.org/configuration_manual/mail_crypt_plugin/</a>
</div>
<div>
<br>
</div>
<div>
I setup mail-crypt for requiring user encrypted EC key
</div>
<div>
(mail_crypt_require_encrypted_user_key = yes). I want for passphrase
</div>
<div>
encrypt EC key using client plaintext password. There is credential no
</div>
<div>
stored on server. But for user with use password too bad, I concatenate
</div>
<div>
user plaintext password with random salt. And then string to SHA512() hash
</div>
<div>
and use as decryption key (mail_crypt_private_password) for EC private
</div>
<div>
key.
</div>
<div>
<br>
</div>
<div>
For above I have plugin config
</div>
<div>
<br>
</div>
<blockquote type="cite">
<div>
mail_plugins = $mail_plugins mail_crypt
</div>
<div>
plugin {
</div>
<div>
mail_crypt_curve = secp256k1
</div>
<div>
mail_crypt_require_encrypted_user_key = yes
</div>
<div>
mail_crypt_save_version = 2
</div>
<div>
}
</div>
</blockquote>
<div>
And for returning userdb_mail_crypt_private_password, I have sql query
</div>
<div>
<br>
</div>
<blockquote type="cite">
<div>
password_query = SELECT username, password, \
</div>
<div>
SHA2( CONCAT('%w',salt), 512 ) AS userdb_mail_crypt_private_password \
</div>
<div>
FROM virtual_users WHERE username='%u';
</div>
</blockquote>
<div>
But how I generate key of user automatically? Note for generating key of
</div>
<div>
user, I need user password plaintext. I never save plaintext password of
</div>
<div>
user of the server.
</div>
<div>
<br>
</div>
<div>
Also user of note creates in PHP of web of the server. And for security I
</div>
<div>
do not allow PHP exec shell (php.ini disabled_functions). Definitely not
</div>
<div>
leaving PHP doveadm access!
</div>
<div>
<br>
</div>
<div>
For solving subject to generate user key encrypted, I do imap of call of
</div>
<div>
the service 'imap-postlogin' the service likes document "Post-login
</div>
<div>
scripting' write
</div>
<div>
<a href="https://doc.dovecot.org/admin_manual/post_login_scripting/" rel="noopener" target="_blank">https://doc.dovecot.org/admin_manual/post_login_scripting/</a>
</div>
<div>
<br>
</div>
<div>
And 'imap-postlogin' execute my custom script with 'script-login' binary
</div>
<div>
<a href="https://github.com/dovecot/core/blob/8606e1abb90a1c91357b84bf547a89564d053533/src/util/script-login.c" rel="noopener" target="_blank">https://github.com/dovecot/core/blob/8606e1abb90a1c91357b84bf547a89564d053533/src/util/script-login.c</a>
</div>
<div>
<br>
</div>
<div>
Here it is config for above
</div>
<div>
<br>
</div>
<blockquote type="cite">
<div>
service imap {
</div>
<div>
executable = imap imap-postlogin
</div>
<div>
}
</div>
<div>
service imap-postlogin {
</div>
<div>
executable = script-login /usr/local/bin/generateKeys.sh
</div>
<div>
unix_listener imap-postlogin {
</div>
<div>
}
</div>
<div>
}
</div>
</blockquote>
<div>
And generateKeys.sh it is script simple for generating keys with sha256()
</div>
<div>
hash product mysql. Variable of note ${MAIL_CRYPT_PRIVATE_PASSWORD}
</div>
<div>
automatically put of 'userdb_mail_crypt_private_password' return of mysql
</div>
<div>
field of query when documented
</div>
<div>
<a href="https://doc.dovecot.org/admin_manual/post_login_scripting/running-surroundings" rel="noopener" target="_blank">https://doc.dovecot.org/admin_manual/post_login_scripting/running-surroundings</a>
</div>
<div>
<br>
</div>
<blockquote type="cite">
<div>
Fields returned by userdb lookup with their keys uppercased
</div>
<div>
(e.g. if userdb returned home, it's stored in HOME).
</div>
</blockquote>
<div>
Here generatekeys.sh
</div>
<div>
<br>
</div>
<blockquote type="cite">
<div>
#!/bin/bash
</div>
<div>
if [ `/usr/bin/doveadm mailbox cryptokey list -u "${USER}" -U >
</div>
</blockquote>
<div>
/dev/null | wc -l` -lt 2 ]; then
</div>
<blockquote type="cite">
<div>
/usr/bin/doveadm -o
</div>
</blockquote>
<div>
"plugin/mail_crypt_private_password=${MAIL_CRYPT_PRIVATE_PASSWORD}"
</div>
<div>
mailbox cryptokey generate -u "${USER}" -U > /dev/null
</div>
<blockquote type="cite">
<div>
fi
</div>
<div>
exec "$@"
</div>
</blockquote>
<div>
This work! But I want more good. By why execute each login? Possible has
</div>
<div>
generateKeys.sh execute in the times only of dovecot create mailbox
</div>
<div>
(lda_mailbox_autocreate) instead?
</div>
</blockquote>
<div>
<br>
</div>
<div class="io-ox-signature">
<pre>---
Aki Tuomi</pre>
</div>
</body>
</html>