Hi Shevindi, I believe you are using -k option when running the curl command, which would avoid the certificate validation and hostname verification at client (curl) side.
Since this is just a test, we can bypass hostname verification and certificate validation and get it to working. For that, we need to override the trust manager and the default hostname verifier and create the SSL Context which will be used for the HTTPS communication. You can find some sample code in [1]. [1] https://github.com/wso2/carbon-identity-framework/blob/v5.12.153/components/authentication-framework/org.wso2.carbon.identity.application.authentication.endpoint.util/src/main/java/org/wso2/carbon/identity/application/authentication/endpoint/util/TenantMgtAdminServiceClient.java#L179 Best Regards, Tharindu Edirisinghe On Thu, Jan 31, 2019 at 1:32 PM Shevindi Rodrigo <[email protected]> wrote: > Hi All, > > I'm working on splunk connector for EI. To access splunk rest API over > https, we have to import the self sign certificate. For that, I got the > certificate server.pem file from the installation directory of splunk and > import that certificate into the EI client-truststore using the keytool > command [1]. When I try this splunk connector via management console, it > working fine. > But to write the integration test cases, I import the same certificate > file into EI client-truststore and wso2carbon.jks as in [2] . In > integration test case, when I try to invoke the splunk api using java > client[4] as in [3], I'm getting the response as in [5] although the same > apiEndpoint works fine with curl. > > Can anyone help me to solve this? > > [1] keytool -importcert -file server.pem -keystore client-truststore.jks > -alias splunk > [2] > keytool -importcert -file server.pem -keystore client-truststore.jks > -alias splunk > keytool -importcert -file server.pem -keystore wso2carbon.jks -alias > splunk2 > > [3] > String apiEndpoint = "https://" + > connectorProperties.getProperty("hostname") + ":" + > connectorProperties.getProperty("port") + "/servicesNS/" + > connectorProperties.getProperty("appUserName") + "/" + > connectorProperties.getProperty("appName") + "/saved/searches/" + > connectorProperties.getProperty("searchName"); > RestResponse<OMElement> apiRestResponse = > sendXmlRestRequest(apiEndpoint,"GET",apiRequestHeadersMap); > Assert.assertEquals(searchName,getValueByExpression("//entry/title", > apiRestResponse.getBody())); > > [4] > https://github.com/wso2-extensions/esb-integration-base/blob/master/src/main/java/org/wso2/connector/integration/test/base/ConnectorIntegrationTestBase.java#L441 > <https://www.google.com/url?q=https://github.com/wso2-extensions/esb-integration-base/blob/master/src/main/java/org/wso2/connector/integration/test/base/ConnectorIntegrationTestBase.java%23L441&sa=D&source=hangouts&ust=1548916323291000&usg=AFQjCNHyRrxk4i8gSaJ7A6gJOmMOLIoTKg> > > [5] > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > *INFO [org.wso2.esb.integration.common.utils.ESBTestCaseUtils] - splunk > Proxy undeployed in 0 millisFAILED: testCreateSavedSearchMandatory > splunk {createSavedSearch} integration test with mandatory > parameters.javax.net.ssl.SSLHandshakeException: > java.security.cert.CertificateException: No name matching localhost > found at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at > sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) at > sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) at > sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) at > sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1506) > at > sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) > at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) at > sun.security.ssl.Handshaker.process_record(Handshaker.java:914) at > sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) at > sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) > at > sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) > at > sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) > at > sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) > at > sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) > at > sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512) > at > sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440) > at > java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) > at > sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338) > at > org.wso2.connector.integration.test.base.ConnectorIntegrationTestBase.readResponse(ConnectorIntegrationTestBase.java:1073) > at > org.wso2.connector.integration.test.base.ConnectorIntegrationTestBase.sendXmlRestRequest(ConnectorIntegrationTestBase.java:630) > at > org.wso2.connector.integration.test.base.ConnectorIntegrationTestBase.sendXmlRestRequest(ConnectorIntegrationTestBase.java:444) > at > org.wso2.carbon.connector.integration.test.splunk.SplunkConnectorIntegrationTest.testCreateSavedSearchMandatory(SplunkConnectorIntegrationTest.java:97) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:497) at > org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) > at org.testng.internal.Invoker.invokeMethod(Invoker.java:673) at > org.testng.internal.Invoker.invokeTestMethod(Invoker.java:842) at > org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1166) at > org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) > at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) > at org.testng.TestRunner.runWorkers(TestRunner.java:1178) at > org.testng.TestRunner.privateRun(TestRunner.java:757) at > org.testng.TestRunner.run(TestRunner.java:608) at > org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at > org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) at > org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) at > org.testng.SuiteRunner.run(SuiteRunner.java:240) at > org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at > org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at > org.testng.TestNG.runSuitesSequentially(TestNG.java:1158) at > org.testng.TestNG.runSuitesLocally(TestNG.java:1083) at > org.testng.TestNG.run(TestNG.java:999) at > org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:178) > at > org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92) > at > org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:96) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:497) at > org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) > at > org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) > at > org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) > at > org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) > at > org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)Caused > by: java.security.cert.CertificateException: No name matching localhost > found at > sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:221) at > sun.security.util.HostnameChecker.match(HostnameChecker.java:95) at > sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:455) > at > sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:436) > at > sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:200) > at > sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) > at > sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1488) > ... 51 more* > > > > Thanks, > Shevindi Rodrigo. > -- > Shevindi Rodrigo > Intern > 0715945303,0710388867 > -- Tharindu Edirisinghe Associate Technical Lead | WSO2 Inc Platform Security Team Blog : http://tharindue.blogspot.com mobile : +94 775181586
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
