Factory tool implements Widevine IRPC HAL v3
Implement IRPC HAL v3 interfaces for extracting device registration CSR. The new interface calls OEMCrypto_GetDeviceInformation() and OEMCrypto_GetSignedCsrPayload() and then constructs the CSR. Also added all mandatory fields of device info in the request. Test: Run extraction tool on Pixel 7 and upload CSR Test: Verified Widevine remote provisioning Bug: 268246995 Change-Id: I24097ba32c7a105266071c1341c938b5874b38d8
This commit is contained in:
@@ -49,7 +49,7 @@ bool WidevineProvisioner::GenerateCertificateRequest(
|
||||
std::vector<uint8_t> bcc;
|
||||
OEMCryptoResult result = crypto_interface_->GetBcc(bcc);
|
||||
if (result != OEMCrypto_SUCCESS) {
|
||||
LOGE("Failed to get BCC.");
|
||||
LOGE("Failed to get BCC, result = %d", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ bool WidevineProvisioner::GenerateCertificateRequest(
|
||||
|
||||
bool WidevineProvisioner::TryAddVerifiedDeviceInfo(
|
||||
cppbor::Map& device_info_map) {
|
||||
VerifiedDeviceInfo verified_device_info;
|
||||
std::vector<uint8_t> verified_device_info;
|
||||
OEMCryptoResult result =
|
||||
crypto_interface_->GetVerifiedDeviceInformation(verified_device_info);
|
||||
if (result == OEMCrypto_ERROR_NOT_IMPLEMENTED) {
|
||||
@@ -73,30 +73,22 @@ bool WidevineProvisioner::TryAddVerifiedDeviceInfo(
|
||||
return true;
|
||||
}
|
||||
if (result != OEMCrypto_SUCCESS) {
|
||||
LOGE("Failed to get verified device information.");
|
||||
LOGE("Failed to get verified device information, result = %d", result);
|
||||
return false;
|
||||
}
|
||||
auto [parsed, _, err] = cppbor::parse(
|
||||
reinterpret_cast<const uint8_t*>(verified_device_info.device_info.data()),
|
||||
verified_device_info.device_info.size());
|
||||
reinterpret_cast<const uint8_t*>(verified_device_info.data()),
|
||||
verified_device_info.size());
|
||||
if (!parsed || !parsed->asMap()) {
|
||||
LOGE("Failed to parse the verified device info cbor: %s", err.c_str());
|
||||
return false;
|
||||
}
|
||||
const cppbor::Map* verified_device_info_map = parsed->asMap();
|
||||
auto& make = verified_device_info_map->get("manufacturer");
|
||||
if (make && make->asTstr() && make->asTstr()->value() != "") {
|
||||
device_info_map.add("manufacturer", make->asTstr()->value());
|
||||
for (size_t i = 0; i < verified_device_info_map->size(); i++) {
|
||||
auto& [key_item, value_item] = (*verified_device_info_map)[i];
|
||||
LOGI("Found device info %s", key_item->asTstr()->value().data());
|
||||
device_info_map.add(key_item->clone(), value_item->clone());
|
||||
}
|
||||
auto& model = verified_device_info_map->get("model");
|
||||
if (model && model->asTstr() && model->asTstr()->value() != "") {
|
||||
device_info_map.add("model", model->asTstr()->value());
|
||||
}
|
||||
auto& fused = verified_device_info_map->get("fused");
|
||||
if (fused && fused->asUint()) {
|
||||
device_info_map.add("fused", fused->asUint()->value());
|
||||
}
|
||||
device_info_map.canonicalize();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -168,8 +160,6 @@ bool WidevineProvisioner::GetDeviceInfoCommon(cppbor::Map& device_info_map) {
|
||||
}
|
||||
device_info_map.add(cppbor::Tstr("oemcrypto_build_info"),
|
||||
cppbor::Tstr(oemcrypto_build_info));
|
||||
|
||||
device_info_map.canonicalize();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -177,7 +167,6 @@ bool WidevineProvisioner::GetDeviceInfo(std::vector<uint8_t>& device_info) {
|
||||
auto device_info_map = cppbor::Map();
|
||||
device_info_map.add(cppbor::Tstr("type"), cppbor::Tstr("widevine"));
|
||||
device_info_map.add(cppbor::Tstr("version"), cppbor::Uint(2));
|
||||
device_info_map.canonicalize();
|
||||
if (!GetDeviceInfoCommon(device_info_map)) return false;
|
||||
device_info = device_info_map.canonicalize().encode();
|
||||
return true;
|
||||
@@ -309,6 +298,50 @@ cppbor::Array WidevineProvisioner::BuildCertReqRecipients(
|
||||
.add(cppbor::Null())); // No ciphertext
|
||||
}
|
||||
|
||||
bool WidevineProvisioner::GetDeviceInfoV2(cppbor::Map& device_info_map) {
|
||||
if (!GetDeviceInfoCommon(device_info_map)) return false;
|
||||
device_info_map.canonicalize();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WidevineProvisioner::GenerateCertificateRequestV2(
|
||||
const std::vector<uint8_t>& challenge, std::vector<uint8_t>* csr) {
|
||||
if (csr == nullptr) {
|
||||
LOGE("CSR is null.");
|
||||
return false;
|
||||
}
|
||||
// Prepare BCC
|
||||
std::vector<uint8_t> bcc;
|
||||
OEMCryptoResult result = crypto_interface_->GetBcc(bcc);
|
||||
if (result != OEMCrypto_SUCCESS) {
|
||||
LOGE("Failed to get BCC, result = %d", result);
|
||||
return false;
|
||||
}
|
||||
// Prepare device info
|
||||
auto device_info_map = cppbor::Map();
|
||||
if (!GetDeviceInfoV2(device_info_map)) {
|
||||
LOGE("Failed to get device_info.");
|
||||
return false;
|
||||
}
|
||||
// Prepare signed CSR payload
|
||||
auto device_info = device_info_map.encode();
|
||||
std::vector<uint8_t> signed_csr_payload;
|
||||
result = crypto_interface_->GetSignedCsrPayload(challenge, device_info,
|
||||
signed_csr_payload);
|
||||
if (result != OEMCrypto_SUCCESS) {
|
||||
LOGE("Failed to get the signed CSR payload, result = %d", result);
|
||||
return false;
|
||||
}
|
||||
// https://source.corp.google.com/android-internal/hardware/interfaces/security/rkp/aidl/android/hardware/security/keymint/IRemotelyProvisionedComponent.aidl
|
||||
*csr = cppbor::Array()
|
||||
.add(1 /* version */)
|
||||
.add(cppbor::Map() /* UdsCerts */)
|
||||
.add(cppbor::EncodedItem(std::move(bcc)))
|
||||
.add(cppbor::EncodedItem(std::move(signed_csr_payload)))
|
||||
.encode();
|
||||
return true;
|
||||
}
|
||||
|
||||
void WidevineProvisioner::InitializeCryptoInterface() {
|
||||
std::string oemcrypto_path;
|
||||
if (!wvcdm::Properties::GetOEMCryptoPath(&oemcrypto_path)) {
|
||||
|
||||
Reference in New Issue
Block a user