55 lines
2.1 KiB
C++
55 lines
2.1 KiB
C++
// 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_
|