Guest User

Untitled

a guest
Apr 26th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout apache.key -out apache.crt
  2.  
  3. apache.crt apache.key > joined.pem
  4.  
  5. <?php
  6. ini_set('display_errors', 1);
  7. ini_set('display_startup_errors', 1);
  8. error_reporting(E_ALL);
  9.  
  10. $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
  11.  
  12. $ctx = stream_context_create(['ssl' => [
  13. 'local_cert' => "{path}/Websites/127.0.0.1/certs/joined.pem",
  14. 'SNI_server_certs' => [
  15. "127.0.0.1" => "{path}/Websites/127.0.0.1/certs/joined.pem",
  16. "localhost" => "{path}//Websites/localhost/certs/joined.pem",
  17. ]
  18. ]]);
  19. stream_context_set_option($ctx, 'ssl', 'ssl_method', 'STREAM_CRYPTO_METHOD_TLSv23_SERVER');
  20. stream_context_set_option($ctx, 'ssl', 'allow_self_signed', true);
  21. stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
  22. stream_context_set_option($ctx, 'ssl', 'ciphers', "HIGH");
  23.  
  24.  
  25. $socket = stream_socket_server("tls://127.0.0.1:8443", $errno, $errstr, $flags, $ctx);
  26.  
  27.  
  28. while ( $client = stream_socket_accept($socket, "-1", $clientIP)):
  29.  
  30. $msg = fread($client, 8192);
  31.  
  32. $resp = "HTTP/1.1 200 OKrnContent-type: text/htmlrnrn<h1>Hi, you are secured.<br>{$msg}";
  33. fwrite($client,$resp );
  34. fclose($client);
  35.  
  36. endwhile;
Add Comment
Please, Sign In to add comment