1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2024-12-04 10:24:42 +02:00

[Web] Allow to overwrite DKIM keys while importing a new key

This commit is contained in:
andryyy 2020-09-26 22:01:15 +02:00
parent 53dd02bc63
commit 23f118a152
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF

View File

@ -50,10 +50,10 @@ function dkim($_action, $_data = null, $privkey = false) {
if ($keypair_ressource = openssl_pkey_new($config)) {
$key_details = openssl_pkey_get_details($keypair_ressource);
$pubKey = implode(array_slice(
array_filter(
explode(PHP_EOL, $key_details['key'])
), 1, -1)
);
array_filter(
explode(PHP_EOL, $key_details['key'])
), 1, -1)
);
// Save public key and selector to redis
try {
$redis->hSet('DKIM_PUB_KEYS', $domain, $pubKey);
@ -150,6 +150,7 @@ function dkim($_action, $_data = null, $privkey = false) {
return false;
}
$private_key_input = trim($_data['private_key_file']);
$overwrite_existing = intval($_data['overwrite_existing']);
$private_key_normalized = preg_replace('~\r\n?~', "\n", $private_key_input);
$private_key = openssl_pkey_get_private($private_key_normalized);
if ($ssl_error = openssl_error_string()) {
@ -178,12 +179,14 @@ function dkim($_action, $_data = null, $privkey = false) {
return false;
}
if ($redis->hGet('DKIM_PUB_KEYS', $domain)) {
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $_action, $_data, $privkey),
'msg' => array('dkim_domain_or_sel_invalid', $domain)
);
return false;
if ($overwrite_existing == 0) {
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $_action, $_data, $privkey),
'msg' => array('dkim_domain_or_sel_exists', $domain)
);
return false;
}
}
if (!ctype_alnum($dkim_selector)) {
$_SESSION['return'][] = array(
@ -194,6 +197,7 @@ function dkim($_action, $_data = null, $privkey = false) {
return false;
}
try {
dkim('delete', $domain);
$redis->hSet('DKIM_PUB_KEYS', $domain, $pem_public_key);
$redis->hSet('DKIM_SELECTORS', $domain, $dkim_selector);
$redis->hSet('DKIM_PRIV_KEYS', $dkim_selector . '.' . $domain, $private_key_normalized);