java-client
java-client copied to clipboard
Appium Java client throws exceptions when connecting to the server behind proxy with self-signed SSL certificate
Description
Appium Java client requires proper SSL certificate if the server is behind proxy with SSL. There is no option to allow less secure connection to the server. The only workaround is to patch Java's keystore so the self-signed certificate is trusted by the javax security mechanism.
Environment
- java client build version or git revision if you use some shapshot: 7.0.0
- Appium server version or git revision if you use some shapshot: N/A
- Desktop OS/version used to run Appium if necessary: N/A
- Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: N/A
- Mobile platform/version under test: N/A
- Real device or emulator/simulator: N/A
Details
If using Appium server behind SSL proxy using self-signed SSL certificate Appium service crashes with errors: unable to find valid certification path to requested target.
This is proper solution, however development environments can use centralized platform (like on-premise HeadSpin) that do not necessarily have to be configured properly - or like in many companies - there is one globally distributed and injected root CA in the OS that is not loaded by Java platform locally causing such exceptions.
Code To Reproduce Issue [ Good To Have ]
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.APP, apk);
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, pkg);
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, activity);
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(ssl_server_url, capabilities); <- this throws error
Exception stacktraces
https://gist.github.com/szczad/aecbee10eda0e1735127cff5ee7b36f0
Link to Appium logs
No Appium logs generated as the client did not connect to the server anyways.
Any update on this ?
With the latest version, SSLContext may help.
https://www.baeldung.com/okhttp-client-trust-all-certificates#set-up-an-okhttpclient-to-trust-all-certificates
The SSLContext instance can be set with the client config:
https://github.com/appium/java-client/blob/41769295f6af68da7721be8cfd3a59ee01fd01d4/src/main/java/io/appium/java_client/AppiumClientConfig.java#L69