usesCleartextTraffic And NetworkSecurityConfig not permitted - java

i have searched for this problem but cant resolve that problem
i have internet in android 8 but in android 9 dont have any connection
usesCleartextTraffic=true >> not resolved
NetworkSecurityConfig >> not resolved
my url have https and ssl certificate but i dont have any internet connection only in android 9
this is security config below
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">ketabenarenji.ir</domain>
</domain-config>
</network-security-config>

I don't think we understood each other, go check my answer in this post WebView shows net::ERR_CLEARTEXT_NOT_PERMITTED on HTTPS url it'll help you on how to configure your files.
EDIT: I just went on your website and it tells me it's not secure even though you have https:// you might wanna fix your certificate, once it's fix you can remove all the useClearTextTraffic and the file network_security_config

Related

Android App doesn't have internet connection - No Permissions required

Well, I have built an app to store values on a remote database. It works!! I didn't use an emulator for testing instead I used my own phone. Now the problem is that on my phone, it works perfectly...no issues but when I installed it on another phone, the app doesn't connect to the internet.
I have included internet permission in android manifest.xml.
I have tried these but didn't work:
Building apk and installing in the new phone.
Compiling directly to the new phone.
Sending the apk from old phone to new phone via shareit.
Creating a signed apk and installing.
Checked via wifi and mobile data (NOTE: BOTH WIFI AND MOBILE DATA WORKS IN OLD PHONE).
Checked android compatibility: supports up to android 10.
*I added error messages for try...catch blocks in form of toasts for the user to know what's the issue. and the catch exception for no internet returns connection problem. I'm getting that error message.
As I researched, I got to know that internet permission is categorized as normal permission which is not prompted to the user upon installation.
I built a second dummy app: Same issue with it... compiled directly to new phone but didn't work...it works in old phone...
Old phone: Samsung J7 Prime with Android 8.1
New Phone: Samsung J7 Pro with Android 9
Any idea or suggestion will be gladly helpful... Thank you!
in android 9 and above you have to set network Security Config
first of all in res package create xml package and in xml package create new xml resource file with network_security_config name
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
then in manifest in
android:networkSecurityConfig="#xml/network_security_config"
<uses-permission android:name="android.permission.INTERNET" />
Use debug APK instead of signed APK
please add permission on Manifest to give a permission of permission.INTERNET

Android 9: Cleartext HTTP traffic not permitted although having cleartextTrafficPermitted="true"

I have a strange issue. My app is using http to connect to a server. It works fine in many devices. However, in Xiaomi devices which has Android 9, it gives me this error:
Caused by java.io.IOException: Cleartext HTTP traffic to internet.vodafone.com.eg not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:142)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:469)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:418)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:549)
at com.google.firebase.perf.network.zzd.getResponseCode(zzd.java:81)
at com.google.firebase.perf.network.zzb.getResponseCode(zzb.java:14)
at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:96)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:123)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
In the AndroidManifest.xml I have this:
<application
...
android:networkSecurityConfig="#xml/network_security_config"
...
</application>
My network_security_config.xml file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">thebondnews.com</domain>
</domain-config>
</network-security-config>
Also, I have all the permission to connect to the internet. It works fine in Many devices with android 9 Like Samsung galaxy s9/s9+ and Samsung galaxy s8/s8+ and many others.
The error message was copied from Firebase Crashlatics. What is strange is that my server domain is thebondnews.com but in the log, it says internet.vodafone.com.eg or sometimes notification.etisalat.com.eg and 10.10.10.1. It is like there is kinda redirection in their devices.
Can anyone help me how to solve it? or what shall I do?
Update 1:
Could it be that I am only allowing my domain in network_security_config.xml
and because of the redirection caused by their providers the connection fails?
As Md. Asaduzzaman said in the comments.
The internet package of that user has finished and the operator tries to redirect him to the internet package page.
So it was not an issue with the app. However, some users have a limited internet package with limited access to things like Facebook, WhatsApp, Instagram..etc.
Thus, when my app tries to connect to the server, it is being redirected by the internet provider to block the traffic.

SSL/HTTPS with Android (Nougat) and Client Certificates

Situation:
I have a Airwatch Installment, that provides the Client with private "User Certificates" that are stored in the User private CA Store. The Certificates should be used when establishing a SSL Connection to a designated https Webserver.
E.g. When i try to access this Webserver via HTTPS and Chrome, Chrome finds the Client Certificate and asks me if i wanna use it (so not directly). By clicking "ok" i can establish the Connection and view the Site.
Problem
In the "recent times" this could be solved in custom Apps by providing the Apps themselfs with the physical Certificate and load it on runtime (by creating a Keystore, Trustmanager, and Custom SSLContext) as described here
I though with Android Nougat i could get rid of the "Workaround", by only configuring where the Certificates for this app are located. Its called Network Security Configuration, as described here https://developer.android.com/training/articles/security-config.html
So i Added:
android:networkSecurityConfig="#xml/network_security_config"
in the Android Manifest, and added a XML that looks like this
<network-security-config>
<base-config>
<!-- Trust ONLY the mydomain.com Domain and its Subdomains -->
<domain includeSubdomains="true">mydomain.com</domain>
<trust-anchors>
<!-- Trust preinstalled CAs -->
<certificates src="system"/>
<!-- Additionally trust user added CAs -->
<certificates src="user"/>
</trust-anchors>
</base-config>
</network-security-config>
I though using a HttpsURLConnection would automatically use also the User-Certificates if necessary.
Current Situation:
Im Still getting this:
javax.net.ssl.SSLHandshakeException: Handshake failed
Question:
1) Do I still have to Create a Custom SSLContext and injecting a Custom Trustmanager with a Custom Keystore ? And If I have to do so, how do I get the User Certificates ? The Defautl System CAs can be easyly initialised via KeyStore.getInstance("AndroidCAStore"); but how to get the Keys from the User Specific Store to use them in the SSLContext ?
3) I didn't find any example in the Web how to Use a HttpsConnection with Client Certificates that are stored in the User Keystore on Android with Nougat or higher, any hints ?

STARTTLS issue when using google as the smtp server when using javamail

I use the Java based CMS dotCMS and I want to use google as the smtp server. I used the config as described in the dotCMS docs: http://dotcms.com/docs/latest/mail-configuration.
My config looks like this:
<Resource
name="mail/MailSession"
auth="Container"
type="javax.mail.Session"
mail.debug="true"
mail.transport.protocol="smtp"
mail.smtp.host="smtp.gmail.com"
mail.smtp.auth="true"
mail.smtp.port="465"
mail.smtp.starttls.enable="true"
mail.smtp.user="[my username]"
mail.password="[my pwd]"
username="[my username]"
password="[my pwd]"
mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
/>
When I call the $mailer.sendEmail method I get an error back:
"Unable to Send Message: 530 5.7.0 Must issue a STARTTLS command first. c7sm25357283wjb.19 - gsmtp".
I also tried port 587, but that did not help either.
Any idea what I am doing wrong? I'm using dotcms 2.5.6. running on debian 7.8 (wheezy)
You shouldn't need the socketFactory setting.
You also shouldn't need the port setting.
Try setting mail.smtp.ssl.enable=true. If that doesn't work, try setting mail.transport.protocol=smtps and change all the mail.smtp.* settings to mail.smtps.*.
The Gmail entry in the JavaMail FAQ might be useful.
If none of that works, post the JavaMail debug output.
Do you have 2 factor authentication set up in google? I think this might prevent the authentication from happening.

Applet: connect to other host

Hallo,
Now, in my one site applet loads from A host and it should work with
B host. But When I tried to do it I got
java.security.AccessControlException: access denied (java.net.SocketPermission MY_URL:443 connect,resolve)
exception. Applet is signed. I have added crossdomain.xml to B host too, but it is not help.
Are there any solution of this issue?
crossdomain.xml:
<?xml version="1.0"?>
<!-- http://192.168.0.199/crossdomain.xml -->
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="Authorization,X-HTTP-Method-Override"/>
</cross-domain-policy>
I dont think there is a solution. An applet is allowed to contact only the server that it has been downloaded from. Regards, - M.S.

Categories

Resources