Exposing the Cast Signing Algorithm

[ Merge of http://go/wvgerrit/178076 ]

1. Exposing the Cast Signing Algorithm in cdm core.
2. Update core Cast tests to use new core CDM Cast signing API.

Bug: 279671867
Bug: 279672538
Test: com.google.android.wvts
Change-Id: Ia73c4b5e6dd61edf790bca97a321881d310e7a99
(cherry picked from commit 8996b624d73adf14db45e54653e7ddc513f3895c)
This commit is contained in:
Kyle Zhang
2023-04-27 19:12:09 +00:00
parent d655ffbfe7
commit bd389027a1
10 changed files with 108 additions and 60 deletions

View File

@@ -2340,4 +2340,48 @@ void CdmEngine::SetFastOtaKeyboxFallbackDurationRules() {
}
system_fallback_policy->SetFastBackoffDurationRules();
}
CdmResponseType CdmEngine::SignRSA(const std::string& wrapped_key,
const std::string& message,
std::string* signature,
RSA_Padding_Scheme padding_scheme) {
// Try to open cdm session.
CdmSessionId session_id;
auto sts = OpenSession("com.widevine", nullptr, nullptr, &session_id);
if (sts != NO_ERROR) {
LOGE("OpenSession failed, status: %d", static_cast<int>(sts));
return sts;
}
// Retrieve the cdm session
std::shared_ptr<CdmSession> session;
if (!session_map_.FindSession(session_id, &session)) {
LOGE("Session not found: session_id = %s", IdToString(session_id));
return CdmResponseType(SESSION_NOT_FOUND_24);
}
// Load cast private key for signing
CryptoWrappedKey key(CryptoWrappedKey::kRsa, wrapped_key);
sts = session->LoadCastPrivateKey(key);
if (sts != NO_ERROR) {
LOGE("LoadCastPrivateKey failed, status: %d", static_cast<int>(sts));
return sts;
}
// Generate Rsa signature for cast message
sts = session->GenerateRSASignature(message, signature, padding_scheme);
if (sts != NO_ERROR) {
LOGE("GenerateRSASignature failed, status: %d", static_cast<int>(sts));
return sts;
}
// Try to close cdm session.
sts = CloseSession(session_id);
if (sts != NO_ERROR) {
LOGE("CloseSession failed, status: %d", static_cast<int>(sts));
return sts;
}
return sts;
}
} // namespace wvcdm

View File

@@ -1302,6 +1302,18 @@ bool CdmSession::HasRootOfTrustBeenRenewed() {
return true;
}
CdmResponseType CdmSession::LoadCastPrivateKey(
const CryptoWrappedKey& private_key) {
return crypto_session_->LoadCertificatePrivateKey(private_key);
}
CdmResponseType CdmSession::GenerateRSASignature(const std::string& message,
std::string* signature,
RSA_Padding_Scheme scheme) {
return crypto_session_->GenerateRsaSignature(message, signature,
scheme);
}
// For testing only - takes ownership of pointers
void CdmSession::set_license_parser(CdmLicense* license_parser) {

View File

@@ -1573,7 +1573,8 @@ CdmResponseType CryptoSession::GenerateDerivedKeys(
}
CdmResponseType CryptoSession::GenerateRsaSignature(const std::string& message,
std::string* signature) {
std::string* signature,
RSA_Padding_Scheme scheme) {
LOGV("Generating RSA signature: id = %u", oec_session_id_);
RETURN_IF_NULL(signature, PARAMETER_NULL);
@@ -1590,7 +1591,7 @@ CdmResponseType CryptoSession::GenerateRsaSignature(const std::string& message,
oec_session_id_, reinterpret_cast<const uint8_t*>(message.data()),
message.size(),
reinterpret_cast<uint8_t*>(const_cast<char*>(signature->data())),
&length, kSign_RSASSA_PSS),
&length, scheme),
metrics_, oemcrypto_generate_rsa_signature_, sts,
metrics::Pow2Bucket(length));
});
@@ -3329,4 +3330,5 @@ CryptoSession* CryptoSessionFactory::MakeCryptoSession(
metrics::CryptoMetrics* crypto_metrics) {
return new CryptoSession(crypto_metrics);
}
} // namespace wvcdm

View File

@@ -867,6 +867,8 @@ const char* CdmResponseEnumToString(CdmResponseEnum cdm_response_enum) {
return "STORE_ATSC_LICENSE_ERROR";
case SESSION_NOT_FOUND_GENERIC_CRYPTO:
return "SESSION_NOT_FOUND_GENERIC_CRYPTO";
case SESSION_NOT_FOUND_24:
return "SESSION_NOT_FOUND_24";
}
return UnknownValueRep(cdm_response_enum);
}