Squashed merge 3 CLs.
1. "Change CdmResponseType from enum into a struct" Merged from http://go/wvgerrit/163199 Bug: 253271674 2. "Log request information when server returns 401" Bug: 260760387 Bug: 186031735 Merged from http://go/wvgerrit/162798 3. "Specify server version on the command line" Bug: 251599048 Merged from http://go/wvgerrit/158897 Test: build android.hardware.drm-service.widevine Test: Netflix and Play Movies & TV Test: build_and_run_all_unit_tests.sh Bug: 253271674 Change-Id: I70c950acce070609ee0343920ec68e66b058bc23
This commit is contained in:
@@ -143,17 +143,17 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
|
||||
SignedDrmCertificate signed_root_cert;
|
||||
if (!signed_root_cert.ParseFromString(root_cert_str)) {
|
||||
LOGE("Failed to deserialize signed root certificate");
|
||||
return DEVICE_CERTIFICATE_ERROR_1;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_1);
|
||||
}
|
||||
DrmCertificate root_cert;
|
||||
if (!root_cert.ParseFromString(signed_root_cert.drm_certificate())) {
|
||||
LOGE("Failed to deserialize root certificate");
|
||||
return DEVICE_CERTIFICATE_ERROR_1;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_1);
|
||||
}
|
||||
RsaPublicKey root_key;
|
||||
if (!root_key.Init(root_cert.public_key())) {
|
||||
LOGE("Failed to load root certificate public key");
|
||||
return DEVICE_CERTIFICATE_ERROR_1;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_1);
|
||||
}
|
||||
|
||||
// Load the provided service certificate.
|
||||
@@ -161,7 +161,7 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
|
||||
SignedDrmCertificate signed_service_cert;
|
||||
if (!signed_service_cert.ParseFromString(certificate)) {
|
||||
LOGE("Failed to parse signed service certificate");
|
||||
return DEVICE_CERTIFICATE_ERROR_2;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_2);
|
||||
}
|
||||
|
||||
#ifdef ACCEPT_TEST_CERT
|
||||
@@ -170,14 +170,14 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
|
||||
if (!root_key.VerifySignature(signed_service_cert.drm_certificate(),
|
||||
signed_service_cert.signature())) {
|
||||
LOGE("Failed to verify service certificate signature");
|
||||
return DEVICE_CERTIFICATE_ERROR_3;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_3);
|
||||
}
|
||||
#endif
|
||||
|
||||
DrmCertificate service_cert;
|
||||
if (!service_cert.ParseFromString(signed_service_cert.drm_certificate())) {
|
||||
LOGE("Failed to parse service certificate");
|
||||
return DEVICE_CERTIFICATE_ERROR_2;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_2);
|
||||
}
|
||||
if (service_cert.type() != video_widevine::DrmCertificate_Type_SERVICE) {
|
||||
LOGE(
|
||||
@@ -185,7 +185,7 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
|
||||
"type = %d, expected_type = %d",
|
||||
static_cast<int>(service_cert.type()),
|
||||
static_cast<int>(video_widevine::DrmCertificate_Type_SERVICE));
|
||||
return DEVICE_CERTIFICATE_ERROR_3;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_3);
|
||||
}
|
||||
|
||||
// Service certificate passes all checks - set up its RSA public key.
|
||||
@@ -193,7 +193,7 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
|
||||
if (!public_key_->Init(service_cert.public_key())) {
|
||||
public_key_.reset();
|
||||
LOGE("Failed to load service certificate public key");
|
||||
return DEVICE_CERTIFICATE_ERROR_2;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_2);
|
||||
}
|
||||
|
||||
// Have service certificate and its public key - keep relevant fields.
|
||||
@@ -202,33 +202,34 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
|
||||
provider_id_ = service_cert.provider_id();
|
||||
has_certificate_ = true;
|
||||
|
||||
return NO_ERROR;
|
||||
return CdmResponseType(NO_ERROR);
|
||||
}
|
||||
|
||||
CdmResponseType ServiceCertificate::VerifySignedMessage(
|
||||
const std::string& message, const std::string& signature) const {
|
||||
if (!public_key_) {
|
||||
LOGE("Service certificate not set");
|
||||
return DEVICE_CERTIFICATE_ERROR_4;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_4);
|
||||
}
|
||||
|
||||
if (!public_key_->VerifySignature(message, signature))
|
||||
return CLIENT_ID_RSA_ENCRYPT_ERROR; // TODO(tinskip): Need new error code.
|
||||
return CdmResponseType(
|
||||
CLIENT_ID_RSA_ENCRYPT_ERROR); // TODO(tinskip): Need new error code.
|
||||
|
||||
return NO_ERROR;
|
||||
return CdmResponseType(NO_ERROR);
|
||||
}
|
||||
|
||||
CdmResponseType ServiceCertificate::EncryptRsaOaep(
|
||||
const std::string& plaintext, std::string* ciphertext) const {
|
||||
if (!public_key_) {
|
||||
LOGE("Service certificate not set");
|
||||
return DEVICE_CERTIFICATE_ERROR_4;
|
||||
return CdmResponseType(DEVICE_CERTIFICATE_ERROR_4);
|
||||
}
|
||||
|
||||
if (!public_key_->Encrypt(plaintext, ciphertext))
|
||||
return CLIENT_ID_RSA_ENCRYPT_ERROR;
|
||||
return CdmResponseType(CLIENT_ID_RSA_ENCRYPT_ERROR);
|
||||
|
||||
return NO_ERROR;
|
||||
return CdmResponseType(NO_ERROR);
|
||||
}
|
||||
|
||||
CdmResponseType ServiceCertificate::EncryptClientId(
|
||||
@@ -245,8 +246,9 @@ CdmResponseType ServiceCertificate::EncryptClientId(
|
||||
|
||||
if (status != NO_ERROR) {
|
||||
LOGE("GetRandom failed for key: status = %d", static_cast<int>(status));
|
||||
return (status == RANDOM_GENERATION_ERROR) ? CLIENT_ID_GENERATE_RANDOM_ERROR
|
||||
: status;
|
||||
return (status == RANDOM_GENERATION_ERROR)
|
||||
? CdmResponseType(CLIENT_ID_GENERATE_RANDOM_ERROR)
|
||||
: status;
|
||||
}
|
||||
|
||||
status =
|
||||
@@ -254,15 +256,17 @@ CdmResponseType ServiceCertificate::EncryptClientId(
|
||||
|
||||
if (status != NO_ERROR) {
|
||||
LOGE("GetRandom failed for IV: status = %d", static_cast<int>(status));
|
||||
return (status == RANDOM_GENERATION_ERROR) ? CLIENT_ID_GENERATE_RANDOM_ERROR
|
||||
: status;
|
||||
return (status == RANDOM_GENERATION_ERROR)
|
||||
? CdmResponseType(CLIENT_ID_GENERATE_RANDOM_ERROR)
|
||||
: status;
|
||||
}
|
||||
std::string id, enc_id, enc_key;
|
||||
clear_client_id->SerializeToString(&id);
|
||||
|
||||
AesCbcKey aes;
|
||||
if (!aes.Init(key)) return CLIENT_ID_AES_INIT_ERROR;
|
||||
if (!aes.Encrypt(id, &enc_id, &iv)) return CLIENT_ID_AES_ENCRYPT_ERROR;
|
||||
if (!aes.Init(key)) return CdmResponseType(CLIENT_ID_AES_INIT_ERROR);
|
||||
if (!aes.Encrypt(id, &enc_id, &iv))
|
||||
return CdmResponseType(CLIENT_ID_AES_ENCRYPT_ERROR);
|
||||
|
||||
CdmResponseType encrypt_result = EncryptRsaOaep(key, &enc_key);
|
||||
if (encrypt_result != NO_ERROR) return encrypt_result;
|
||||
@@ -270,7 +274,7 @@ CdmResponseType ServiceCertificate::EncryptClientId(
|
||||
encrypted_client_id->set_encrypted_client_id_iv(iv);
|
||||
encrypted_client_id->set_encrypted_privacy_key(enc_key);
|
||||
encrypted_client_id->set_encrypted_client_id(enc_id);
|
||||
return NO_ERROR;
|
||||
return CdmResponseType(NO_ERROR);
|
||||
}
|
||||
|
||||
bool ServiceCertificate::GetRequest(CdmKeyMessage* request) {
|
||||
@@ -288,39 +292,39 @@ CdmResponseType ServiceCertificate::ParseResponse(const std::string& response,
|
||||
std::string* certificate) {
|
||||
if (response.empty()) {
|
||||
LOGE("Response is empty");
|
||||
return EMPTY_RESPONSE_ERROR_1;
|
||||
return CdmResponseType(EMPTY_RESPONSE_ERROR_1);
|
||||
}
|
||||
if (certificate == nullptr) {
|
||||
LOGE("Output parameter |certificate| not provided");
|
||||
return INVALID_PARAMETERS_ENG_24;
|
||||
return CdmResponseType(INVALID_PARAMETERS_ENG_24);
|
||||
}
|
||||
|
||||
SignedMessage signed_response;
|
||||
if (!signed_response.ParseFromString(response)) {
|
||||
LOGE("Failed to parse signed response");
|
||||
return PARSE_RESPONSE_ERROR_1;
|
||||
return CdmResponseType(PARSE_RESPONSE_ERROR_1);
|
||||
}
|
||||
|
||||
if (signed_response.type() == SignedMessage::ERROR_RESPONSE) {
|
||||
LicenseError license_error;
|
||||
if (!license_error.ParseFromString(signed_response.msg())) {
|
||||
LOGE("Failed to parse license error");
|
||||
return PARSE_RESPONSE_ERROR_2;
|
||||
return CdmResponseType(PARSE_RESPONSE_ERROR_2);
|
||||
}
|
||||
LOGE("Server response contains error: error_code = %d",
|
||||
static_cast<int>(license_error.error_code()));
|
||||
return PARSE_RESPONSE_ERROR_3;
|
||||
return CdmResponseType(PARSE_RESPONSE_ERROR_3);
|
||||
}
|
||||
|
||||
if (signed_response.type() != SignedMessage::SERVICE_CERTIFICATE) {
|
||||
LOGE("Unexpected response type: type = %d, expected_type = %d",
|
||||
static_cast<int>(signed_response.type()),
|
||||
static_cast<int>(SignedMessage::SERVICE_CERTIFICATE));
|
||||
return PARSE_RESPONSE_ERROR_4;
|
||||
return CdmResponseType(PARSE_RESPONSE_ERROR_4);
|
||||
}
|
||||
|
||||
certificate->assign(signed_response.msg());
|
||||
return NO_ERROR;
|
||||
return CdmResponseType(NO_ERROR);
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user