8

I need to stream video over a local HTTPS server (of course to do some background DRM) in Android. The Android media player is then connecting to the local server, 'streaming' the video content to the screen.

It all works fine with a HTTP server but as soon as I enable SSL, the video player stops.

If i connect to the HTTPS server from outside my app using a browser, I get an SSL warning which i can ignore and then the video player starts.

Is there a way to disable the strict certificate handling for the media player module? I have seen a lot of posts on how to do this using my own HTTP connection, but nothing on how to do this for the media player.

Thanks!

UPDATE: Google for 'intranet certificate' or 'instant certificate' and you will find something that's supposed to work. Will try it out tomorrow and post the answer here.

KPK
  • 367
  • 2
  • 9
  • 1
    Can you include details on the specific SSL warning you're seeing when you use a browser? – P.T. Oct 19 '11 at 22:33
  • In the browser hits an untrusted site, it tells me the usual thing about this site does might be a security risk. And I have the options :Proceed anyway or cancel. Read some messages about how to enable that globally (big security risk, thus not possible): http://superuser.com/questions/27268/how-do-i-disable-the-warning-chrome-gives-if-a-security-certificate-is-not-trust. I Basically want to do the same but just add the certificate exception for my app - and without writing a derived HTTP client. – KPK Oct 19 '11 at 22:46
  • The MediaPlayer on Android < 3.2 does not support HTTPS connections :( – Kevin Parker Oct 25 '11 at 18:13
  • And DRM won't be available either: http://developer.android.com/reference/android/drm/package-summary.html – KPK Oct 25 '11 at 19:55

2 Answers2

1

You Should Try this for Sure,

    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[]{
        new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            public void checkClientTrusted(
                java.security.cert.X509Certificate[] certs, String authType) {
            }
            public void checkServerTrusted(
                java.security.cert.X509Certificate[] certs, String authType) {
            }
        }
    };

    // Install the all-trusting trust manager
    // Try "SSL" or Replace with "TLS"
    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
    }

    // Now you can access an https URL without having the certificate in the truststore 
           // Your Code Goes Here

Here are More Solutions for This
Certificate Validation in an HTTPS Connection
Android: Trusting SSL certificates
https://stackoverflow.com/a/6378872/1008278

Community
  • 1
  • 1
VenomVendor
  • 14,660
  • 11
  • 66
  • 92
  • how can we do this for video view? please elobrate your answer? – Praveen Jun 11 '12 at 09:30
  • Before calling the local or external file via https add the above code – VenomVendor Jun 11 '12 at 09:49
  • 1
    did you try this before? i am asking this why because in video view we have a setVideoURI method. just we need to pass the video url in that. i have no idea that how to add the above code in that. please edit your answer. so that it will help me. thanks in advance – Praveen Jun 11 '12 at 10:05
  • Post your original code, somewhere not here in some txt file, give the link of the txt file & i'll send you back ,Hope this will help you – VenomVendor Jun 11 '12 at 10:07
  • 1
    That won't work if you're calling a different application (activity) such as the default video player. – NoBugs Jun 12 '12 at 00:51
0

here is the solution actually , to add this android:usesCleartextTraffic="true" to your manifest , so it allows connections to http as well ,

solution taken from :How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?