• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/cppcose/cppcose.h>
27 
28 namespace keymaster {
29 
30 class RemoteProvisioningContext {
31   public:
RemoteProvisioningContext()32     RemoteProvisioningContext() {}
~RemoteProvisioningContext()33     virtual ~RemoteProvisioningContext(){};
34     virtual std::vector<uint8_t> DeriveBytesFromHbk(const std::string& context,
35                                                     size_t numBytes) const = 0;
36     virtual std::unique_ptr<cppbor::Map> CreateDeviceInfo() const = 0;
37     virtual cppcose::ErrMsgOr<std::vector<uint8_t>>
38     BuildProtectedDataPayload(bool testMode,                       //
39                               const std::vector<uint8_t>& macKey,  //
40                               const std::vector<uint8_t>& aad) const = 0;
41     // Generate an HMAC-SHA256 over the given input. This is used to verify a given
42     // input hasn't changed across multiple calls to the remote provisioning HAL.
43     virtual std::optional<cppcose::HmacSha256>
44     GenerateHmacSha256(const cppcose::bytevec& input) const = 0;
45 
46   private:
47     // Uncopyable.
48     RemoteProvisioningContext(const RemoteProvisioningContext&);
49     void operator=(const RemoteProvisioningContext&);
50 };
51 
52 }  // namespace keymaster
53