How to fix unsafe implementation of X509TrustManager in Android app

Nabeel

Google has advised that I have an unsafe implementation of the interface X509TrustManager in my Android application and need to change my code as follows:

To properly handle SSL certificate validation, change your code in the checkServerTrusted method of your custom X509TrustManager interface to raise either CertificateException or IllegalArgumentException whenever the certificate presented by the server does not meet your expectations. For technical questions, you can post to Stack Overflow and use the tags “android-security” and “TrustManager.”

How can the following code be modified to fix the above issue?

public EasySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
    super(truststore);

    TrustManager tm = new X509TrustManager()  {
        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
        }

        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    };

    mContext.init(null, new TrustManager[] { tm }, null);
}
Nabeel

I have solved this using the following code:

public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                try {
                    chain[0].checkValidity();
                } catch (Exception e) {
                    throw new CertificateException("Certificate not valid or trusted.");
                }
            }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Simulate the solution for Security Alert - unsafe implementation of X509TrustManager

From Dev

You are using an unsafe implementation of X509TrustManager

From Dev

an unsafe implementation of the interface X509TrustManager from google

From Dev

How to fix apps containing an unsafe implementation of TrustManager

From Dev

No X509TrustManager Implementation available

From Dev

How do I validate an android.net.http.SslCertificate with an X509TrustManager?

From Dev

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No X509TrustManager implementation available

From Dev

Keep getting No X509TrustManager implementation available error when trying to connect to web socket server

From Dev

Keep getting No X509TrustManager implementation available error when trying to connect to web socket server

From Dev

Google Play Security Alert X509Trustmanager - Will my App be removed from store after May 17?

From Dev

How to fix the issue if app is crashed in android?

From Dev

How to fix Implementation error?

From Dev

How to fix Chrome's Refused to set unsafe header "Connection"

From Dev

How to fix Chrome's Refused to set unsafe header "Connection"

From Dev

How to fix ERR_UNSAFE_PORT error on Chrome when browsing to unsafe ports

From Dev

How to fix "Your Android App Bundle is signed with the wrong key"?

From Dev

How to fix the issue in running my NativeScript app in android?

From Dev

How to fix styling of app

From Dev

Android X509TrustManager#checkServerTrusted throws CertificateException on API > 23

From Dev

How to fix unrecognized selector issue in AdMob implementation?

From Dev

How to fix NetworkonMainThreadException in Android?

From Dev

How to fix android bootloop?

From Dev

how to fix `Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager` error in android?

From Dev

how to fix `Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager` error in android?

From Dev

"Unsafe permissions on configuration file `/home/david/.gnupg/gpg.conf" What does it mean and how to fix?

From Dev

"Unsafe permissions on configuration file `/home/david/.gnupg/gpg.conf" What does it mean and how to fix?

From Dev

How to Fix CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')

From Dev

How to solve "Google Play will block publishing of any new apps or updates that use an unsafe implementation of HostnameVerifier"?

From Java

How to fix: android.app.RemoteServiceException: Bad notification posted from package *: Couldn't create icon: StatusBarIcon

Related Related

  1. 1

    Simulate the solution for Security Alert - unsafe implementation of X509TrustManager

  2. 2

    You are using an unsafe implementation of X509TrustManager

  3. 3

    an unsafe implementation of the interface X509TrustManager from google

  4. 4

    How to fix apps containing an unsafe implementation of TrustManager

  5. 5

    No X509TrustManager Implementation available

  6. 6

    How do I validate an android.net.http.SslCertificate with an X509TrustManager?

  7. 7

    javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No X509TrustManager implementation available

  8. 8

    Keep getting No X509TrustManager implementation available error when trying to connect to web socket server

  9. 9

    Keep getting No X509TrustManager implementation available error when trying to connect to web socket server

  10. 10

    Google Play Security Alert X509Trustmanager - Will my App be removed from store after May 17?

  11. 11

    How to fix the issue if app is crashed in android?

  12. 12

    How to fix Implementation error?

  13. 13

    How to fix Chrome's Refused to set unsafe header "Connection"

  14. 14

    How to fix Chrome's Refused to set unsafe header "Connection"

  15. 15

    How to fix ERR_UNSAFE_PORT error on Chrome when browsing to unsafe ports

  16. 16

    How to fix "Your Android App Bundle is signed with the wrong key"?

  17. 17

    How to fix the issue in running my NativeScript app in android?

  18. 18

    How to fix styling of app

  19. 19

    Android X509TrustManager#checkServerTrusted throws CertificateException on API > 23

  20. 20

    How to fix unrecognized selector issue in AdMob implementation?

  21. 21

    How to fix NetworkonMainThreadException in Android?

  22. 22

    How to fix android bootloop?

  23. 23

    how to fix `Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager` error in android?

  24. 24

    how to fix `Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager` error in android?

  25. 25

    "Unsafe permissions on configuration file `/home/david/.gnupg/gpg.conf" What does it mean and how to fix?

  26. 26

    "Unsafe permissions on configuration file `/home/david/.gnupg/gpg.conf" What does it mean and how to fix?

  27. 27

    How to Fix CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')

  28. 28

    How to solve "Google Play will block publishing of any new apps or updates that use an unsafe implementation of HostnameVerifier"?

  29. 29

    How to fix: android.app.RemoteServiceException: Bad notification posted from package *: Couldn't create icon: StatusBarIcon

HotTag

Archive