[Huawei Developers] Freemind R:
Huawei WisePlay DRM Solution

Digital rights management (a.k.a DRM) protects digital media copy rights. The purpose is to prohibit unauthorized redistribution of digital media and restrict the ways that consumers can copy purchased content.

In general, DRM systems have been implemented by embedding code that prevents copying, specifies a time period in which the content can be accessed or limits the number of devices the media can be installed on.

There are several DRM solutions on market, one of the frequently used solution is Widevine DRM provided by Google that is mainly used in Android and Google native devices.

On the other hand, for the purposes of this article, Huawei WisePlay DRM solution will be analyzed. WisePlay DRM provides royalty-free (WisePlay doesn’t charge a license fee in order to implement its protection technology), standards-based digital content copyright protection capabilities , supports both hardware and software level DRM capabilities, and builds high-quality digital content service copyright protection capabilities developers.

Key Features of WisePlay DRM

1) Online Playback (VOD/Live TV)

The content license will be deleted when the playback session is closed.

2) Offline Playback(VOD)

The content license will be stored in the device.

3) Hardware and Software Level DRM

WisePlay DRM supports both hardware and software level encryption capabilities.

The difference between hardware-level and software-level encryption capabilities lies in device security level. Most of the service providers requires hardware-level DRM capability for the high quality e.g. 4K video media content for data protection.

The Trusted Application (a.k.a TA) running at the Trusted Execution Environment (a.k.a TEE) layer is required for the hardware-level encryption capability. The TA running at the TEE layer is not required for the software-level encryption capability and encryption depends on device chip capabilities.

According to software-level DRM capability, data encryption and other operations are performed at the Rich Operating System Execution Environment (a.k.a REE) layer. Content security is protected by software.

4) Supports Multiple Content Formats

WisePlay DRM provides most frequently used adaptive streaming content formats:

fMP4 DASH

fMP4 HLS

TS HLS

5) Supports Multiple Encryption Algorithms

WisePlay DRM provides most frequently used adaptive streaming content formats:

CENC

AES128-CTR

AES128-CBC

Development Scenarios

1) Obtain Online License

Call isCryptoSchemeSupported() method to check whether the UUID of WisePlay DRM is supported.

Create a MediaDrm object and transfer the UUID of WisePlay DRM. The UUID indicates the globally unique ID of each DRM type. (Note: Wiseplay DRM UUID = 3d5e6d35–9b9a-41e8-b843-dd3c6e72c42c)

Call the openSession() method of MediaDrm to open a session and obtain sessionId.

Call getKeyRequest() of MediaDrm to obtain the KeyRequest object in the license request body. The input parameters are described as follows:

sessionId: session ID returned by the openSession method.

initData:

If KeyType is set 　　　　　　　　　　　　　　　　to MediaDrm.KEY_TYPE_STREAMING or MediaDrm.KEY_TYPE_OFFLINE, set initData to the value of psshbox. The value of psshbox can be obtained from a media index file. (The value is obtained from the MPD file for Dash streams and from M3U8 file for HLS streams.)

If keyType is set to MediaDrm.KEY_TYPE_RELEASE, the initData parameter can be left empty.

mimeType: media type, for example, video/mp4 or video/webm. For the license deletion, this parameter can be 　　left empty.

keyType:

To obtain an offline license, set this parameter to MediaDrm.KEY_TYPE_STREAMING.

To obtain an offline license, set this parameter to MediaDrm.KEY_TYPE_OFFLINE.

To delete a license, set this parameter to MediaDrm.KEY_TYPE_RELEASE

optionalParameters: Leave this parameter empty.

Send a license request online to the server in POST mode. Set Content-Type in the request header to application/json and the request body to the data obtained by using the getData method of KeyRequest in the preceding step.

After receiving a response from the server, use the provideKeyResponse() method to transfer the content of the WisePlay DRM Server response transparently transmitted by the server to the underlying plug-in. The input parameter is the byte array of the license data obtained from the server.

Obtain online license

private void getOnlineLicense() {
if (!MediaDrm.isCryptoSchemeSupported(WISEPLAY_DRM_UUID)) {
showToast("The device does not support Wiseplay DRM.");
return;
}
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
InputStream inputStream = null;
MediaDrm mediaDrm = null;
byte[] sessionID = null;

try {
// Value of pssh box obtained from the movie.
byte[] initData = Base64.decode(PSSH_BOX, Base64.DEFAULT);

// Obtain the value of pssh box of the movie whose UUID is wiseplay drm from the movie.
String mimeType = "video/mp4";
mediaDrm = new MediaDrm(WISEPLAY_DRM_UUID);
sessionID = mediaDrm.openSession();
MediaDrm.KeyRequest keyRequest =
mediaDrm.getKeyRequest(sessionID, initData, mimeType, MediaDrm.KEY_TYPE_STREAMING, null);

byte[] requestData = keyRequest.getData();
String licenseServerUrl = licenseUrl;
URL url = new URL(licenseServerUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("content-type", "application/json");
connection.connect();

outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.write(requestData);

int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = connection.getInputStream();
byte[] response = toByteArray(inputStream);
Log.i(TAG, "getOnlineLicense response : " +
new String(response, StandardCharsets.UTF_8));
mediaDrm.provideKeyResponse(sessionID, response);

showToast("get online license success.");
}
} catch (NotProvisionedException | IOException | DeniedByServerException
| ResourceBusyException | UnsupportedSchemeException e) {
e.printStackTrace();
Log.i(TAG, "get online license failed: " + e.getMessage());
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
if (connection != null) {
connection.disconnect();
}
if (mediaDrm != null) {
if (sessionID != null) {
mediaDrm.closeSession(sessionID);
}
mediaDrm.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

2) Obtain Offline License

The process is the same as that in obtain online license.

The difference lies in the input parameter for calling the getKeyRequest API of MediaDrm.

keyType must be set as MediaDrm.KEY_TYPE_OFFLINE

After obtaining an offline license, call the provideKeyResponse() method to query keySetId indicating the unique ID of the offline license. Keep it secure for offline play content.

3) Delete Offline License

The process is the same as that in obtain online license.

The difference lies in the input parameter for calling the getKeyRequest API of MediaDrm.

keyType must be set as MediaDrm.KEY_TYPE_RELEASE

4) Play Content with Offline License

Call restoreKeys() of MediaDrm and pass keySetId. The offline license can be used later for playing the content.

If the license has expired or keySetId does not exist, calling restoreKeys will fail.

If the license has expired, do not initialize the codec.

private void useOfflineLicense() {
if (!MediaDrm.isCryptoSchemeSupported(WISEPLAY_DRM_UUID)) {
showToast("The device does not support wiseplay drm.");
return;
}
// Obtain the keySetId of the license from the store.
byte[] keySetIdToRestore = offlineKeySetId;
MediaDrm mediaDrm;
byte[] sessionID;
try {
mediaDrm = new MediaDrm(WISEPLAY_DRM_UUID);
sessionID = mediaDrm.openSession();
mediaDrm.restoreKeys(sessionID, keySetIdToRestore);

// If resotreKeys succeed, you can play it with this license.

showToast("use offline license success.");
mediaDrm.closeSession(sessionID);
mediaDrm.close();
} catch (NotProvisionedException | UnsupportedSchemeException | ResourceBusyException e) {
e.printStackTrace();
Log.i(TAG, "use offline license failed: " + e.getMessage());
}
}

Things to Consider

WisePlay DRM now supports Huawei phones with Kirin 990 chipset (EMUI 10.1 or later installed)

WisePlay DRM is available for Enterprise Developers now.

You can find more: How to join Huawei Developer, register an account, integrate your apps to Huawei AppGallery and so on.

Please refer to below link.

APP Development Process

WisePlay DRM Integration Preparation Steps：https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/wiseplay-preparation