简体   繁体   English

Android - 通过本地 HTTPS 服务器的视频流:SSL 证书被拒绝

[英]Android - Video streaming over local HTTPS server: SSL certificate rejected

I need to stream video over a local HTTPS server (of course to do some background DRM) in Android.我需要在 Android 中通过本地 HTTPS 服务器流式传输视频(当然要做一些后台 DRM)。 The Android media player is then connecting to the local server, 'streaming' the video content to the screen.然后,Android 媒体播放器连接到本地服务器,将视频内容“流式传输”到屏幕上。

It all works fine with a HTTP server but as soon as I enable SSL, the video player stops.在 HTTP 服务器上一切正常,但是一旦我启用 SSL,视频播放器就会停止。

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.如果我使用浏览器从应用程序外部连接到 HTTPS 服务器,则会收到 SSL 警告,我可以忽略该警告,然后视频播放器启动。

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.我已经看到很多关于如何使用我自己的 HTTP 连接来做到这一点的帖子,但没有关于如何为媒体播放器做到这一点。

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.明天会尝试并在此处发布答案。

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 HTTPS 连接中的证书验证
Android: Trusting SSL certificates Android:信任 SSL 证书
https://stackoverflow.com/a/6378872/1008278 https://stackoverflow.com/a/6378872/1008278

here is the solution actually , to add this android:usesCleartextTraffic="true" to your manifest , so it allows connections to http as well ,这是实际的解决方案,将这个 android:usesCleartextTraffic="true" 添加到您的清单中,因此它也允许连接到 http,

solution taken from : How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?解决方案取自: 如何在 Android (9) Pie 中允许所有网络连接类型 HTTP 和 HTTPS?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM