Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: cURL и безопасное соединение HTTPS
Форумы портала PHP.SU » » Работа с сетью » cURL и безопасное соединение HTTPS

Страниц (1): [1]
 

1. Dragon_Knight - 20 Января, 2017 - 04:08:00 - перейти к сообщению
Всем привет.

Прошу помощи в организации безопасного соединения с удалённым хостом.

Мои действия были такие:
1) Взял с хоста все 3 сертификата и записал их в один файл 'api_telegram_org.crt';
2) Создал самоподписной сертификат 'public.pem' и 'private.key';
3) Написал следующую функцию:
PHP:
скопировать код в буфер обмена
  1. function get_web_page($url)
  2. {
  3.         $ch = curl_init($url);
  4.  
  5.         curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  6.         curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  7.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  8.         curl_setopt($ch, CURLOPT_FORBID_REUSE, false);
  9.         curl_setopt($ch, CURLOPT_FRESH_CONNECT, false);
  10.         curl_setopt($ch, CURLOPT_HEADER, false);
  11.         curl_setopt($ch, CURLOPT_HTTPGET, true);
  12.         curl_setopt($ch, CURLOPT_POST, false);
  13.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  15.         curl_setopt($ch, CURLOPT_VERBOSE, true);
  16.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  17.         curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  18.         curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  19.         curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
  20.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  21.         curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
  22.         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  23.         curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/api_telegram_org.crt");
  24.         curl_setopt($ch, CURLOPT_ENCODING, "");
  25.         curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . "/public.pem");
  26.         //curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "");
  27.         curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");
  28.         curl_setopt($ch, CURLOPT_SSLKEY, getcwd() . "/private.key");
  29.         //curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "");
  30.         curl_setopt($ch, CURLOPT_SSLKEYTYPE, "PEM");
  31.         curl_setopt($ch, CURLOPT_USERAGENT, "MikroTikManagementSystem/1.0");
  32.  
  33.         $content = curl_exec($ch);
  34.         $err = curl_errno($ch);
  35.         $errmsg = curl_error($ch);
  36.         $header = curl_getinfo($ch);
  37.         curl_close( $ch );
  38.  
  39.         $header['errno']   = $err;
  40.         $header['errmsg']  = $errmsg;
  41.         $header['content'] = $content;
  42.  
  43.         return $header;
  44. }


При выполнении получаю следующий ответ:
PHP:
скопировать код в буфер обмена
  1. (
  2.     [url] => https://api.telegram.org/bot.....
  3.     [content_type] => application/json
  4.     [http_code] => 401
  5.     [header_size] => 279
  6.     [request_size] => 188
  7.     [filetime] => -1
  8.     [ssl_verify_result] => 0
  9.     [redirect_count] => 0
  10.     [total_time] => 0.219
  11.     [namelookup_time] => 0
  12.     [connect_time] => 0.063
  13.     [pretransfer_time] => 0.172
  14.     [size_upload] => 0
  15.     [size_download] => 58
  16.     [speed_download] => 264
  17.     [speed_upload] => 0
  18.     [download_content_length] => 58
  19.     [upload_content_length] => -1
  20.     [starttransfer_time] => 0.219
  21.     [redirect_time] => 0
  22.     [certinfo] => Array
  23.         (
  24.         )
  25.  
  26.     [primary_ip] => 149.154.167.199
  27.     [primary_port] => 443
  28.     [local_ip] => 10.0.1.20
  29.     [local_port] => 18552
  30.     [redirect_url] =>
  31.     [errno] => 0
  32.     [errmsg] =>
  33.     [content] => {....}
  34. )


Из всего этого ответа непонятно два пункта: '[ssl_verify_result] => 0' и пусто массив '[certinfo]'. Почему 0, и как найти список кодов? И почему массив информации сертификата пустой?
И вообще как можно проверить, что все сертификаты работают и всё надёжно на уровне "больной параноик"?
2. Sail - 20 Января, 2017 - 10:56:24 - перейти к сообщению
Dragon_Knight, по п.2. Это ведь самозаверенный сертификат. Как CURL, или telegram его проверит?
Например, API Telegram на этот случай есть особая инструкция.
3. Dragon_Knight - 20 Января, 2017 - 14:49:55 - перейти к сообщению
Sail, Спасибо за ответ.
Та инструкция для хука, который я не могу использовать Недовольство, огорчение
Да и вообще мои знания в вопросе SSL заканчиваются ровно там, где начинаются, поэтому и прошу помощи.
4. Dragon_Knight - 21 Января, 2017 - 20:39:54 - перейти к сообщению
Прошу помощи Огорчение

 

Powered by ExBB FM 1.0 RC1