diff --git a/interface/web/mail/mail_domain_edit.php b/interface/web/mail/mail_domain_edit.php index f5697b4f1c27fea3680d93dc3758675eb850e972..254a7c5bd12de7b030a952ce207b907b591b91f9 100644 --- a/interface/web/mail/mail_domain_edit.php +++ b/interface/web/mail/mail_domain_edit.php @@ -240,24 +240,11 @@ class page_action extends tform_actions { $app->tpl->setVar('relay_pass', $rec['relay_pass'], true); } - // load dkim-values - $sql = "SELECT domain, dkim_private, dkim_public, dkim_selector FROM mail_domain WHERE domain_id = ?"; - $rec = $app->db->queryOneRecord($sql, $app->functions->intval($_GET['id'])); - $dns_key = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"),'',$rec['dkim_public']); - - /* we do not show split DKIM key anymore - $keyparts = str_split('v=DKIM1; t=s; p=' . $dns_key, 200); - array_walk($keyparts, function(&$value, $key) { $value = '"'.$value.'"'; } ); - $dkim_txt = implode('', $keyparts); - */ - $dkim_txt = '"v=DKIM1; t=s; p=' . $dns_key . '"'; - - $dns_record = $rec['dkim_selector'] . '._domainkey.' . $rec['domain'] . '. 3600 IN TXT '.$dkim_txt; - - $app->tpl->setVar('dkim_selector', $rec['dkim_selector'], true); - $app->tpl->setVar('dkim_private', $rec['dkim_private'], true); - $app->tpl->setVar('dkim_public', $rec['dkim_public'], true); - if (!empty($rec['dkim_public'])) $app->tpl->setVar('dns_record', $dns_record, true); + $dns_key = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"), '', $this->dataRecord['dkim_public']); + $dkim_txt = 'v=DKIM1; t=s; p=' . $dns_key; + $dns_record = $this->dataRecord['dkim_selector'] . '._domainkey.' . $this->dataRecord['domain'] . '. 3600 IN TXT "' . $dkim_txt . '"'; + + if (!empty($this->dataRecord['dkim_public'])) $app->tpl->setVar('dns_record', $dns_record, true); $csrf_token = $app->auth->csrf_token_get('mail_domain_del'); $app->tpl->setVar('_csrf_id', $csrf_token['csrf_id']); diff --git a/server/plugins-available/mail_plugin_dkim.inc.php b/server/plugins-available/mail_plugin_dkim.inc.php index 4114148f118251f330b8e101bdd134aec9598516..0a75cab974966e84d54ba42b9a49208be0e08eb5 100755 --- a/server/plugins-available/mail_plugin_dkim.inc.php +++ b/server/plugins-available/mail_plugin_dkim.inc.php @@ -204,26 +204,21 @@ class mail_plugin_dkim { */ private function write_dkim_key($key_file, $key_value, $key_domain) { global $app; - $success=false; + $success = false; if ($key_file == '' || $key_value == '' || $key_domain == '') { $app->log('DKIM internal error for domain '.$key_domain, LOGLEVEL_ERROR); return $success; } if ( $app->system->file_put_contents($key_file.'.private', $key_value) ) { $app->log('Saved DKIM Private-key to '.$key_file.'.private', LOGLEVEL_DEBUG); - $success=true; - $pubkey = null; - $result = 0; - /* now we get the DKIM Public-key */ - $app->system->exec_safe('cat ?|openssl rsa -pubout 2> /dev/null', $key_file.'.private'); - $pubkey = $app->system->last_exec_out(); - $public_key=''; - foreach($pubkey as $values) { - $public_key = $public_key . $values . "\n"; - } - /* save the DKIM Public-key in dkim-dir */ - if($app->system->file_put_contents($key_file.'.public', $public_key)) { + + // Extract the dkim public key from the private. + $public_key = openssl_pkey_get_details(openssl_pkey_get_private($key_value))['key']; + + // Save the DKIM Public-key in dkim-dir + if(!empty($public_key) && $app->system->file_put_contents($key_file.'.public', $public_key)) { $app->log('Saved DKIM Public to '.$key_domain.'.', LOGLEVEL_DEBUG); + $success = true; } else { $app->log('Unable to save DKIM Public to '.$key_domain.'.', LOGLEVEL_DEBUG); }