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,22 +14,21 @@
|
|||||||
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
||||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||||
|
|
||||||
const bool kKeyRotationEnabled = true;
|
const char kCsaEvenKey[] = "even_key"; // 8 bytes
|
||||||
const char kEvenKey[] = "even_content_key"; // 16 bytes
|
const char kEvenContentIv8Bytes[] = "even_iv."; // 8 bytes
|
||||||
const char kCsaEvenKey[] = "12345678"; // 8 bytes
|
const char kEvenEntitlementKeyId[] = "fake_key_id1...."; // 16 bytes
|
||||||
const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes
|
const char kEvenEntitlementKey[] =
|
||||||
const char kEvenContentIv16Bytes[] = "evencontevencont"; // 16 bytes
|
"fakefakefakefakefakefakefake1..."; // 32 bytes
|
||||||
const char kOddKey[] = "odd_content_key."; // 16 bytes
|
const char kCsaOddKey[] = "odd_key."; // 8 bytes
|
||||||
const char kCsaOddKey[] = "87654321"; // 8 bytes
|
const char kOddContentIv8Bytes[] = "odd_iv.."; // 8 bytes
|
||||||
const char kOddContentIv8Bytes[] = "oddcont."; // 8 bytes
|
const char kOddEntitlementKeyId[] = "fake_key_id2...."; // 16 bytes
|
||||||
const char kOddContentIv16Bytes[] = "oddcont.oddcont."; // 16 bytes
|
const char kOddEntitlementKey[] =
|
||||||
const char kEntitlementKeyId[] = "ent_key_id......"; // 16 bytes
|
"fakefakefakefakefakefakefake2..."; // 32 bytes
|
||||||
const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
widevine::cas::WvCasEcm wv_cas_ecm;
|
widevine::cas::WvCasEcm wv_cas_ecm;
|
||||||
widevine::cas::WvCasStatus status =
|
widevine::cas::WvCasStatus status = wv_cas_ecm.Initialize(
|
||||||
wv_cas_ecm.Initialize(/* content_iv_size= */ 8, kKeyRotationEnabled,
|
/* content_iv_size= */ 8, /* key_rotation_enabled= */ true,
|
||||||
widevine::cas::CryptoMode::kDvbCsa2);
|
widevine::cas::CryptoMode::kDvbCsa2);
|
||||||
if (status != widevine::cas::OK) {
|
if (status != widevine::cas::OK) {
|
||||||
std::cerr << "Failed to initialize WV CAS ECM, error: "
|
std::cerr << "Failed to initialize WV CAS ECM, error: "
|
||||||
@@ -37,9 +36,10 @@ int main(int argc, char **argv) {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
std::string ecm;
|
std::string ecm;
|
||||||
status = wv_cas_ecm.GenerateEcm(kCsaEvenKey, kEvenContentIv8Bytes, kCsaOddKey,
|
status = wv_cas_ecm.GenerateEcm(
|
||||||
kOddContentIv8Bytes, kEntitlementKeyId,
|
kCsaEvenKey, kEvenContentIv8Bytes, kEvenEntitlementKeyId,
|
||||||
kEntitlementKey, &ecm);
|
kEvenEntitlementKey, kCsaOddKey, kOddContentIv8Bytes,
|
||||||
|
kOddEntitlementKeyId, kOddEntitlementKey, &ecm);
|
||||||
if (status != widevine::cas::OK) {
|
if (status != widevine::cas::OK) {
|
||||||
std::cerr << "Failed to generate WV CAS ECM, error: "
|
std::cerr << "Failed to generate WV CAS ECM, error: "
|
||||||
<< widevine::cas::GetWvCasStatusMessage(status)
|
<< 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 size: " << ecm.size() << std::endl;
|
||||||
std::cout << "ECM bytes: ";
|
std::cout << "ECM bytes: ";
|
||||||
for (size_t i = 0; i < ecm.size(); i++) {
|
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;
|
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
|
// Generate an ECM containing two keys (even and odd). Can be called when
|
||||||
// |key_rotation_enabled| is initialized to 'true'.
|
// |key_rotation_enabled| is initialized to 'true'.
|
||||||
//
|
//
|
||||||
// Args:
|
// Args (all pointer parameters must be not nullptr):
|
||||||
// - |even_key| clear even content key
|
// - |even_key| clear even content key, must be 8 bytes for kDvbCsa2,
|
||||||
// - |even_content_iv| iv used along with |even_key| for encrypting content
|
// 16 bytes for kAesCtr or kAesCbc
|
||||||
// - |odd_key| clear odd content key
|
// - |even_content_iv| iv used along with |even_key| for encrypting content,
|
||||||
// - |odd_content_iv| iv used along with |odd_key| for encrypting content
|
// length must match |content_iv_size| set during initialization
|
||||||
// - |entitlement_key_id| key id for |entitlement_key|
|
// - |even_entitlement_key_id| key id for |even_entitlement_key|,
|
||||||
// - |entitlement_key| entitlement key used to encrypt even and odd keys
|
// must be 16 bytes length
|
||||||
// - |ecm| for returning the generated ECM, must not be nullptr
|
// - |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:
|
// Returns:
|
||||||
// - A status indicating whether there was any error during processing
|
// - A status indicating whether there was any error during processing
|
||||||
//
|
virtual WvCasStatus GenerateEcm(const char* const even_key,
|
||||||
// Note:
|
const char* const even_content_iv,
|
||||||
// - The same |entitlement_key| will be used to encrypt both |even_key|
|
const char* const even_entitlement_key_id,
|
||||||
// and |odd_key| in the ECM
|
const char* const even_entitlement_key,
|
||||||
// - Size of |even_content_iv| and |odd_content_iv| must match
|
const char* const odd_key,
|
||||||
// |content_iv_size| set during initialization
|
const char* const odd_content_iv,
|
||||||
virtual WvCasStatus GenerateEcm(const std::string& even_key,
|
const char* const odd_entitlement_key_id,
|
||||||
const std::string& even_content_iv,
|
const char* const odd_entitlement_key,
|
||||||
const std::string& odd_key,
|
|
||||||
const std::string& odd_content_iv,
|
|
||||||
const std::string& entitlement_key_id,
|
|
||||||
const std::string& entitlement_key,
|
|
||||||
std::string* ecm) const;
|
std::string* ecm) const;
|
||||||
|
|
||||||
// Generate an ECM containing only a singe even key. Can be called when
|
// Generate an ECM containing only a singe even key. Can be called when
|
||||||
// |key_rotation_enabled| is initialized to 'false'.
|
// |key_rotation_enabled| is initialized to 'false'.
|
||||||
//
|
//
|
||||||
// Args:
|
// Args (all pointer parameters must be not nullptr):
|
||||||
// - |even_key| clear even content key
|
// - |even_key| clear even content key, must be 8 bytes for kDvbCsa2,
|
||||||
// - |even_content_iv| iv used along with |even_key| for encrypting content
|
// 16 bytes for kAesCtr or kAesCbc
|
||||||
// - |entitlement_key_id| key id for |entitlement_key|
|
// - |even_content_iv| iv used along with |even_key| for encrypting content,
|
||||||
// - |entitlement_key| entitlement key used to encrypt even key
|
// length must match |content_iv_size| set during initialization
|
||||||
// - |ecm| for returning the generated ECM, must not be nullptr
|
// - |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:
|
// Returns:
|
||||||
// - A status indicating whether there was any error during processing
|
// - A status indicating whether there was any error during processing
|
||||||
//
|
virtual WvCasStatus GenerateSingleKeyEcm(
|
||||||
// Note:
|
const char* const even_key, const char* const even_content_iv,
|
||||||
// - Size of |even_content_iv| and |odd_content_iv| must match
|
const char* const even_entitlement_key_id,
|
||||||
// |content_iv_size| set during initialization
|
const char* const even_entitlement_key, std::string* ecm) const;
|
||||||
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;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user