我正在编写一个简单的检查器,您可以在其中输入一个 URL,该检查器将检查输入的 URL 是否使用 TLS 1.0、1.1 或 1.2。本质上,我想显示一条消息“Yoursite.com 正在使用 TLS 1.0。建议禁用此功能。”
问题是,只有当我是拨打电话的服务器时,我才能弄清楚。然后我可以使用this https://stackoverflow.com/questions/27904854/verify-if-curl-is-using-tls。这允许您编写 Curl 脚本,连接到 howsmyssl.com,它将返回我用来连接的连接。这不是我想要的。
我想知道如何使用 PHP 连接到 URL,并查看该服务器是否支持 TLS1.0、1.1 或 1.2。
有没有办法做到这一点?
这个怎么样:
<?php
$url = 'https://fancyssl.hboeck.de/';
$protocols = [
'TLS1.0' => ['protocol' => CURL_SSLVERSION_TLSv1_0, 'sec' => false],
'TLS1.1' => ['protocol' => CURL_SSLVERSION_TLSv1_1, 'sec' => false],
'TLS1.2' => ['protocol' => CURL_SSLVERSION_TLSv1_2, 'sec' => true],
'TLS1.3' => ['protocol' => CURL_SSLVERSION_TLSv1_3, 'sec' => true],
];
foreach ($protocols as $name => $value) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLVERSION, $value['protocol']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch) !== false;
if ($value['sec'] && !$response) {
echo "Secure $name not supported =( \n";
} elseif ($value['sec'] && $response) {
echo "Ok! Secure $name supported \n";
} elseif (!$value['sec'] && $response) {
echo "Insecure $name supported =( \n";
} elseif (!$value['sec'] && !$response) {
echo "Ok! Insecure $name not supported\n";
}
}
输出是:
Ok! Insecure TLS1.0 not supported
Ok! Insecure TLS1.1 not supported
Ok! Secure TLS1.2 supported
Ok! Secure TLS1.3 supported
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)