[fix] we check FIRST for certificate already existing in ssl->import_check()

This commit is contained in:
Benjamin Sonntag 2018-06-23 16:37:11 +02:00
parent 152551a8bb
commit a2e22a8d1f
1 changed files with 7 additions and 7 deletions

View File

@ -457,6 +457,13 @@ INSTR(CONCAT(sd.sub,IF(sd.sub!='','.',''),sd.domaine),'.')+1))=?
global $cuid, $msg, $db;
$msg->log("ssl", "import_cert");
// Search for an existing cert: (first)
$db->query("SELECT id FROM certificates WHERE crt=?;",array($crt));
if ($db->next_record()) {
$msg->raise("ERROR","ssl", _("Certificate already exists in database"));
return false;
}
$result = $this->check_cert($crt, $chain, $key);
if ($result === false) {
$msg->raise("ERROR","ssl", $this->error);
@ -469,13 +476,6 @@ INSTR(CONCAT(sd.sub,IF(sd.sub!='','.',''),sd.domaine),'.')+1))=?
$fqdn = $crtdata["subject"]["CN"];
$altnames = $this->parseAltNames($crtdata["extensions"]["subjectAltName"]);
// Search for an existing cert:
$db->query("SELECT id FROM certificates WHERE crt=?;",array($crt));
if ($db->next_record()) {
$msg->raise("ERROR","ssl", _("Certificate already exists in database"));
return false;
}
// Everything is PERFECT and has been thoroughly checked, let's insert those in the DB !
$db->query(
"INSERT INTO certificates SET uid='?', status=?, shared=0, fqdn=?, altnames=?, validstart=FROM_UNIXTIME(?), validend=FROM_UNIXTIME(?), sslkey=?, sslcrt=?, sslchain=?, provider=?;",