1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <array> 20 #include <optional> 21 #include <string> 22 #include <tuple> 23 #include <vector> 24 25 #include <cppbor.h> 26 #include <keymaster/android_keymaster_messages.h> 27 #include <keymaster/cppcose/cppcose.h> 28 29 namespace keymaster { 30 31 class RemoteProvisioningContext { 32 public: RemoteProvisioningContext()33 RemoteProvisioningContext() {} ~RemoteProvisioningContext()34 virtual ~RemoteProvisioningContext(){}; 35 virtual std::vector<uint8_t> DeriveBytesFromHbk(const std::string& context, 36 size_t numBytes) const = 0; 37 virtual std::unique_ptr<cppbor::Map> CreateDeviceInfo(uint32_t csrVersion) const = 0; 38 virtual cppcose::ErrMsgOr<std::vector<uint8_t>> 39 BuildProtectedDataPayload(bool testMode, // 40 const std::vector<uint8_t>& macKey, // 41 const std::vector<uint8_t>& aad) const = 0; 42 // Generate an HMAC-SHA256 over the given input. This is used to verify a given 43 // input hasn't changed across multiple calls to the remote provisioning HAL. 44 virtual std::optional<cppcose::HmacSha256> 45 GenerateHmacSha256(const cppcose::bytevec& input) const = 0; 46 virtual void GetHwInfo(GetHwInfoResponse* hwInfo) const = 0; 47 virtual cppcose::ErrMsgOr<cppbor::Array> BuildCsr(const std::vector<uint8_t>& challenge, 48 cppbor::Array keysToSign) const = 0; 49 50 private: 51 // Uncopyable. 52 RemoteProvisioningContext(const RemoteProvisioningContext&); 53 void operator=(const RemoteProvisioningContext&); 54 }; 55 56 } // namespace keymaster 57