2024-01-10 21:08:25 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
assert(function_exists('openssl_digest'));
|
|
|
|
|
assert(openssl_digest('123456', 'md5') === 'e10adc3949ba59abbe56e057f20f883e');
|
2025-01-28 19:37:50 +08:00
|
|
|
if (file_exists('/etc/ssl/openssl.cnf')) {
|
2025-08-02 18:40:55 +08:00
|
|
|
$domain_list = [
|
2025-08-03 01:23:47 +08:00
|
|
|
'captive.apple.com',
|
|
|
|
|
'detectportal.firefox.com',
|
|
|
|
|
'static-php.dev',
|
|
|
|
|
'www.example.com',
|
2025-08-02 18:40:55 +08:00
|
|
|
];
|
|
|
|
|
$valid = false;
|
|
|
|
|
foreach ($domain_list as $domain) {
|
2025-08-03 01:23:47 +08:00
|
|
|
$ssloptions = [
|
|
|
|
|
'capture_peer_cert' => true,
|
|
|
|
|
'capture_peer_cert_chain' => true,
|
|
|
|
|
'allow_self_signed' => false,
|
|
|
|
|
'CN_match' => $domain,
|
|
|
|
|
'verify_peer' => true,
|
|
|
|
|
'SNI_enabled' => true,
|
|
|
|
|
'SNI_server_name' => $domain,
|
|
|
|
|
];
|
|
|
|
|
$context = stream_context_create(['ssl' => $ssloptions]);
|
|
|
|
|
$result = stream_socket_client("ssl://{$domain}:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
|
|
|
|
|
if ($result !== false) {
|
2025-08-02 18:40:55 +08:00
|
|
|
$valid = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert($valid);
|
2025-01-28 19:37:50 +08:00
|
|
|
}
|
2025-07-30 23:02:28 +08:00
|
|
|
if (PHP_VERSION_ID >= 80500 && defined('OPENSSL_VERSION_NUMBER') && OPENSSL_VERSION_NUMBER >= 0x30200000) {
|
|
|
|
|
assert(function_exists('openssl_password_hash'));
|
|
|
|
|
}
|