PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи

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

> Найдено сообщений: 3
Zelenuy Отправлено: 23 Марта, 2014 - 13:43:39 • Тема: Проблема с сокетом • Форум: Работа с сетью

Ответов: 1
Просмотров: 1739
Вот запускаю чисто openSll
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2. $dn = array(
  3.     "countryName" => "UK",
  4.     "stateOrProvinceName" => "Somerset",
  5.     "localityName" => "Glastonbury",
  6.     "organizationName" => "The Brain Room Limited",
  7.     "organizationalUnitName" => "PHP Documentation Team",
  8.     "commonName" => "Wez Furlong",
  9.     "emailAddress" => "wez@example.com"
  10. );
  11.  
  12. // Generate a new private (and public) key pair
  13. $privkey = openssl_pkey_new();
  14.  
  15. // Generate a certificate signing request
  16. $csr = openssl_csr_new($dn, $privkey);
  17.  
  18.  
  19. $sscert = openssl_csr_sign($csr, null, $privkey, 365);
  20.  
  21.  
  22. openssl_csr_export($csr, $csrout) and var_dump($csrout);
  23. openssl_x509_export($sscert, $certout) and var_dump($certout);
  24. openssl_pkey_export($privkey, $pkeyout, "mypassword") and var_dump($pkeyout);
  25.  
  26. // Show any errors that occurred here
  27. while (($e = openssl_error_string()) !== false) {
  28.     echo $e . "\n";
  29. }
  30. ?>

Вот чего выдает
Цитата:
Warning: openssl_csr_sign(): cannot get CSR from parameter 1 in C:\OpenServer\domains\site.ru\ssl.php on line 20

Warning: openssl_csr_export() expects parameter 1 to be resource, boolean given in C:\OpenServer\domains\site.ru\ssl.php on line 23

Warning: openssl_x509_export(): cannot get cert from parameter 1 in C:\OpenServer\domains\site.ru\ssl.php on line 24

Warning: openssl_pkey_export(): cannot get key from parameter 1 in C:\OpenServer\domains\site.ru\ssl.php on line 25
error:02001003:system library:fopen:No such process error:2006D080:BIO routines:BIO_new_file:no such file error:0E064002:configuration file routines:CONF_load:system lib error:02001003:system library:fopen:No such process error:2006D080:BIO routines:BIO_new_file:no such file error:0E064002:configuration file routines:CONF_load:system lib error:02001003:system library:fopen:No such process error:2006D080:BIO routines:BIO_new_file:no such file error:0E064002:configuration file routines:CONF_load:system lib error:02001003:system library:fopen:No such process error:2006D080:BIO routines:BIO_new_file:no such file error:0E064002:configuration file routines:CONF_load:system lib
Zelenuy Отправлено: 23 Марта, 2014 - 11:27:05 • Тема: Проблема с сокетом • Форум: Работа с сетью

Ответов: 1
Просмотров: 1739
Вот хочу собрать сервер с использованием SSL туннеля, но информации почти не где нет на эту тему, кое какие примеры нашел но они по чему-то отказываются работать, помогите разобраться
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2. $dn = array(
  3.     "countryName" => "UK",
  4.     "stateOrProvinceName" => "Somerset",
  5.     "localityName" => "Glastonbury",
  6.     "organizationName" => "The Brain Room Limited",
  7.     "organizationalUnitName" => "PHP Documentation Team",
  8.     "commonName" => "Wez Furlong",
  9.     "emailAddress" => "wez@example.com"
  10. );
  11.  
  12. $privkey = openssl_pkey_new();
  13. $cert    = openssl_csr_new($dn, $privkey);
  14. $cert    = openssl_csr_sign($cert, null, $privkey, 365);
  15.  
  16. $pem_passphrase = 'comet';
  17. $pem = array();
  18. openssl_x509_export($cert, $pem[0]);
  19. openssl_pkey_export($privkey, $pem[1], $pem_passphrase);
  20. $pem = implode($pem);
  21.  
  22. $pemfile = './server.pem';
  23. file_put_contents($pemfile, $pem);
  24.  
  25. $context = stream_context_create();
  26.  
  27. stream_context_set_option($context, 'ssl', 'local_cert', $pemfile);
  28.  
  29. stream_context_set_option($context, 'ssl', 'passphrase', $pem_passphrase);
  30.  
  31. stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
  32. stream_context_set_option($context, 'ssl', 'verify_peer', false);
  33.  
  34. $server = stream_socket_server('ssl://127.0.0.1:2000', $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
  35.  
  36. while(true)
  37. {
  38.     $buffer = '';
  39.     print "waiting...";
  40.     $client = stream_socket_accept($server);
  41.     print "accepted " . stream_socket_get_name( $client, true) . "\n";
  42.     if( $client )
  43.     {
  44.         // Read until double CRLF
  45.         while( !preg_match('/\r?\n\r?\n/', $buffer) )
  46.             $buffer .= fread($client, 2046);
  47.         // Respond to client
  48.         fwrite($client,  "200 OK HTTP/1.1\r\n"
  49.             . "Connection: close\r\n"
  50.             . "Content-Type: text/html\r\n"
  51.             . "\r\n"
  52.             . "Hello World! " . microtime(true)
  53.             . "<pre>{$buffer}</pre>");
  54.         fclose($client);
  55.     } else {
  56.         print "error.\n";
  57.     }
  58. }
  59. ?>

Растерялся Вроде запускается, но соединится не получается, грешу на функции openSSL, так как они почти все false
Zelenuy Отправлено: 18 Марта, 2014 - 14:41:17 • Тема: OpenSSL Не работает • Форум: Программирование на PHP

Ответов: 3
Просмотров: 3250
Тоже openssl вроде не работает, уже все примеры из мануала перепробовал, не один из них не заработал, в php ini библиотека подключена Растерялся
Microteam
Ваш пример у меня не завис а просто выдал: Fatal error: Call to undefined function openssl_get_privkey()
(Добавление)
Огорчение Вот тоже не могу заставить работать
PHP:
скопировать код в буфер обмена
  1. <?
  2. $dn = array("countryName" => 'XX', "stateOrProvinceName" => 'State', "localityName" => 'SomewhereCity', "organizationName" => 'MySelf', "organizationalUnitName" => 'Whatever', "commonName" => 'mySelf', "emailAddress" => 'user@domain.com');
  3. $privkeypass = '1234';
  4. $numberofdays = 365;
  5.  
  6. $privkey = openssl_pkey_new();
  7. $csr = openssl_csr_new($dn, $privkey);
  8. $sscert = openssl_csr_sign($csr, null, $privkey, $numberofdays);
  9. openssl_x509_export($sscert, $publickey);
  10. openssl_pkey_export($privkey, $privatekey, $privkeypass);
  11. openssl_csr_export($csr, $csrStr);
  12.  
  13. echo $privatekey; // Will hold the exported PriKey
  14. echo $publickey;  // Will hold the exported PubKey
  15. echo $csrStr;     // Will hold the exported Certificate
  16. ?>

Результат:
Цитата:
Warning: openssl_csr_sign(): cannot get CSR from parameter 1 in C:\OpenServer\domains\ssl\openssl.php on line 8

Warning: openssl_x509_export(): cannot get cert from parameter 1 in C:\OpenServer\domains\ssl\openssl.php on line 9

Warning: openssl_pkey_export(): cannot get key from parameter 1 in C:\OpenServer\domains\ssl\openssl.php on line 10

Warning: openssl_csr_export() expects parameter 1 to be resource, boolean given in C:\OpenServer\domains\ssl\openssl.php on line 11

Может кто подскажет как эту проблему решить?

Страниц (1): [1]
Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB