Problem: My demo code client unable to connect to the Azure Cosmos emulator on Windows 10.
Steps:
I installed the Cosmosdb emulator on Windows - looks fine
As per documentation, I started the Windows cert manage.msc. I selected private cert with friendly name "DocumentDBEmulatorCertificate" as base64 encoded x.509.cer file to local disk
I started the cmd console in Windows as administrator and cd to local JAVA_HOME/lib/security directory (I'm using Java 8.0.131)
I ran keytool with this
keytool -import -trustcacerts -keystore cacerts -storepass changeit -noprompt -alias azureCosmossDBEmulator -file "D:\exported certificates\cosmossDB-emulator-cert.cer"
I listed out the revised keystore to
dump.txt
file. I can see my entry in the dumpazurecosmossdbemulator, 30-Aug-2017, trustedCertEntry, Certificate fingerprint (SHA1): 5B:F4:14:BE:9F:2B:7F:6A:2B:C0:87:A4:3E:4D:9A:52:45:FA:2F:EA
and this matches the thumbprint value in the x.509 cert.
I restarted Intellij on my build, and checked that Java 8.0.1.3.1 was the only jdk in the project.
I fired up Groovy test script in debug and stepped through code. I can create DocumentClient ok.
This is just a rough script to test connection code looks like this
final String key = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" DocumentClient client = new DocumentClient("https://localhost:8081", key , new ConnectionPolicy(), ConsistencyLevel.Session) String dbname = "familyDB" String dblink = "/dbs/$dbname" //create db if not exists try { client.readDatabase(dblink,null) println "found db $dbname" } catch (DocumentClientException de) { if (de.getStatusCode() == 404) { Database db = new Database() db.id = dbname client.createDatabase(db, null) println "created new DB $dbname" } else { throw de } }
When I get to the client.readDatabase line I get an exception like this:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Caught: java.lang.IllegalStateException: Http client execution failed.
java.lang.IllegalStateException: Http client execution failed.
at com.microsoft.azure.documentdb.internal.GatewayProxy.performGetRequest(GatewayProxy.java:234)
at com.microsoft.azure.documentdb.internal.GatewayProxy.doRead(GatewayProxy.java:89)
at com.microsoft.azure.documentdb.internal.GatewayProxy.processMessage(GatewayProxy.java:336)
at com.microsoft.azure.documentdb.DocumentClient$8.apply(DocumentClient.java:2985)
at com.microsoft.azure.documentdb.internal.RetryUtility.executeDocumentClientRequest(RetryUtility.java:58)
at com.microsoft.azure.documentdb.DocumentClient.doRead(DocumentClient.java:2991)
at com.microsoft.azure.documentdb.DocumentClient.readDatabase(DocumentClient.java:491)
at com.microsoft.azure.documentdb.DocumentClient$readDatabase.call(Unknown Source)
at com.softwood.azure.client.cosmossDBClientScript.run(cosmossDBClientScript.groovy:29)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.microsoft.azure.documentdb.internal.GatewayProxy.performGetRequest(GatewayProxy.java:231)
... 8 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
... 20 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
... 20 more
which basically states it can't find my cacert entry and refuses to connect.
What's gone wrong? (I haven't restarted Windows yet). The cert looks ok, the import seemed to work via keytool into cacerts, I'm using single jdk ref, but code won't connect.
How can I unravel what I have not done correctly, and must now do to have the code connect from Java into Azure DB emulator running locally in my Windows 10 machine?