Skip to content

Commit b27a041

Browse files
committed
Fixes routing in neo4j aura
Fixes #57
1 parent 3b32cb8 commit b27a041

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/Neo4j/Neo4jConnectionPool.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
use Bolt\connection\StreamSocket;
1717
use Exception;
18+
use function explode;
19+
use const FILTER_VALIDATE_IP;
20+
use function filter_var;
1821
use Laudis\Neo4j\Bolt\BoltDriver;
1922
use Laudis\Neo4j\Common\Uri;
2023
use Laudis\Neo4j\Contracts\ConnectionPoolInterface;
@@ -52,9 +55,37 @@ public function acquire(UriInterface $uri, AccessMode $mode): StreamSocket
5255
{
5356
$table = $this->routingTable($uri);
5457
$server = $this->getNextServer($table, $mode);
55-
$uri = Uri::create($server);
5658

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+
}
5889
}
5990

6091
/**

0 commit comments

Comments
 (0)