In Android N, for SSL certificate I have to add this code (according to the provided Android developer link )
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
And the network_security_config.xml file in the xml folder is
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<domain includeSubdomains="true">example.com</domain>
<trust-anchors>
<certificates src="@raw/my_ca"/>
</trust-anchors>
</domain-config>
This works fine for a single static domain, but my problem is: the server domain will not be applied every time in my application. The second problem is that I download the SSL certificate from my server domain at run time, so every time I can update the certificate file in the raw folder, because we know that we can not write the file in the raw folder at run time.
, Android N .
Edit1: , , .
Edit2:
, , 200, "ok" Android Android ( ).
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
InputStream caInput = new BufferedInputStream(new FileInputStream(certFile));
X509Certificate ca =(X509Certificate) cf.generateCertificate(caInput);
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
}};
HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier());
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, trustAllCerts, new java.security.SecureRandom());
url = new URL(wsdlUrl);
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setSSLSocketFactory(sslcontext.getSocketFactory());
urlConnection.setConnectTimeout(5000);
urlConnection.connect();
if (urlConnection.getResponseCode() == 200) {
result = true;
} else {
result = false;
}
200 SOAP- ,
com.neurospeech.wsclient.SoapFaultException: Server Error
at com.neurospeech.wsclient.SoapWebService.postXML(SoapWebService.java:225)
at com.neurospeech.wsclient.SoapWebService.getSoapResponse(SoapWebService.java:157)
at com.vxlsoftware.fudmagent.serviceclasses.AndroidServiceAsync.access$1300(AndroidServiceAsync.java:6)
at com.vxlsoftware.fudmagent.serviceclasses.AndroidServiceAsync$setAndroidClient HeartbitRequest.executeRequest(AndroidServiceAsync.java:367)
at com.neurospeech.wsclient.ServiceRequest.run(ServiceRequest.java:20)
at java.lang.Thread.run(Thread.java:761)
, Android N, SOAP- .
, , , , , , .