Log cleanup and reformatting for core/ (Part 2-6)

[ Merge of http://go/wvgerrit/83423 ]
[ Merge of http://go/wvgerrit/83424 ]
[ Merge of http://go/wvgerrit/83425 ]
[ Merge of http://go/wvgerrit/83426 ]
[ Merge of http://go/wvgerrit/83427 ]

Types of cleanup:
  - Removed function / class prefixes from the logs.
  - Fixed log string format options to match the types passed
  - Corrected small spelling mistakes / typos
  - _Tried_ to make the log format more consistent
  - Added static_cast<int> conversion on enumerations when logged
  - Changed several LOGE to LOGW and vice versa
      - Used LOGE if the triggering condition stops the method/function
        from completing its task
      - Used LOGW if the triggering condition changes the expected
        outcome but does not stop the rest of the method/function's
        task
  - Changed several instances of `NULL` to `nullptr`
  - Ran clang-format on files after cleanup

This is part of a larger code quality effort in Widevine DRM.

Test: WV linux unittests and WV Android unit tests
Bug: 134460638
Bug: 134365840
Bug: 136123217
Change-Id: I958ec70ef99eef95c38dbebd7a1acd62ef304145
This commit is contained in:
Alex Dale
2019-08-01 11:18:12 -07:00
parent 79a28e5ddb
commit f4360552b7
15 changed files with 871 additions and 1132 deletions

View File

@@ -142,17 +142,17 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
// Load root cert public key. Don't bother verifying it.
SignedDrmDeviceCertificate signed_root_cert;
if (!signed_root_cert.ParseFromString(root_cert_str)) {
LOGE("Failed to deserialize signed root certificate.");
LOGE("Failed to deserialize signed root certificate");
return DEVICE_CERTIFICATE_ERROR_1;
}
DrmDeviceCertificate root_cert;
if (!root_cert.ParseFromString(signed_root_cert.drm_certificate())) {
LOGE("Failed to deserialize signed root certificate.");
LOGE("Failed to deserialize root certificate");
return DEVICE_CERTIFICATE_ERROR_1;
}
RsaPublicKey root_key;
if (!root_key.Init(root_cert.public_key())) {
LOGE("Failed to load root certificate public key.");
LOGE("Failed to load root certificate public key");
return DEVICE_CERTIFICATE_ERROR_1;
}
@@ -160,22 +160,27 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
// First, parse it and verify its signature.
SignedDrmDeviceCertificate signed_service_cert;
if (!signed_service_cert.ParseFromString(certificate)) {
LOGE("Failed to parse signed service certificate.");
LOGE("Failed to parse signed service certificate");
return DEVICE_CERTIFICATE_ERROR_2;
}
if (!root_key.VerifySignature(signed_service_cert.drm_certificate(),
signed_service_cert.signature())) {
LOGE("Service certificate signature verification failed.");
LOGE("Failed to verify service certificate signature");
return DEVICE_CERTIFICATE_ERROR_3;
}
DrmDeviceCertificate service_cert;
if (!service_cert.ParseFromString(signed_service_cert.drm_certificate())) {
LOGE("Failed to parse service certificate.");
LOGE("Failed to parse service certificate");
return DEVICE_CERTIFICATE_ERROR_2;
}
if (service_cert.type() !=
video_widevine::DrmDeviceCertificate_CertificateType_SERVICE) {
LOGE("Not a service certificate.");
LOGE(
"DRM device certificate type is not a service certificate: "
"type = %d, expected_type = %d",
static_cast<int>(service_cert.type()),
static_cast<int>(
video_widevine::DrmDeviceCertificate_CertificateType_SERVICE));
return DEVICE_CERTIFICATE_ERROR_3;
}
@@ -183,7 +188,7 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
public_key_.reset(new RsaPublicKey);
if (!public_key_->Init(service_cert.public_key())) {
public_key_.reset();
LOGE("Failed to load service certificate public key.");
LOGE("Failed to load service certificate public key");
return DEVICE_CERTIFICATE_ERROR_2;
}
@@ -198,8 +203,8 @@ CdmResponseType ServiceCertificate::Init(const std::string& certificate) {
CdmResponseType ServiceCertificate::VerifySignedMessage(
const std::string& message, const std::string& signature) {
if (public_key_.get() == NULL) {
LOGE("Service certificate not set.");
if (public_key_.get() == nullptr) {
LOGE("Service certificate not set");
return DEVICE_CERTIFICATE_ERROR_4;
}
@@ -211,8 +216,8 @@ CdmResponseType ServiceCertificate::VerifySignedMessage(
CdmResponseType ServiceCertificate::EncryptRsaOaep(const std::string& plaintext,
std::string* ciphertext) {
if (public_key_.get() == NULL) {
LOGE("Service certificate not set.");
if (public_key_.get() == nullptr) {
LOGE("Service certificate not set");
return DEVICE_CERTIFICATE_ERROR_4;
}
@@ -235,18 +240,18 @@ CdmResponseType ServiceCertificate::EncryptClientId(
key.size(), reinterpret_cast<uint8_t*>(&key[0]));
if (status != NO_ERROR) {
LOGE("ServiceCertificate::EncryptClientId: GetRandom error: %d", status);
return status == RANDOM_GENERATION_ERROR ? CLIENT_ID_GENERATE_RANDOM_ERROR
: status;
LOGE("GetRandom failed for key: status = %d", static_cast<int>(status));
return (status == RANDOM_GENERATION_ERROR) ? CLIENT_ID_GENERATE_RANDOM_ERROR
: status;
}
status =
crypto_session->GetRandom(iv.size(), reinterpret_cast<uint8_t*>(&iv[0]));
if (status != NO_ERROR) {
LOGE("ServiceCertificate::EncryptClientId: GetRandom error: %d", status);
return status == RANDOM_GENERATION_ERROR ? CLIENT_ID_GENERATE_RANDOM_ERROR
: status;
LOGE("GetRandom failed for IV: status = %d", static_cast<int>(status));
return (status == RANDOM_GENERATION_ERROR) ? CLIENT_ID_GENERATE_RANDOM_ERROR
: status;
}
std::string id, enc_id, enc_key;
clear_client_id->SerializeToString(&id);
@@ -265,8 +270,8 @@ CdmResponseType ServiceCertificate::EncryptClientId(
}
bool ServiceCertificate::GetRequest(CdmKeyMessage* request) {
if (!request) {
LOGE("ServiceCertificate::PrepareRequest: no request parameter provided");
if (request == nullptr) {
LOGE("Output parameter |request| not provided");
return false;
}
SignedMessage message;
@@ -278,34 +283,35 @@ bool ServiceCertificate::GetRequest(CdmKeyMessage* request) {
CdmResponseType ServiceCertificate::ParseResponse(const std::string& response,
std::string* certificate) {
if (response.empty()) {
LOGE("ServiceCertificate::ParseResponse: empty response");
LOGE("Response is empty");
return EMPTY_RESPONSE_ERROR_1;
}
if (!certificate) {
LOGE("ServiceCertificate::ParseResponse: null return parameter");
if (certificate == nullptr) {
LOGE("Output parameter |certificate| not provided");
return INVALID_PARAMETERS_ENG_24;
}
SignedMessage signed_response;
if (!signed_response.ParseFromString(response)) {
LOGE("ServiceCertificate::ParseResponse: cannot parse response");
LOGE("Failed to parse signed response");
return PARSE_RESPONSE_ERROR_1;
}
if (signed_response.type() == SignedMessage::ERROR_RESPONSE) {
LicenseError license_error;
if (!license_error.ParseFromString(signed_response.msg())) {
LOGE("ServiceCertificate::ParseResponse: cannot parse license error");
LOGE("Failed to parse license error");
return PARSE_RESPONSE_ERROR_2;
}
LOGE("ServiceCertificate::ParseResponse: server returned error = %d",
license_error.error_code());
LOGE("Server response contains error: error_code = %d",
static_cast<int>(license_error.error_code()));
return PARSE_RESPONSE_ERROR_3;
}
if (signed_response.type() != SignedMessage::SERVICE_CERTIFICATE) {
LOGE("ServiceCertificate::ParseResponse: response (%d) is wrong type",
signed_response.type());
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;
}