【问题标题】:PHP - how to get SSL key lengthPHP - 如何获取 SSL 密钥长度
【发布时间】:2015-11-16 18:47:50
【问题描述】:

我有一个使用 fopen 的脚本(是的,我知道,但这是出于遗留原因)来检索 SSL 证书的详细信息。现在他们想将 SSL 密钥长度添加到提取中,但我找不到它。我可以使用 CURL 重构,但提取的变量太多,解析结果需要很长时间。有什么简单的方法可以获取我缺少的密钥长度吗?

我已经改用它来获取证书详细信息:

$r = stream_socket_client("ssl://www.google.com:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $g);
$cont = stream_context_get_params($r);
$temp = openssl_x509_parse($cont["options"]["ssl"]["peer_certificate"]);

然后我从数组中取出数据

【问题讨论】:

  • 请添加一些关于您正在使用的 SSL 证书类型的代码。
  • 我不太明白你在问什么。我正在解析很多 SSL 证书。如果只是一个,我会使用浏览器。
  • @RobbieAverill 谢谢。我正在使用它来获取证书详细信息。 $r = stream_socket_client("ssl://www.google.com:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $g); 不知道怎么用这个函数
  • 在问题关闭之前将它放入您的问题中:)

标签: php ssl curl fopen


【解决方案1】:
<?php
    $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,
        "cafile"=>'/etc/ssl/certs/ca-certificates.crt' //mozilla ca cert bundle: http://curl.haxx.se/docs/caextract.html
    ];
    $g = stream_context_create (["ssl" => $ssloptions]);
    $r = stream_socket_client("ssl://$domain:$port", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $g);
    $cont = stream_context_get_params($r);
    $key = openssl_pkey_get_public($cont["options"]["ssl"]["peer_certificate"];);
    $res = openssl_pkey_get_details($key);
    echo $res['bits'];

?>

【讨论】:

    猜你喜欢
    • 2019-07-29
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 2019-11-11
    • 1970-01-01
    相关资源
    最近更新 更多