Ejemplo n.º 1
0
 /**
  * @memcheck
  */
 public function testEncrypt()
 {
     $listener = new Listener(ION_TEST_SERVER_HOST);
     $server_ssl = Crypto::server(Crypto::METHOD_TLSv12)->passPhrase('unittest')->localCert(ION_RESOURCES . '/cacert.pem', ION_RESOURCES . '/cakey.pem')->allowSelfSigned();
     $client_ssl = Crypto::client(Crypto::METHOD_TLSv12)->allowSelfSigned();
     $listener->encrypt($server_ssl);
     $listener->whenAccepted()->then(function (Stream $connect) {
         $this->data["connect"] = $this->describe($connect);
         $this->data["incoming"] = (yield $connect->readLine("\r\n"));
         $connect->write("welcome\r\n");
         (yield $connect->flush());
         $this->stop();
     })->onFail(function (\Throwable $error) {
         $this->data["server.error"] = $this->describe($error);
         $this->stop();
     });
     $this->promise(function () use($client_ssl) {
         $socket = Stream::socket(ION_TEST_SERVER_HOST, $client_ssl);
         $socket->write("hello\r\n");
         $this->data["outgoing"] = (yield $socket->readLine("\r\n"));
     }, false);
     $this->loop();
     $this->assertEquals(["connect" => ["object" => "ION\\Stream"], "incoming" => "hello", "outgoing" => "welcome"], $this->data);
 }
Ejemplo n.º 2
0
 /**
  * @memcheck
  */
 public function testEncrypted()
 {
     $this->promise(function () {
         $socket = Stream::socket("example.com:443", Crypto::client());
         $socket->write(implode("\r\n", ["GET / HTTP/1.1", "Host: example.com", "Connection: close", "Accept: text/html", "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36", "Accept-Language: en-US,en;q=0.8,ru;q=0.6"]) . "\r\n\r\n");
         $this->data["response"] = (yield $socket->readAll());
     });
     $this->loop(1);
     $this->assertTrue(isset($this->data["response"]));
     $this->assertEquals("HTTP/1.1 200 OK", strstr($this->data["response"], "\r\n", true));
 }
Ejemplo n.º 3
0
 /**
  * @memcheck
  */
 public function testLoadCA()
 {
     Crypto::server()->ca(ION_RESOURCES . '/cacert.pem');
 }
Ejemplo n.º 4
0
<?php

$client = new \ION\Stream\Storage();
$server = new \ION\Stream\Server();
$server->listen("0.0.0.0:8080");
$server->listen("0.0.0.0:8443")->encrypt(\ION\Crypto::server());
$server->whenIncoming()->then(function (\ION\HTTP\Request $proxy_req) use($client) {
    $uri = $proxy_req->getUri();
    $body = new \ION\HTTP\Body($proxy_req);
    $body = new \ION\HTTP\Body\MultiParted($proxy_req);
    while ($part = (yield $body->readPart(2 * MiB))) {
        if ($part->isComplete()) {
        } else {
            while ($chunk = (yield $part->read(2 * MiB))) {
            }
        }
    }
    $target_host = $uri->getHost() . ":" . $uri->getPort();
    $stream = (yield $client->fetchStream($target_host)->timeout(10));
    $request = $proxy_req->withUri($uri->relative());
    //	$response_out = yield $stream->write($request)->flush();
    //
    //	if(!$proxy_req->getHeaderLine("transfer-encoding") == "Chunked") {
    //		$proxy_content = new \ION\HTTP\Content\Chunked($stream);
    //		$content = new \ION\HTTP\Content\Chunked($stream);
    //	} else if($proxy_req->getHeaderLine("content-length") > 2 * MiB) {
    //		$reader = $proxy_req->getContentReader();
    //	} else {
    //
    //	}
    //