From e4c8130ebe6e4a7ae9524688b1edd079d3f94c00 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 15 Oct 2026 01:07:32 -0400 Subject: [PATCH] Certificates: Check now connects to the host and saves what it serves - issuer, issued and expiry dates, names covered, SHA-256 fingerprint and the PEM - with the result (OK, name mismatch, untrusted, expired or unreachable) and when it ran, and a check that reaches nothing keeps the certificate on file; New/Edit form split into tabs (Certificate, Paste or by hand, Notes) with a Check button that shows what the host serves before saving, the host tidied from a pasted web address, the name defaulting to the host, the domain picked from the host and limited to the client's own, and a PEM paste or issuer and expiry by hand for hosts ITFlow can't reach; new certificate quick look with the check result and what to do about it, names covered, fingerprint copy, PEM copy and .crt download, domain, services, notes and history; certificates list rebuilt with All/Starred/Expiring soon/Expired/Problems/Not checked pills, host and names covered, domain link, issuer filter, last check column, whitelisted sort, ?open= and bulk check/star/archive/restore/delete; short-lived (ACME) certificates only count as expiring soon inside 20 days and skip the 45-day alert; domain and service quick looks link certificates to their quick look (with New certificate from a domain), global search finds certificates by name, host, names covered or fingerprint, client overview gets a Certificate problems box and renewals open the certificate, dashboard links to Expiring soon, client portal shows expiry badges, export adds last check, names covered, fingerprint and more, documentation PDF adds host and last check; certificate refresher now checks hosts daily in a time-boxed batch, writes history and notifies when an OK certificate turns bad; nightly alerts skip archived certificates and open the certificate; API create uses the same form rules and checks the host; demo data adds firewall, remote access and RADIUS certificates with real check results. Fixes the delete audit log using an undefined name, the archive flash type, certificates linking to another client's domain, services linking to another client's certificates, PEM parsing assuming an issuer organisation, and the API create using an undefined variable. DB 2.8.4 --- admin/database_updates/2.8.4.php | 50 ++ admin/post/demo_data_model.php | 124 +++- agent/ajax.php | 79 ++- agent/certificates.php | 563 +++++++++++------- agent/js/certificate_fetch_ssl.js | 37 -- agent/modals/certificate/certificate.php | 243 ++++++++ agent/modals/certificate/certificate_add.php | 165 +---- agent/modals/certificate/certificate_edit.php | 190 +----- .../modals/certificate/certificate_export.php | 16 +- agent/modals/certificate/certificate_form.php | 270 +++++++++ agent/modals/domain/domain.php | 37 +- agent/modals/service/service.php | 19 +- agent/modals/service/service_add.php | 6 +- agent/modals/service/service_edit.php | 11 +- agent/post/certificate.php | 489 +++++++-------- agent/post/certificate_model.php | 11 - agent/post/client.php | 5 +- agent/post/service.php | 8 +- api/v1/certificates/certificate_model.php | 67 --- api/v1/certificates/create.php | 73 +-- client/certificates.php | 12 +- cron/certificate_refresher.php | 111 ++-- cron/nightly_tasks.php | 39 +- css/itflow_custom.css | 23 + db.sql | 5 + functions.php | 1 + functions/certificate.php | 552 +++++++++++++++++ functions/client_overview.php | 12 +- functions/dashboard.php | 4 +- functions/domain.php | 62 +- functions/export.php | 11 +- functions/search.php | 27 + includes/cron_jobs.php | 2 +- 33 files changed, 2195 insertions(+), 1129 deletions(-) create mode 100644 admin/database_updates/2.8.4.php delete mode 100644 agent/js/certificate_fetch_ssl.js create mode 100644 agent/modals/certificate/certificate.php create mode 100644 agent/modals/certificate/certificate_form.php delete mode 100644 agent/post/certificate_model.php delete mode 100644 api/v1/certificates/certificate_model.php create mode 100644 functions/certificate.php diff --git a/admin/database_updates/2.8.4.php b/admin/database_updates/2.8.4.php new file mode 100644 index 000000000..1c8ec99d7 --- /dev/null +++ b/admin/database_updates/2.8.4.php @@ -0,0 +1,50 @@ + 0 AND `domain_id` IS NULL"); diff --git a/admin/post/demo_data_model.php b/admin/post/demo_data_model.php index 92ae28bb9..2c398022e 100644 --- a/admin/post/demo_data_model.php +++ b/admin/post/demo_data_model.php @@ -1340,17 +1340,8 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) { $counts['documentation']++; } - $certificate_id = starterInsert($mysqli, 'certificates', [ - 'certificate_name' => 'www.' . $profile['domain'], - 'certificate_description' => $profile['cert_issuer'] === "Let's Encrypt" ? 'Public website certificate, renewed automatically by the reverse proxy' : 'Public website certificate, renewed manually at expiry', - 'certificate_domain' => 'www.' . $profile['domain'], - 'certificate_issued_by' => $profile['cert_issuer'], - 'certificate_expire' => demoDate(-1 * (20 + ($index * 9))), - 'certificate_domain_id' => $domain_id, - 'certificate_client_id' => $client_id, - 'certificate_created_at' => demoMonthDateTime($months, 7, 9, 50), - ]); - $counts['documentation'] += 2; + $certificate_id = demoBuildCertificates($mysqli, $profile, $index, $client_id, $domain_id, $months, $counts); + $counts['documentation']++; // The renewals behind them. Both tables cascade off their parent, so the // client purge takes these with the domain and the certificate. @@ -1368,13 +1359,6 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) { 'domain_history_domain_id' => $domain_id, 'domain_history_modified_at' => demoMonthDateTime(max(1, min(9, $months)), 6, 15, 40), ]); - starterInsert($mysqli, 'certificate_history', [ - 'certificate_history_column' => 'certificate_expire', - 'certificate_history_old_value' => demoMonthDate(3, 20), - 'certificate_history_new_value' => demoDate(-1 * (20 + ($index * 9))), - 'certificate_history_certificate_id' => $certificate_id, - 'certificate_history_modified_at' => demoMonthDateTime(3, 20, 4, 15), - ]); // Credentials - only when the vault actually opened for this session $credential_ids = []; @@ -1624,6 +1608,110 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) { } +/** + * The client's certificates: the one on their website (checked, OK - the + * Let's Encrypt ones short-lived, one of them overdue to renew), and for some + * clients the firewall's factory self-signed admin certificate, a remote + * access portal still serving the certificate for its old name, and a RADIUS + * certificate from their own CA that has no host to check. Returns the + * website certificate's id, for the services that use it. + */ +function demoBuildCertificates($mysqli, $profile, $index, $client_id, $domain_id, $months, &$counts) { + $domain = $profile['domain']; + $fingerprint = function ($seed) { + return implode(':', str_split(strtoupper(hash('sha256', 'itflow-demo-' . $seed)), 2)); + }; + $short_lived = $profile['cert_issuer'] === "Let's Encrypt"; + // Let's Encrypt certificates last 90 days and renew with 30 left; one is stuck + $expire_days = $short_lived ? ($index % 7 === 4 ? 12 : 31 + ($index * 13) % 58) : 20 + ($index * 9); + $expire = demoDate(-1 * $expire_days); + $issued = date('Y-m-d', strtotime($expire . ($short_lived ? ' -90 days' : ' -397 days'))); + + $website_id = starterInsert($mysqli, 'certificates', [ + 'certificate_name' => 'www.' . $domain, + 'certificate_description' => $short_lived ? 'Public website certificate, renewed automatically by the reverse proxy' : 'Public website certificate, renewed manually at expiry', + 'certificate_domain' => 'www.' . $domain, + 'certificate_names' => 'www.' . $domain . "\n" . $domain, + 'certificate_issued_by' => $profile['cert_issuer'], + 'certificate_issued_at' => $issued, + 'certificate_expire' => $expire, + 'certificate_fingerprint' => $fingerprint('www.' . $domain . $issued), + 'certificate_check_status' => 'ok', + 'certificate_checked_at' => demoDateTime(1 + $index % 3, 3, 30), + 'certificate_notes' => $short_lived ? 'Issued and renewed by the reverse proxy over HTTP-01 - port 80 has to stay open to it.' : 'Renewed by us at expiry - the CSR is generated on the web server and the key never leaves it.', + 'certificate_domain_id' => $domain_id, + 'certificate_client_id' => $client_id, + 'certificate_created_at' => demoMonthDateTime($months, 7, 9, 50), + ]); + starterInsert($mysqli, 'certificate_history', [ + 'certificate_history_column' => 'certificate_expire', + 'certificate_history_old_value' => date('Y-m-d', strtotime($expire . ($short_lived ? ' -60 days' : ' -365 days'))), + 'certificate_history_new_value' => $expire, + 'certificate_history_certificate_id' => $website_id, + 'certificate_history_modified_at' => $issued . ' 04:15:00', + ]); + $counts['documentation']++; + + // The firewall's admin page - the factory certificate, which browsers don't trust + $gateway = $profile['networks'][0][4] ?? ''; + if ($index % 3 === 1 && $gateway !== '') { + starterInsert($mysqli, 'certificates', [ + 'certificate_name' => 'Firewall admin', + 'certificate_description' => 'Management page on the LAN - still the factory self-signed certificate', + 'certificate_domain' => $gateway . ':8443', + 'certificate_names' => $gateway, + 'certificate_issued_by' => 'Self-signed (factory)', + 'certificate_issued_at' => demoDate(365 * 3 + $index * 17), + 'certificate_expire' => demoDate(-1 * (365 * 7 - $index * 17)), + 'certificate_fingerprint' => $fingerprint('fw-' . $domain), + 'certificate_check_status' => 'untrusted', + 'certificate_checked_at' => demoDateTime(1 + $index % 3, 3, 35), + 'certificate_notes' => 'Replace with one from the internal CA at the next firmware upgrade, so the browser warning stops training people to click through.', + 'certificate_client_id' => $client_id, + 'certificate_created_at' => demoMonthDateTime($months, 7, 10, 10), + ]); + $counts['documentation']++; + } + + // A remote access portal renamed in the spring, still serving the old name's certificate + if ($index % 4 === 2) { + starterInsert($mysqli, 'certificates', [ + 'certificate_name' => 'Remote access portal', + 'certificate_description' => 'SSL VPN portal for staff working from home', + 'certificate_domain' => 'remote.' . $domain, + 'certificate_names' => 'vpn.' . $domain, + 'certificate_issued_by' => 'Sectigo', + 'certificate_issued_at' => demoDate(200 + $index), + 'certificate_expire' => demoDate(-1 * (165 - $index)), + 'certificate_fingerprint' => $fingerprint('vpn-' . $domain), + 'certificate_check_status' => 'mismatch', + 'certificate_checked_at' => demoDateTime(1 + $index % 3, 3, 40), + 'certificate_notes' => 'The portal moved from vpn. to remote. - the new certificate is bought but not installed yet.', + 'certificate_domain_id' => $domain_id, + 'certificate_client_id' => $client_id, + 'certificate_created_at' => demoMonthDateTime($months, 7, 10, 20), + ]); + $counts['documentation']++; + } + + // From the client's own CA, for Wi-Fi - nothing to connect to, so nobody checks it + if ($index % 5 === 3) { + starterInsert($mysqli, 'certificates', [ + 'certificate_name' => 'Wi-Fi RADIUS (NPS)', + 'certificate_description' => 'Server certificate the laptops check before joining the staff Wi-Fi', + 'certificate_issued_by' => strtoupper($profile['abbreviation'] ?: substr($domain, 0, 4)) . '-DC01-CA', + 'certificate_expire' => demoDate(-1 * (40 + $index * 3)), + 'certificate_notes' => 'Renew from the internal CA before it expires - when it lapses, every laptop drops off the staff Wi-Fi at once.', + 'certificate_client_id' => $client_id, + 'certificate_created_at' => demoMonthDateTime($months, 7, 10, 30), + ]); + $counts['documentation']++; + } + + return $website_id; +} + + // ------------------------------ // demoBuildAssets // Builds the fleet from the profile's counts, named the way an MSP names kit. diff --git a/agent/ajax.php b/agent/ajax.php index bba15665c..0d2af7700 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -12,32 +12,73 @@ require_once "../includes/check_login.php"; require_once "../libs/totp/totp.php"; /* - * Fetches SSL certificates from remote hosts & returns the relevant info (issuer, expiry, public key) + * The host in a New / Edit Certificate form, checked when asked: connect, + * take the certificate it serves and say what it is - OK, for another name, + * untrusted, expired, or nothing answering - with what will be saved, the + * client's domain it belongs to, and whether the client has it already. */ -if (isset($_GET['certificate_fetch_parse_json_details'])) { - enforceUserPermission('module_support'); +if (isset($_GET['certificate_check'])) { + enforceUserPermission('module_support', 2); - // PHP doesn't appreciate attempting SSL sockets to non-existent domains - if (empty($_GET['domain'])) { - exit(); + header('Content-Type: application/json'); + + $input = trim((string) ($_GET['host'] ?? '')); + $check_client_id = intval($_GET['client_id'] ?? 0); + $check_certificate_id = intval($_GET['certificate_id'] ?? 0); + + if ($input === '') { + echo json_encode(['state' => '', 'message' => '', 'html' => '']); + exit; + } + $host = certificateHost($input); + if (!$host) { + echo json_encode(['state' => 'bad', 'message' => "That isn't a host - something like www.example.com, or portal.example.com:8443.", 'html' => '']); + exit; } - $name = $_GET['domain']; - - // Get SSL cert for domain (if exists) - $certificate = getSslCertificate($name); - - if ($certificate['success'] == "TRUE") { - $response['success'] = "TRUE"; - $response['expire'] = $certificate['expire']; - $response['issued_by'] = $certificate['issued_by']; - $response['public_key'] = $certificate['public_key']; - } else { - $response['success'] = "FALSE"; + $response = ['host' => $host['display'], 'domain_id' => 0, 'html' => '']; + $notes = []; + if (strcasecmp($input, $host['display']) !== 0) { + $notes[] = "Saved as {$host['display']}."; } + // Already on this client? Which of its domains is it under? + if ($check_client_id) { + $client_id = $check_client_id; + enforceClientAccess(); + $host_sql = escapeSql($host['display']); + $existing = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT certificate_name FROM certificates WHERE certificate_domain = '$host_sql' AND certificate_client_id = $check_client_id AND certificate_id <> $check_certificate_id AND certificate_archived_at IS NULL LIMIT 1")); + if ($existing) { + $notes[] = 'This client already has it, as ' . $existing['certificate_name'] . '.'; + } + $response['domain_id'] = certificateDomainFor($host['host'], $check_client_id); + } + + $check = certificateCheck($host); + if (empty($check['reachable'])) { + $response['state'] = 'bad'; + $response['message'] = trim(implode(' ', $notes) . " Nothing answered on {$host['display']} - check the host and port. If ITFlow can't reach it, paste the certificate instead."); + echo json_encode($response); + exit; + } + + $state = CERTIFICATE_CHECK_STATES[$check['status']]; + $response['state'] = $check['status'] === 'ok' ? 'ok' : 'warn'; + $response['message'] = trim(implode(' ', $notes) . ' ' . $state['text'] . '.'); + + $expiry = certificateExpiry(['certificate_expire' => $check['expire'], 'certificate_issued_at' => $check['issued_at']]); + $names = $check['names']; + $response['html'] = '
' + . certificateStatusPill(['certificate_check_status' => $check['status'], 'certificate_domain' => $host['display']]) + . certificateExpiryPill($expiry, true) . '
' + . '
' + . '
Issuer
' . escapeHtml($check['issuer'] ?: 'Unknown') . ($check['self_signed'] ? ' (self-signed)' : '') . '
' + . '
Valid
' . escapeHtml($check['issued_at']) . ' to ' . escapeHtml($check['expire']) . ' (' . $check['days'] . ' days)
' + . '
Covers
' . escapeHtml(implode(', ', array_slice($names, 0, 6))) . (count($names) > 6 ? ' and ' . (count($names) - 6) . ' more' : '') . '
' + . '
'; + echo json_encode($response); - + exit; } /* diff --git a/agent/certificates.php b/agent/certificates.php index 69127855c..87863c071 100644 --- a/agent/certificates.php +++ b/agent/certificates.php @@ -1,5 +1,14 @@ ['label' => 'All', 'where' => ''], + 'starred' => ['label' => 'Starred', 'icon' => 'fa-star', 'where' => 'certificates.certificate_favorite = 1'], + 'soon' => ['label' => 'Expiring soon', 'icon' => 'fa-hourglass-half', 'where' => certificateSoonSql(), + 'title' => 'In the next ' . CERTIFICATE_SOON_DAYS . " days - or 20 for a short-lived one, which should have renewed itself by then"], + 'expired' => ['label' => 'Expired', 'icon' => 'fa-calendar-times', 'where' => 'certificates.certificate_expire < CURDATE()'], + 'problems' => ['label' => 'Problems', 'icon' => 'fa-exclamation-triangle', 'where' => certificateProblemSql(), + 'title' => "The last check found it serving one for another name, an untrusted or expired one - or nothing answered"], + 'unchecked' => ['label' => 'Not checked', 'icon' => 'fa-eye-slash', 'where' => 'certificates.certificate_check_status IS NULL', + 'title' => 'No host to check, or not checked yet'], +]; +$show = isset($shows[$_GET['show'] ?? '']) ? ($_GET['show'] ?? '') : ''; +$show_query = $shows[$show]['where'] ? 'AND ' . $shows[$show]['where'] : ''; + +$expire_days = $_GET['expire_days'] ?? ''; +$expire_query = ''; +if ($expire_days === 'expired') { + $expire_query = 'AND certificates.certificate_expire < CURDATE()'; +} elseif (intval($expire_days) > 0) { + $expire_query = 'AND certificates.certificate_expire BETWEEN CURDATE() AND CURDATE() + INTERVAL ' . intval($expire_days) . ' DAY'; } -$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS certificate_archived_at, certificate_created_at, certificate_description, - certificate_domain, certificate_expire, certificate_id, certificate_issued_by, - certificate_name, client_id, client_name FROM certificates - LEFT JOIN clients ON client_id = certificate_client_id - WHERE $archive_query - AND (certificate_name LIKE '%$q%' OR certificate_domain LIKE '%$q%' OR certificate_description LIKE '%$q%' OR certificate_issued_by LIKE '%$q%' OR client_name LIKE '%$q%') - " . clientScopeSql('certificate_client_id') . " - $client_query - $expire_query - ORDER BY $sort $order LIMIT $record_from, $record_to" -); +// Only these sort - filter_header.php will hand through any lowercase word, and +// an unknown column takes the page down with a mysqli exception +$sortable_columns = ['certificate_name' => 'certificates.certificate_name', 'certificate_domain' => 'certificates.certificate_domain', + 'certificate_issued_by' => 'certificates.certificate_issued_by', 'certificate_expire' => 'certificates.certificate_expire', + 'certificate_checked_at' => 'certificates.certificate_checked_at', 'client_name' => 'client_name', 'certificate_created_at' => 'certificates.certificate_created_at']; +if (!isset($sortable_columns[$sort])) { + $sort = 'certificate_name'; +} +// Certificates without an expiry (or never checked) go last whichever way it is sorted +$sort_sql = (in_array($sort, ['certificate_expire', 'certificate_checked_at'], true) ? "{$sortable_columns[$sort]} IS NULL, " : '') . $sortable_columns[$sort] . " $order"; + +[$certificate_columns, $certificate_joins] = certificateSelectSql(); +$search_query = "AND (certificates.certificate_name LIKE '%$q%' OR certificates.certificate_domain LIKE '%$q%' OR certificates.certificate_description LIKE '%$q%' + OR certificates.certificate_issued_by LIKE '%$q%' OR certificates.certificate_names LIKE '%$q%' OR certificates.certificate_fingerprint LIKE '%$q%' + OR certificates.certificate_notes LIKE '%$q%' OR domains.domain_name LIKE '%$q%' OR client_name LIKE '%$q%')"; +$scope_query = clientScopeSql('certificate_client_id'); +$filters = "$archive_query $issuer_query $search_query $expire_query $scope_query $client_query"; + +$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS $certificate_columns + FROM certificates $certificate_joins + WHERE $filters $show_query + ORDER BY certificates.certificate_favorite DESC, $sort_sql, certificates.certificate_name ASC LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); +$certificates = []; +while ($row = mysqli_fetch_assoc($sql)) { + $certificates[intval($row['certificate_id'])] = $row; +} + +// How many of each, for the pills - everything in scope, before the pill itself +$count_sql = []; +foreach ($shows as $key => $s) { + $count_sql[] = $key === '' ? 'COUNT(*)' : "COALESCE(SUM({$s['where']}), 0)"; +} +$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " FROM certificates $certificate_joins WHERE $filters")); +$counts = []; +foreach (array_keys($shows) as $i => $key) { + $counts[$key] = intval($row[$i]); +} + +$filter_url = function ($changes) { + $params = array_merge($_GET, $changes); + unset($params['page']); + return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null; })); +}; + +// Issuers for the filter - the ones on a certificate in this scope +$sql_issuers_filter = mysqli_query($mysqli, "SELECT certificates.certificate_issued_by, COUNT(*) AS issued FROM certificates $certificate_joins + WHERE $archive_query $scope_query $client_query AND certificates.certificate_issued_by <> '' + GROUP BY certificates.certificate_issued_by ORDER BY certificates.certificate_issued_by ASC"); + +// What the export starts from - the pill, as the export's own filters +$export_extra = [ + 'expire_days' => $show === 'expired' ? 'expired' : ($show === 'soon' ? CERTIFICATE_SOON_DAYS : ''), + 'problems' => $show === 'problems' ? 1 : '', +]; + ?>
-

Certificates

+

Certificates

+
- + + + 0) { ?> - - +
+
+
- -
+
- - + +
- +
+ +
-
-
- -
+
+
- -
-
- -
-
- - -
- - -
-
- "> - Archived +
+
+ + Archived -
-
+ + + +
+ + Clear +
+
-
-
- + + - - "> +
+
+ text-nowrap table-light"> - + + - + $row) { + $row_client_id = intval($row['certificate_client_id']); $certificate_name = escapeHtml($row['certificate_name']); $certificate_description = escapeHtml($row['certificate_description']); - $certificate_domain = escapeHtml($row['certificate_domain']); - $certificate_issued_by = escapeHtml($row['certificate_issued_by']); - $certificate_expire = escapeHtml($row['certificate_expire']); - $certificate_created_at = escapeHtml($row['certificate_created_at']); + $certificate_favorite = intval($row['certificate_favorite']); $certificate_archived_at = escapeHtml($row['certificate_archived_at']); - - $certificate_expire_ago = timeAgo($certificate_expire); - // Convert the expiry date to a timestamp - $certificate_expire_timestamp = strtotime($row['certificate_expire']); - $current_timestamp = time(); // Get current timestamp - - // Calculate the difference in days - $days_until_expiry = ($certificate_expire_timestamp - $current_timestamp) / (60 * 60 * 24); - - // Determine the class based on the number of days until expiry - if ($days_until_expiry <= 0) { - $tr_class = "table-secondary"; - } elseif ($days_until_expiry <= 1) { - $tr_class = "table-danger"; - } elseif ($days_until_expiry <= 7) { - $tr_class = "table-warning"; - } else { - $tr_class = ''; - } + $host = certificateHost($row['certificate_domain']); + $names = certificateNames($row); + $other_names = $host ? array_values(array_filter($names, function ($covered) use ($host) { return strtolower($covered) !== $host['host']; })) : $names; + $expiry = certificateExpiry($row); + $quick_url = "modals/certificate/certificate.php?id=$certificate_id"; ?> - + + - - - - - - + + + - + - - +
+ +
- +
- +
- - Name + + Certificate - - Domain + + Host - - Issued By + + Issuer - - Expire + + Expires + + + + Last check - + Client Action
- - +
- -
- -
-
-
-
+ +
+
+ +
+ + + Archived + +
+
- +
-
- -
+
+ +
+ + +
+ + No host + + +
+ +
+ +
+ +
+ + +
!empty($row['domain_archived_at'])]) ?>
+ +
+ +
+ + - + +
+ + +
+ +
+ + +
- +
- -
-
+
+ + +
+ +
+
+
+ + + + 'That certificate no longer exists.']); + exit; +} +$client_id = intval($certificate['certificate_client_id']); +enforceClientAccess(); + +// When it was last looked at - kept off the updated date +mysqli_query($mysqli, "UPDATE certificates SET certificate_accessed_at = NOW(), certificate_updated_at = certificate_updated_at WHERE certificate_id = $certificate_id"); + +$certificate_name = escapeHtml($certificate['certificate_name']); +$certificate_archived = !empty($certificate['certificate_archived_at']); +$can_edit = certificateCan(2) && !$certificate_archived; +$host = certificateHost($certificate['certificate_domain']); +$expiry = certificateExpiry($certificate); +$parsed = certificateParse($certificate['certificate_public_key']); +$names = certificateNames($certificate); +$services = certificateServices($certificate_id); +$history = certificateHistory($certificate_id, 15); +$pem = $parsed ? $parsed['pem'] : ''; +$fingerprint = trim((string) $certificate['certificate_fingerprint']); + +// What the last check found, said in full when it is a problem - with what to do about it +$status_problem = null; +$status = (string) $certificate['certificate_check_status']; +if ($status !== 'ok' && isset(CERTIFICATE_CHECK_STATES[$status])) { + $status_problem = CERTIFICATE_CHECK_STATES[$status]; + $status_problem['hint'] = [ + 'mismatch' => 'install the certificate for this name, or check the host is right', + 'untrusted' => !$parsed ? 'replace a self-signed certificate with one from a CA (or your own CA, for internal hosts), or install the intermediate certificates with it' + : ($parsed['self_signed'] ? 'replace the self-signed certificate with one from a CA (or your own CA, for internal hosts)' : 'install the intermediate certificates with it'), + 'expired' => 'renew it, and install the new one', + 'unreachable' => 'check the host and port, or that ITFlow can reach it', + ][$status] ?? ''; +} + +// Covered names - the host's own first, then the rest as the certificate lists them +if ($host && $names) { + usort($names, function ($a, $b) use ($host) { + return intval(certificateCovers($host['host'], [$b])) - intval(certificateCovers($host['host'], [$a])); + }); +} + +ob_start(); + +?> + + + + + + + +
+ + + -
- - 'That certificate no longer exists.']); + exit; +} +$client_id = intval($certificate['certificate_client_id']); enforceClientAccess(); +$certificate_form_mode = 'edit'; +$certificate_name = escapeHtml($certificate['certificate_name']); +$certificate_description = escapeHtml($certificate['certificate_description']); +$certificate_domain = escapeHtml($certificate['certificate_domain']); +$certificate_domain_id = intval($certificate['certificate_domain_id']); +$certificate_issued_by = escapeHtml($certificate['certificate_issued_by']); +$certificate_expire = escapeHtml($certificate['certificate_expire']); +$certificate_notes = escapeHtml($certificate['certificate_notes']); +$certificate_favorite = intval($certificate['certificate_favorite']); +// Only a real certificate is shown to keep - anything else on file is cleared on save +$certificate_public_key = certificateParse($certificate['certificate_public_key']) ? escapeHtml(trim($certificate['certificate_public_key'])) : ''; + ob_start(); ?> -
+ -
- - Search
- +
@@ -86,6 +89,17 @@ ob_start();
+
+ +
+ + +
+
+
diff --git a/agent/modals/certificate/certificate_form.php b/agent/modals/certificate/certificate_form.php new file mode 100644 index 000000000..578c2594c --- /dev/null +++ b/agent/modals/certificate/certificate_form.php @@ -0,0 +1,270 @@ + + + + +
+ + +
+
+ +
+ +
+ + +
+
+ +
+ +
+ + > + +
+
Where it is served - a web address is fine, and a port when it isn't 443. Check shows what it serves now; saving a new one checks it.
+
+
+
+ +
+ + +
+
+
+
+ > + +
+
+
+ +
+ + +
+
+
+ + +
+ + +
+
The client's domain it is for - left to itself, the one the host is under.
+ +
Matched to the client's domain the host is under when it's saved.
+ +
+
+
+ + +
+ + +
For a host ITFlow can't reach. The issuer, dates, names it covers and fingerprint are read from it - a whole chain is fine, only the first certificate is kept. Never paste the private key.
+ +
+
Nothing to paste? By hand
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
>Read from the certificate above - clear it to type these.
+
+ +

Certificate ID

+ +
+ + +
+ + +
+ +
+ + diff --git a/agent/modals/domain/domain.php b/agent/modals/domain/domain.php index 594535935..ca6e73cff 100644 --- a/agent/modals/domain/domain.php +++ b/agent/modals/domain/domain.php @@ -134,20 +134,31 @@ ob_start();
- -
Certificates
- +
+ + + +

None on this domain yet.

+ diff --git a/agent/modals/service/service.php b/agent/modals/service/service.php index aa9538ee4..8822d8311 100644 --- a/agent/modals/service/service.php +++ b/agent/modals/service/service.php @@ -63,9 +63,11 @@ $sql_domains = mysqli_query( // Associated Certificates $sql_certificates = mysqli_query( $mysqli, - "SELECT certificate_domain, certificate_name FROM service_certificates - LEFT JOIN certificates ON service_certificates.certificate_id = certificates.certificate_id - WHERE service_id = $service_id" + "SELECT certificates.certificate_id, certificate_domain, certificate_name, certificate_issued_at, certificate_expire, certificate_check_status, + certificate_checked_at, certificate_archived_at FROM service_certificates + JOIN certificates ON service_certificates.certificate_id = certificates.certificate_id + WHERE service_id = $service_id + ORDER BY certificate_name" ); // Associated Vendors @@ -194,14 +196,13 @@ ob_start(); 0) { - echo "
Certificates