|
15 | 15 |
|
16 | 16 | use Bolt\connection\StreamSocket;
|
17 | 17 | use Exception;
|
| 18 | +use function explode; |
| 19 | +use const FILTER_VALIDATE_IP; |
| 20 | +use function filter_var; |
18 | 21 | use Laudis\Neo4j\Bolt\BoltDriver;
|
19 | 22 | use Laudis\Neo4j\Common\Uri;
|
20 | 23 | use Laudis\Neo4j\Contracts\ConnectionPoolInterface;
|
@@ -52,9 +55,37 @@ public function acquire(UriInterface $uri, AccessMode $mode): StreamSocket
|
52 | 55 | {
|
53 | 56 | $table = $this->routingTable($uri);
|
54 | 57 | $server = $this->getNextServer($table, $mode);
|
55 |
| - $uri = Uri::create($server); |
56 | 58 |
|
57 |
| - return $this->pool->acquire($uri, $mode); |
| 59 | + $socket = $this->pool->acquire(Uri::create($server), $mode); |
| 60 | + |
| 61 | + $scheme = $uri->getScheme(); |
| 62 | + $explosion = explode('+', $scheme, 2); |
| 63 | + $sslConfig = $explosion[1] ?? ''; |
| 64 | + |
| 65 | + if (str_starts_with('s', $sslConfig)) { |
| 66 | + $this->enableSsl($server, $sslConfig, $socket, $uri); |
| 67 | + } |
| 68 | + |
| 69 | + return $socket; |
| 70 | + } |
| 71 | + |
| 72 | + private function enableSsl(string $host, string $sslConfig, StreamSocket $sock, UriInterface $uri): void |
| 73 | + { |
| 74 | + // Pass a standard option to enable ssl as there is no direct flag |
| 75 | + // and \Bolt\Bolt only turns on ssl if an option is passed. |
| 76 | + $options = [ |
| 77 | + 'verify_peer' => true, |
| 78 | + 'peer_name' => $uri->getHost(), |
| 79 | + ]; |
| 80 | + if (!filter_var($host, FILTER_VALIDATE_IP)) { |
| 81 | + $options['SNI_enabled'] = true; |
| 82 | + } |
| 83 | + if ($sslConfig === 's') { |
| 84 | + $sock->setSslContextOptions($options); |
| 85 | + } elseif ($sslConfig === 'ssc') { |
| 86 | + $options['allow_self_signed'] = true; |
| 87 | + $sock->setSslContextOptions($options); |
| 88 | + } |
58 | 89 | }
|
59 | 90 |
|
60 | 91 | /**
|
|
0 commit comments