Skip to content

Commit

Permalink
Merge pull request #937 from rnrneverdies/0.9
Browse files Browse the repository at this point in the history
Added Widevine Base Aquisition Url + FairPlay support
  • Loading branch information
jianghaolu authored Jul 12, 2016
2 parents 06051dd + a66019f commit 60aa3c9
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ClientResponse doHandle(ClientRequest cr) {
MultivaluedMap<String, Object> headers = cr.getHeaders();
headers.add("DataServiceVersion", "3.0");
headers.add("MaxDataServiceVersion", "3.0");
headers.add("x-ms-version", "2.11");
headers.add("x-ms-version", "2.12");
return getNext().handle(cr);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.microsoft.windowsazure.services.media.implementation.templates.fairplay;

import java.io.ByteArrayOutputStream;
import java.security.KeyStore;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.microsoft.windowsazure.core.utils.Base64;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class FairPlayConfiguration {

private String askId;

private String fairPlayPfxPasswordId;

private String fairPlayPfx;

private String contentEncryptionIV;

public static String createSerializedFairPlayOptionConfiguration(
KeyStore keyStore, String pfxPassword, String pfxPasswordKeyId, String askId,
String contentIv) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
keyStore.store(outputStream, pfxPassword.toCharArray());
String certString = Base64.encode(outputStream.toByteArray());
FairPlayConfiguration config = new FairPlayConfiguration();
config.askId = askId;
config.contentEncryptionIV = contentIv;
config.fairPlayPfx = certString;
config.fairPlayPfxPasswordId = pfxPasswordKeyId;
ObjectMapper mapper = new ObjectMapper();
String configuration = mapper.writeValueAsString(config);

return configuration;
} catch (Throwable t) {
throw new RuntimeException(t);
}
}

static final char[] HEXARRAY = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEXARRAY[v >>> 4];
hexChars[j * 2 + 1] = HEXARRAY[v & 0x0F];
}
return new String(hexChars);
}

@JsonProperty("ASkId")
public String getASkId() {
return askId;
}

@JsonProperty("FairPlayPfxPasswordId")
public String getFairPlayPfxPasswordId() {
return fairPlayPfxPasswordId;
}

@JsonProperty("FairPlayPfx")
public String getFairPlayPfx() {
return fairPlayPfx;
}

@JsonProperty("ContentEncryptionIV")
public String getContentEncryptionIV() {
return contentEncryptionIV;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.microsoft.windowsazure.services.media.implementation.templates.fairplay;
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ public enum AssetDeliveryPolicyConfigurationKey {
/** The initialization vector to use for envelope encryption. */
EnvelopeEncryptionIV(6),
/** Widevine DRM Acquisition Url to use for common encryption. */
WidevineLicenseAcquisitionUrl(7);

WidevineLicenseAcquisitionUrl(7),
/** Base Widevine url that will have KID=<Guid> appended */
WidevineBaseLicenseAcquisitionUrl(8),
/** FairPlay license acquisition URL. */
FairPlayLicenseAcquisitionUrl(9),
/** Base FairPlay license acquisition URL that will have KID=<Guid> appended. */
FairPlayBaseLicenseAcquisitionUrl(10),
/** Initialization Vector that will be used for encrypting the content. Must match
IV in the AssetDeliveryPolicy. */
CommonEncryptionIVForCbcs(11);

/** The AssetDeliveryPolicyType code. */
private int assetDeliveryPolicyConfigurationKey;
Expand Down Expand Up @@ -87,6 +95,14 @@ public static AssetDeliveryPolicyConfigurationKey fromCode(int option) {
return AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIV;
case 7:
return AssetDeliveryPolicyConfigurationKey.WidevineLicenseAcquisitionUrl;
case 8:
return AssetDeliveryPolicyConfigurationKey.WidevineBaseLicenseAcquisitionUrl;
case 9:
return AssetDeliveryPolicyConfigurationKey.FairPlayLicenseAcquisitionUrl;
case 10:
return AssetDeliveryPolicyConfigurationKey.FairPlayBaseLicenseAcquisitionUrl;
case 11:
return AssetDeliveryPolicyConfigurationKey.CommonEncryptionIVForCbcs;
default:
throw new InvalidParameterException("option");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public enum AssetDeliveryPolicyType {
/** Apply Dynamic Envelope encryption. */
DynamicEnvelopeEncryption(3),
/** Apply Dynamic Common encryption. */
DynamicCommonEncryption(4);
DynamicCommonEncryption(4),
/** Apply Dynamic Common encryption with cbcs */
DynamicCommonEncryptionCbcs(5);


/** The AssetDeliveryPolicyType code. */
Expand Down Expand Up @@ -75,6 +77,8 @@ public static AssetDeliveryPolicyType fromCode(int option) {
return AssetDeliveryPolicyType.DynamicEnvelopeEncryption;
case 4:
return AssetDeliveryPolicyType.DynamicCommonEncryption;
case 5:
return AssetDeliveryPolicyType.DynamicCommonEncryptionCbcs;
default:
throw new InvalidParameterException("option");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public enum ContentKeyDeliveryType {
/** Use MPEG Baseline HTTP key protocol. */
BaselineHttp(2),
/** Use Widevine license acquisition protocol. */
Widevine(3);
Widevine(3),
/** Send FairPlay SPC to Key Delivery server and get CKC back */
FairPlay(4);

/** The AssetDeliveryPolicyType code. */
private int contentKeyDeliveryType;
Expand Down Expand Up @@ -70,6 +72,8 @@ public static ContentKeyDeliveryType fromCode(int option) {
return ContentKeyDeliveryType.BaselineHttp;
case 3:
return ContentKeyDeliveryType.Widevine;
case 4:
return ContentKeyDeliveryType.FairPlay;
default:
throw new InvalidParameterException("option");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ public enum ContentKeyType {
/** The Configuration encryption. */
ConfigurationEncryption(2),
/** The Envelope encryption. */
EnvelopeEncryption(4);
EnvelopeEncryption(4),
/** Specifies a content key for common encryption with CBCS. */
CommonEncryptionCbcs(6),
/** Application Secret key for FairPlay. */
FairPlayASk (7),
/** Password for FairPlay application certificate. */
FairPlayPfxPassword (8);

/** The content key type code. */
private int contentKeyTypeCode;
Expand Down Expand Up @@ -72,6 +78,12 @@ public static ContentKeyType fromCode(int code) {
return ContentKeyType.ConfigurationEncryption;
case 4:
return ContentKeyType.EnvelopeEncryption;
case 6:
return ContentKeyType.CommonEncryptionCbcs;
case 7:
return ContentKeyType.FairPlayASk;
case 8:
return ContentKeyType.FairPlayPfxPassword;
default:
throw new InvalidParameterException("code");
}
Expand Down

0 comments on commit 60aa3c9

Please sign in to comment.