Connecting to AWS Neptune with Gremlin.net from a local windows machine

902 Views Asked by At

I'm following Amazon's documentation at access-graph-gremlin-dotnet and trying to run it on a local windows machine that is connected to Neptune with an SSH tunnel through an EC2 instance.
I've tested the SSH tunnel with gremlin console and it works fine.
Running the program on an EC2 instance works as well, but when running the program on a local windows machine I'm getting the following exception because the Neptune's certificate needs to be added to trusted certificates:

System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server ---> 
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner 
 exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is 
invalid according to the validation procedure.

I'm searching for how to do so in Gremlin.Net 3.4.6 (preferable C#).

2

There are 2 best solutions below

1
On BEST ANSWER

You will need to do this:

  1. Open cmd.exe as an Administrator
  2. notepad c:\windows\system32\drivers\hosts
  3. add a line 127.0.0.1 <your neptune cluster endpoint just the name without port>
  4. Save the file
  5. Now try and run the .Net code again

This is because you are most likely connecting to localhost and the certificate is signed for the cluster's hostname, so there is a mismatch.

0
On

Another option is to use webSocketConfiguration parameter to the GremlinClient constructor and using the RemoteCertificateValidationCallback to do manual checking.
You should be extremely careful with the certificate validation because of the obvious security risks.

var webSocketConfiguration = new Action<ClientWebSocketOptions>(options => {options.RemoteCertificateValidationCallback=(o, c, ch, er) => Test and return true if certificate is valid;});
var gremlinServer = new GremlinServer(endpoint, 8182, enableSsl: true );
var gremlinClient = new GremlinClient(gremlinServer, webSocketConfiguration: webSocketConfiguration);