Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSL option for clients to allow non-standard port options #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions app/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function connectToServer(string $sharedUrl, $subdomain, $authToken = ''):
$deferred = new Deferred();
$promise = $deferred->promise();

$wsProtocol = $this->configuration->port() === 443 ? 'wss' : 'ws';
$wsProtocol = $this->configuration->ssl() ? 'wss' : 'ws';

connect($wsProtocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control?authToken={$authToken}", [], [
'X-Expose-Control' => 'enabled',
Expand Down Expand Up @@ -117,12 +117,8 @@ public function connectToServer(string $sharedUrl, $subdomain, $authToken = ''):
});

$connection->on('authenticated', function ($data) use ($deferred, $sharedUrl) {
$httpProtocol = $this->configuration->port() === 443 ? 'https' : 'http';
$host = $this->configuration->host();

if ($httpProtocol !== 'https') {
$host .= ":{$this->configuration->port()}";
}
$httpProtocol = $this->configuration->ssl() ? 'https' : 'http';
$host = $this->getHost();

$this->logger->info($data->message);
$this->logger->info("Local-URL:\t\t{$sharedUrl}");
Expand Down Expand Up @@ -172,4 +168,17 @@ protected function retryConnectionOrExit(string $sharedUrl, $subdomain, $authTok
exit(1);
}
}

private function getHost()
{
$host = $this->configuration->host();
if ($this->configuration->port() === 80 && ! $this->configuration->ssl()) {
return $host;
}
if ($this->configuration->port() === 443 && $this->configuration->ssl()) {
return $host;
}

return "{$host}:{$this->configuration->port()}";
}
}
16 changes: 15 additions & 1 deletion app/Client/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ class Configuration
/** @var string|null */
protected $auth;

public function __construct(string $host, int $port, ?string $auth = null)
/** @var bool|null */
protected $ssl;

public function __construct(string $host, int $port, ?string $auth = null, $ssl = null)
{
$this->host = $host;

$this->port = $port;

$this->auth = $auth;

$this->ssl = $ssl;
}

public function host(): string
Expand All @@ -36,4 +41,13 @@ public function port(): int
{
return intval($this->port);
}

public function ssl(): bool
{
if ($this->ssl === null) {
return $this->port() === 443;
}

return boolval($this->ssl);
}
}
12 changes: 11 additions & 1 deletion app/Client/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Factory
/** @var string */
protected $auth = '';

/** @var bool|null */
protected $ssl = null;

/** @var \React\EventLoop\LoopInterface */
protected $loop;

Expand Down Expand Up @@ -63,6 +66,13 @@ public function setAuth(?string $auth)
return $this;
}

public function setSsl(?bool $ssl)
{
$this->ssl = $ssl;

return $this;
}

public function setLoop(LoopInterface $loop)
{
$this->loop = $loop;
Expand All @@ -73,7 +83,7 @@ public function setLoop(LoopInterface $loop)
protected function bindConfiguration()
{
app()->singleton(Configuration::class, function ($app) {
return new Configuration($this->host, $this->port, $this->auth);
return new Configuration($this->host, $this->port, $this->auth, $this->ssl);
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/Client/ProxyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(Configuration $configuration, LoopInterface $loop)

public function createProxy(string $clientId, $connectionData)
{
$protocol = $this->configuration->port() === 443 ? 'wss' : 'ws';
$protocol = $this->configuration->ssl() ? 'wss' : 'ws';

connect($protocol."://{$this->configuration->host()}:{$this->configuration->port()}/expose/control", [], [
'X-Expose-Control' => 'enabled',
Expand Down
1 change: 1 addition & 0 deletions app/Commands/ShareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function handle()
->setLoop(app(LoopInterface::class))
->setHost(config('expose.host', 'localhost'))
->setPort(config('expose.port', 8080))
->setSsl(config('expose.ssl', null))
->setAuth($this->option('auth'))
->createClient()
->share($this->argument('host'), explode(',', $this->option('subdomain')))
Expand Down
13 changes: 13 additions & 0 deletions config/expose.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
*/
'port' => 443,

/*
|--------------------------------------------------------------------------
| SSL
|--------------------------------------------------------------------------
|
| If Expose is to consider this as a SSL port.
| this allows SSL use if you are using a non-standard SSL port.
| If null, assume SSL if 443, set to true to force SSL
| use false to force no SSL
|
*/
'ssl' => null,

/*
|--------------------------------------------------------------------------
| Auth Token
Expand Down