Print uint16 as \x01 not \x1
------------- Allow the usage of different entitlement keys to wrap even vs. odd key. ------------- (1) Change parameter type from 'string' to 'const char* const' to handle possible '\x00' (Nul char) byte in the input. (2) Check size of generated ECM string, return error if the size is not as expected. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=220172089
This commit is contained in:
Binary file not shown.
@@ -14,32 +14,32 @@
|
||||
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
const bool kKeyRotationEnabled = true;
|
||||
const char kEvenKey[] = "even_content_key"; // 16 bytes
|
||||
const char kCsaEvenKey[] = "12345678"; // 8 bytes
|
||||
const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes
|
||||
const char kEvenContentIv16Bytes[] = "evencontevencont"; // 16 bytes
|
||||
const char kOddKey[] = "odd_content_key."; // 16 bytes
|
||||
const char kCsaOddKey[] = "87654321"; // 8 bytes
|
||||
const char kOddContentIv8Bytes[] = "oddcont."; // 8 bytes
|
||||
const char kOddContentIv16Bytes[] = "oddcont.oddcont."; // 16 bytes
|
||||
const char kEntitlementKeyId[] = "ent_key_id......"; // 16 bytes
|
||||
const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes
|
||||
const char kCsaEvenKey[] = "even_key"; // 8 bytes
|
||||
const char kEvenContentIv8Bytes[] = "even_iv."; // 8 bytes
|
||||
const char kEvenEntitlementKeyId[] = "fake_key_id1...."; // 16 bytes
|
||||
const char kEvenEntitlementKey[] =
|
||||
"fakefakefakefakefakefakefake1..."; // 32 bytes
|
||||
const char kCsaOddKey[] = "odd_key."; // 8 bytes
|
||||
const char kOddContentIv8Bytes[] = "odd_iv.."; // 8 bytes
|
||||
const char kOddEntitlementKeyId[] = "fake_key_id2...."; // 16 bytes
|
||||
const char kOddEntitlementKey[] =
|
||||
"fakefakefakefakefakefakefake2..."; // 32 bytes
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
widevine::cas::WvCasEcm wv_cas_ecm;
|
||||
widevine::cas::WvCasStatus status =
|
||||
wv_cas_ecm.Initialize(/* content_iv_size= */ 8, kKeyRotationEnabled,
|
||||
widevine::cas::CryptoMode::kDvbCsa2);
|
||||
widevine::cas::WvCasStatus status = wv_cas_ecm.Initialize(
|
||||
/* content_iv_size= */ 8, /* key_rotation_enabled= */ true,
|
||||
widevine::cas::CryptoMode::kDvbCsa2);
|
||||
if (status != widevine::cas::OK) {
|
||||
std::cerr << "Failed to initialize WV CAS ECM, error: "
|
||||
<< widevine::cas::GetWvCasStatusMessage(status)
|
||||
<< std::endl;
|
||||
}
|
||||
std::string ecm;
|
||||
status = wv_cas_ecm.GenerateEcm(kCsaEvenKey, kEvenContentIv8Bytes, kCsaOddKey,
|
||||
kOddContentIv8Bytes, kEntitlementKeyId,
|
||||
kEntitlementKey, &ecm);
|
||||
status = wv_cas_ecm.GenerateEcm(
|
||||
kCsaEvenKey, kEvenContentIv8Bytes, kEvenEntitlementKeyId,
|
||||
kEvenEntitlementKey, kCsaOddKey, kOddContentIv8Bytes,
|
||||
kOddEntitlementKeyId, kOddEntitlementKey, &ecm);
|
||||
if (status != widevine::cas::OK) {
|
||||
std::cerr << "Failed to generate WV CAS ECM, error: "
|
||||
<< widevine::cas::GetWvCasStatusMessage(status)
|
||||
@@ -48,7 +48,7 @@ int main(int argc, char **argv) {
|
||||
std::cout << "ECM size: " << ecm.size() << std::endl;
|
||||
std::cout << "ECM bytes: ";
|
||||
for (size_t i = 0; i < ecm.size(); i++) {
|
||||
printf("'\\x%x', ", static_cast<uint16_t>(ecm.at(i)));
|
||||
printf("'\\x%02x', ", static_cast<uint16_t>(ecm.at(i)));
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -55,52 +55,61 @@ class WvCasEcm {
|
||||
// Generate an ECM containing two keys (even and odd). Can be called when
|
||||
// |key_rotation_enabled| is initialized to 'true'.
|
||||
//
|
||||
// Args:
|
||||
// - |even_key| clear even content key
|
||||
// - |even_content_iv| iv used along with |even_key| for encrypting content
|
||||
// - |odd_key| clear odd content key
|
||||
// - |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
|
||||
// - |ecm| for returning the generated ECM, must not be nullptr
|
||||
// Args (all pointer parameters must be not nullptr):
|
||||
// - |even_key| clear even content key, must be 8 bytes for kDvbCsa2,
|
||||
// 16 bytes for kAesCtr or kAesCbc
|
||||
// - |even_content_iv| iv used along with |even_key| for encrypting content,
|
||||
// length must match |content_iv_size| set during initialization
|
||||
// - |even_entitlement_key_id| key id for |even_entitlement_key|,
|
||||
// must be 16 bytes length
|
||||
// - |even_entitlement_key| entitlement key used to encrypt even key,
|
||||
// must be 32 bytes length
|
||||
// - |odd_key| clear odd content key, must be 8 bytes for kDvbCsa2,
|
||||
// 16 bytes for kAesCtr or kAesCbc
|
||||
// - |odd_content_iv| iv used along with |odd_key| for encrypting content,
|
||||
// length must match |content_iv_size| set during initialization
|
||||
// - |odd_entitlement_key_id| key id for |odd_entitlement_key|,
|
||||
// must be 16 bytes length
|
||||
// - |odd_entitlement_key| entitlement key used to encrypt odd key,
|
||||
// must be 32 bytes length
|
||||
// - |ecm| for returning the generated ECM,
|
||||
// size of the generated ecm is 149 bytes when content iv is 8 bytes
|
||||
// 165 bytes when content iv is 16 bytes
|
||||
//
|
||||
// Returns:
|
||||
// - A status indicating whether there was any error during processing
|
||||
//
|
||||
// Note:
|
||||
// - The same |entitlement_key| will be used to encrypt both |even_key|
|
||||
// and |odd_key| in the ECM
|
||||
// - Size of |even_content_iv| and |odd_content_iv| must match
|
||||
// |content_iv_size| set during initialization
|
||||
virtual WvCasStatus GenerateEcm(const std::string& even_key,
|
||||
const std::string& even_content_iv,
|
||||
const std::string& odd_key,
|
||||
const std::string& odd_content_iv,
|
||||
const std::string& entitlement_key_id,
|
||||
const std::string& entitlement_key,
|
||||
virtual WvCasStatus GenerateEcm(const char* const even_key,
|
||||
const char* const even_content_iv,
|
||||
const char* const even_entitlement_key_id,
|
||||
const char* const even_entitlement_key,
|
||||
const char* const odd_key,
|
||||
const char* const odd_content_iv,
|
||||
const char* const odd_entitlement_key_id,
|
||||
const char* const odd_entitlement_key,
|
||||
std::string* ecm) const;
|
||||
|
||||
// Generate an ECM containing only a singe even key. Can be called when
|
||||
// |key_rotation_enabled| is initialized to 'false'.
|
||||
//
|
||||
// Args:
|
||||
// - |even_key| clear even content key
|
||||
// - |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
|
||||
// - |ecm| for returning the generated ECM, must not be nullptr
|
||||
// Args (all pointer parameters must be not nullptr):
|
||||
// - |even_key| clear even content key, must be 8 bytes for kDvbCsa2,
|
||||
// 16 bytes for kAesCtr or kAesCbc
|
||||
// - |even_content_iv| iv used along with |even_key| for encrypting content,
|
||||
// length must match |content_iv_size| set during initialization
|
||||
// - |even_entitlement_key_id| key id for |even_entitlement_key|,
|
||||
// must be 16 bytes length
|
||||
// - |even_entitlement_key| entitlement key used to encrypt even key,
|
||||
// must be 32 bytes length
|
||||
// - |ecm| for returning the generated ECM,
|
||||
// size of the generated ecm is 77 bytes when content iv is 8 bytes
|
||||
// 85 bytes when content iv is 16 bytes
|
||||
//
|
||||
// Returns:
|
||||
// - A status indicating whether there was any error during processing
|
||||
//
|
||||
// Note:
|
||||
// - Size of |even_content_iv| and |odd_content_iv| must match
|
||||
// |content_iv_size| set during initialization
|
||||
virtual WvCasStatus GenerateSingleKeyEcm(const std::string& even_key,
|
||||
const std::string& even_content_iv,
|
||||
const std::string& entitlement_key_id,
|
||||
const std::string& entitlement_key,
|
||||
std::string* ecm) const;
|
||||
virtual WvCasStatus GenerateSingleKeyEcm(
|
||||
const char* const even_key, const char* const even_content_iv,
|
||||
const char* const even_entitlement_key_id,
|
||||
const char* const even_entitlement_key, std::string* ecm) const;
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
|
||||
Reference in New Issue
Block a user