Add Device info validator to oemcrypto util and unit tests
Validator that can parse and validate device info Cbor object. This is to support better prov40 unit tests regarding OEMCrypto_GetDeviceInformation() later. Test: opk_ta_p40 Bug: 300304834 Change-Id: Ic260a6626dffcbef5d6b386263839499f83a69db
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Copyright 2023 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
//
|
||||
// Reference implementation utilities of OEMCrypto APIs
|
||||
//
|
||||
#ifndef WVOEC_UTIL_DEVICE_INFO_VALIDATOR_H_
|
||||
#define WVOEC_UTIL_DEVICE_INFO_VALIDATOR_H_
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cbor_validator.h"
|
||||
#include "cppbor.h"
|
||||
|
||||
namespace wvoec {
|
||||
namespace util {
|
||||
// DeviceInfoValidator parses and validates a Cbor struct of DeviceInfo used by
|
||||
// Provisioning 4.0. DeviceInfo definition:
|
||||
// https://source.corp.google.com/h/googleplex-android/platform/superproject/main/+/main:hardware/interfaces/security/rkp/aidl/android/hardware/security/keymint/DeviceInfoV3.cddl
|
||||
class DeviceInfoValidator : public CborValidator {
|
||||
public:
|
||||
explicit DeviceInfoValidator(int version_number)
|
||||
: version_number_(version_number) {}
|
||||
DeviceInfoValidator() = delete;
|
||||
virtual ~DeviceInfoValidator() override = default;
|
||||
DeviceInfoValidator(const DeviceInfoValidator&) = delete;
|
||||
DeviceInfoValidator& operator=(const DeviceInfoValidator&) = delete;
|
||||
|
||||
// Decodes |device_info| and sets |message_status_|.
|
||||
virtual CborMessageStatus Parse(
|
||||
const std::vector<uint8_t>& device_info) override;
|
||||
// Verifies the Cbor struct of a client generated device info.
|
||||
virtual CborMessageStatus Validate() override;
|
||||
// Outputs DeviceInfo in YAML.
|
||||
virtual std::string GetFormattedMessage() const override;
|
||||
|
||||
private:
|
||||
// Checks whether a device info entry with |entry_name| and |major_type|
|
||||
// exists in |device_info| map.
|
||||
void CheckDeviceInfoMapEntry(const cppbor::Map& device_info,
|
||||
cppbor::MajorType major_type,
|
||||
const std::string& entry_name);
|
||||
// Used to generate formatted message.
|
||||
std::stringstream msg_ss_;
|
||||
// Device info version. Validations are done based on the version number.
|
||||
int version_number_;
|
||||
// Saved Cbor-encoded device info.
|
||||
std::vector<uint8_t> device_info_bytes_;
|
||||
};
|
||||
} // namespace util
|
||||
} // namespace wvoec
|
||||
#endif // WVOEC_UTIL_DEVICE_INFO_VALIDATOR_H_
|
||||
Reference in New Issue
Block a user