diff --git a/example/wv_cas_ecm_example b/example/wv_cas_ecm_example new file mode 100644 index 0000000..1b4651b Binary files /dev/null and b/example/wv_cas_ecm_example differ diff --git a/example/wv_cas_ecm_example.cc b/example/wv_cas_ecm_example.cc new file mode 100644 index 0000000..3b5a1f3 --- /dev/null +++ b/example/wv_cas_ecm_example.cc @@ -0,0 +1,55 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright 2018 Google LLC. +// +// This software is licensed under the terms defined in the Widevine Master +// License Agreement. For a copy of this agreement, please contact +// widevine-licensing@google.com. +//////////////////////////////////////////////////////////////////////////////// + +// Example of how to use the wv_cas_ecm library. + +#include + +#include "gflags/gflags.h" +#include "glog/logging.h" +#include "absl/strings/escaping.h" +#include "absl/strings/str_cat.h" +#include "util/status.h" +#include "media_cas_packager_sdk/public/wv_cas_ecm.h" + +const char kEvenKey[] = "even_content_key"; // 16 bytes +const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes +const char kOddKey[] = "odd_content_key."; // 16 bytes +const char kOddContentIv8Bytes[] = "oddcont."; // 8 bytes +const char kEntitlementKeyId[] = "ent_key_id......"; // 16 bytes +const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes + +int main(int argc, char **argv) { + gflags::ParseCommandLineFlags(&argc, &argv, true); + + widevine::cas::WvCasEcm wv_cas_ecm; + auto status = wv_cas_ecm.Initialize(/* content_iv_size= */ 16, + /* key_rotation_enabled= */ true, + /* crypto_mode= */ 1); + if (!status.ok()) { + LOG(FATAL) << "Failed to initialize WV CAS ECM, error: " << status; + } + std::string ecm; + status = wv_cas_ecm.GenerateEcm( + /* even_key= */ kEvenKey, + /* even_content_iv= */ + absl::StrCat(kEvenContentIv8Bytes, kEvenContentIv8Bytes), + /* odd_key= */ kOddKey, + /* odd_content_iv= */ + absl::StrCat(kOddContentIv8Bytes, kOddContentIv8Bytes), + /* entitlement_key_id= */ kEntitlementKeyId, + /* entitlement_key= */ kEntitlementKey, &ecm); + if (!status.ok()) { + LOG(FATAL) << "Failed to generate WV CAS ECM, error: " << status; + } else { + LOG(INFO) << "Generated WV CAS ECM (in hex): " + << absl::BytesToHexString(ecm); + } + + return 0; +} diff --git a/libmedia_cas_packager_sdk.so b/libmedia_cas_packager_sdk.so index 06bab3b..889c083 100755 Binary files a/libmedia_cas_packager_sdk.so and b/libmedia_cas_packager_sdk.so differ diff --git a/media_cas_packager_sdk/public/wv_cas_ecm.h b/media_cas_packager_sdk/public/wv_cas_ecm.h index 54695ab..2b76cc2 100644 --- a/media_cas_packager_sdk/public/wv_cas_ecm.h +++ b/media_cas_packager_sdk/public/wv_cas_ecm.h @@ -38,8 +38,9 @@ class WvCasEcm { // // Args: // - |content_iv_size| iv size in bytes for encrypting the content, - // only support 8 bytes now - // TODO(user): Double-check with jfore@ regarding only support 8 bytes. + // only support 8 bytes or 16 bytes + // When using 8 bytes content_iv, we assume additional 8 bytes of '\x00' are + // appended to the iv to form a 16 bytes AES IV when content is encrypted. // - |key_rotation_enabled| whether key rotation is enabled, // if this is 'true' only subsequent call to GenerateEcm will be allowed, // if this is 'false' only subsequent call to GenerateSingleKeyEcm will @@ -47,7 +48,6 @@ class WvCasEcm { // - |crypto_mode| crypto mode for encrypting content, // kCryptoModeCbc = 0, kCryptoModeCtr = 1 // only CTR is supported by Widevine CAS plugin for now - // TODO(user): Check with jfore@ regarding supporting kCryptoModeCbc. // // Returns: // - A status indicating whether there was any error during initialization @@ -62,10 +62,8 @@ class WvCasEcm { // // Args: // - |even_key| clear even content key - // - |even_wrapping_iv| iv used when encrypting |even_key| in the ECM // - |even_content_iv| iv used along with |even_key| for encrypting content // - |odd_key| clear odd content key - // - |odd_wrapping_iv| iv used when encrypting |odd_key| in the ECM // - |odd_content_iv| iv used along with |odd_key| for encrypting content // - |entitlement_key_id| key id for |entitlement_key| // - |entitlement_key| entitlement key used to encrypt even and odd keys @@ -77,15 +75,10 @@ class WvCasEcm { // Note: // - The same |entitlement_key| will be used to encrypt both |even_key| // and |odd_key| in the ECM - // - Currently, we only allow |even_content_iv| and |odd_content_iv| - // to be of size 8 bytes, so we assume the encryptor would append suffix - // {'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'} - // to |even_content_iv| and |odd_content_iv| to obtain a 16 bytes IV - // before encrypting the content + // - Size of |even_content_iv| and |odd_content_iv| must match + // |content_iv_size| set during initialization util::Status GenerateEcm(const std::string& even_key, - const std::string& even_wrapping_iv, const std::string& even_content_iv, const std::string& odd_key, - const std::string& odd_wrapping_iv, const std::string& odd_content_iv, const std::string& entitlement_key_id, const std::string& entitlement_key, std::string* ecm); @@ -95,7 +88,6 @@ class WvCasEcm { // // Args: // - |even_key| clear even content key - // - |even_wrapping_iv| iv used when encrypting |even_key| in the ECM // - |even_content_iv| iv used along with |even_key| for encrypting content // - |entitlement_key_id| key id for |entitlement_key| // - |entitlement_key| entitlement key used to encrypt even key @@ -105,14 +97,9 @@ class WvCasEcm { // - A status indicating whether there was any error during processing // // Note: - // - // - Currently, we only allow |even_content_iv| - // to be of size 8 bytes, so we assume the encryptor would append suffix - // {'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'} - // to |even_content_iv| to obtain a 16 bytes IV - // before encrypting the content + // - Size of |even_content_iv| and |odd_content_iv| must match + // |content_iv_size| set during initialization util::Status GenerateSingleKeyEcm(const std::string& even_key, - const std::string& even_wrapping_iv, const std::string& even_content_iv, const std::string& entitlement_key_id, const std::string& entitlement_key, std::string* ecm);