ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

How could I Play Dash DRM widevine stream without license url?

Open fabiobazurto opened this issue 9 years ago • 14 comments

Issue description

I'm trying to play a DASH DRM WV video but i need to set license manually. My client cant publish his license server however he gave me String License. I got this error Failed to handle key response: General DRM error (-2000)

Reproduction steps

Edit DefaultDrmSessionManager line 578, add this code: String license = "CAIS3wIKSgogMkE4MDc3MDlDQUY1NjM0NjAyMDAwMDAwMDAwMDAwMDASIDJBODA3NzA5Q0FGNTYzNDYwMjAwMDAwMDAwMDAwMDAwGgAgASgAEgoIARAAGAEoADAAGmYSELsnxdNyPDDZJDCt84WJlk0aUBov91jlqHM1Pg6NVK5SbGHtUt4POkDVCS4e/KoC1tFmGFDJUMquSEBrcxZYfEy3MaueFBJAJpu/PMK0oETCeL9Ae008Tx1AHHE+Rk1mSxMeIAEahgEKEP////+qqru7AAEAAAAAAAESEN6yZOnUjzTYMym4ue/Cf9gaIHlQDqBcMnohG0fV/7oYn/46QShtzaGTVxFayPDbhAk+IAIoATIECAAQKkI0CiDpALeZtTNraPeGlAiUULLxX9YmeaGlFXB9rB0oyK5FpxIQGOYErujRrZtIogWkfuQtSyDIh+DLBTgAQgxIRENQREFUQQAAAAMaIDpM21lxMyu1s+s1grgvingAqU6d5RXvV8jI2JIxBWU3IoACXIzOUCG8amUYp95CU3dYV93r1vD/r65T3vUdo3mhwVag/rmjeZq3/ayKgkFA+mWNysSNxqL0gdRecyH4vKw3Vrrh9YydeMfFeB1ZRt/AaORiNT38wnMlWGqJcR4fhS/oKNtZjpQ0q8UKi54BG6Ffowc7QQUdWezqhMx1tc1LybXnl8Z1JENfsstGpAKmApkGUiHTjshlRu2mhN2zNqvf4MUjB039Vfk4rPGVQNNpAhAiV9JGYpwRyuO7vrk/dS2HB2Yy65H1XmIHiKgCtv4Pwp5vE97OuGomwpb42Lq9zshR1mEHWww2azmMZA/4icDijUt1de5tCWyzpqI3G19lnQ=="; response = Base64.decode(license, Base64.DEFAULT);

Link to test content

https://d3dejapp0ui3ef.cloudfront.net/totalplay-enc-wv.mpd

Version of ExoPlayer being used

r2.4.3 (Demo project)

Device(s) and version(s) of Android being used

Moto G 2nd, Android 6.0 Pixel C(ryu) Android O

A full bug report captured from the device

Could i send you my parameters to test dash in exoplayer? i didnt get to play dash. i can play all exoplayer examples.

fabiobazurto avatar Jul 26 '17 17:07 fabiobazurto

Create a custom MediaDrmCallback that returns what you want for for executeProvisionRequest() and executeKeyRequest() (look at HttpMediaDrmCallback for reference). Then give this to a DrmSessionManager on instantiation.

gvidda avatar Jul 27 '17 12:07 gvidda

Thank you for your response, i will give a try to ur recommendation. Then i'll send you a feedback.

fabiobazurto avatar Jul 28 '17 03:07 fabiobazurto

Hello @gvidda , " returns what you want for for executeProvisionRequest() and executeKeyRequest()" you mean byte[] return? I don't understand how to make String readeable to drm. could u help me with a reference to learn how to?

fabiobazurto avatar Jul 28 '17 16:07 fabiobazurto

I don't understand this question, primarily because my understanding of how Widevine works is that a license response is tied to a specific device. If it were possible to take a license response provided to one device and then use that to make content playable locally on any other device, then wouldn't the DRM system be fundamentally quite broken?

To conclude: I don't think there's a way to play Widevine protected content without a proper license server.

ojw28 avatar Jul 31 '17 16:07 ojw28

If you think the above is incorrect, please let us know. Else we'll close this issue.

ojw28 avatar Jul 31 '17 16:07 ojw28

Could i send you my parameters to test dash in exoplayer? i didnt get to play dash. i can play all exoplayer examples.

fabiobazurto avatar Jul 31 '17 18:07 fabiobazurto

I don't understand what that means, sorry? As per above, I don't think it's valid to hard code a license response, which is what your original posts suggests you're doing.

ojw28 avatar Jul 31 '17 18:07 ojw28

ok I know. We have local license server. Dash media content works with dash.js player. Now we want to use Exoplayer but we generate license indirectly, i mean, I got my challenge value in keyRequest variable from postKeyRequest(...) method. This value is injected in a CAllback parameter called "challenge" to get license string but i dont know how to inject this license to my device in order to play my dash content. Could i send you my parameters by email to ensure I am doing right way?

fabiobazurto avatar Jul 31 '17 18:07 fabiobazurto

You would also need to insert the license into the exact same DRM session for it to be valid (i.e. you couldn't use it for a subsequent playback attempt). Why don't you just use the license server?

ojw28 avatar Jul 31 '17 18:07 ojw28

To put it another way, there is no alternative to implementing MediaDrmCallback.executeKeyRequest in a way that provides a response specific to the request that's passed to it. It is not possible to generate a response prior to receiving the request. Generating a response based on a previous request from the same device will not work; the response needs to be generated for the particular request in all cases.

If you want to use some non-standard way of implementing executeKeyRequest, then you're free to implement your own MediaDrmCallback that does this. You cannot avoid the rules described above, however. You must obtain or generate a response in executeKeyRequest that's specific to the request, one way or another.

ojw28 avatar Jul 31 '17 18:07 ojw28

I got it. I've published my license server, could i sent you the url and manifest to test it? maybe i'm doing something wrong.

fabiobazurto avatar Jul 31 '17 20:07 fabiobazurto

I got it, i forgot my license service needs custom HTTP Header setup to request license. I wrote a CustomDrmCallback with custom executePOST. Thank you @ojw28 , your explanation was exactly I needed.

fabiobazurto avatar Aug 01 '17 01:08 fabiobazurto

My code:

private static byte[] executePost(HttpDataSource.Factory dataSourceFactory, String url,
                                      byte[] data, Map<String, String> requestProperties) throws IOException {
        URL objUrl;
        String response = "";
        try {
	    //1. SETUP HTTP REQUEST
            objUrl = new URL(url);
            HttpURLConnection urlConnection = (HttpURLConnection)objUrl.openConnection();
            urlConnection.setDoInput (true);
            urlConnection.setDoOutput (true);
            urlConnection.setUseCaches (false);
            urlConnection.setRequestProperty("Content-Type","application/json");
            urlConnection.setRequestMethod("POST");
            urlConnection.setRequestProperty("Origin", "XXXXXXXXXXXXXXX");
            /*
            *	Add HTTP HEADERS YOU NEED Ex.: urlConnection.setRequestProperty("Accept", "XXXXXXXXXXXXXXX");
            *
            */
	    /*
	    *	2. Prepare request body with "data" parameter 
	    */
	    
            StringBuilder sb = new StringBuilder();
            DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream());

	    /*
	    *
	    *	"data" parameter contains the challenge value, you need to concatenate with word "challenge" like this
	    */
            wr.writeBytes("{\"challenge\":\"" + Base64.encodeToString(data,Base64.NO_WRAP) + "\"}");

            wr.flush();

            wr.close();

            int HttpResult = urlConnection.getResponseCode();

            if ((HttpResult == HttpURLConnection.HTTP_OK) || (HttpResult == HttpURLConnection.HTTP_CREATED)) {

                BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "utf-8"));

                String line = null;

                while ((line = br.readLine()) != null) {

                    sb.append(line + "\n");

                }

                br.close();

                response = sb.toString();
                JSONObject jObj = new JSONObject(response);
                response= jObj.get("license").toString().split("\"")[1];
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
        return Base64.decode(response,0);
    }

fabiobazurto avatar Aug 01 '17 01:08 fabiobazurto