1 /*
2  * Copyright 2020, 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 <aidl/android/hardware/security/keymint/BnKeyMintOperation.h>
20 #include <aidl/android/hardware/security/secureclock/ISecureClock.h>
21 
22 #include <hardware/keymaster_defs.h>
23 
24 #include "guest/hals/keymint/remote/remote_keymaster.h"
25 
26 namespace keymaster {
27 class AndroidKeymaster;
28 }
29 
30 namespace aidl::android::hardware::security::keymint {
31 
32 using ::ndk::ScopedAStatus;
33 using secureclock::TimeStampToken;
34 using std::optional;
35 using std::shared_ptr;
36 using std::string;
37 using std::vector;
38 
39 class RemoteKeyMintOperation : public BnKeyMintOperation {
40  public:
41   explicit RemoteKeyMintOperation(::keymaster::RemoteKeymaster& implementation,
42                                   keymaster_operation_handle_t opHandle);
43   virtual ~RemoteKeyMintOperation();
44 
45   ScopedAStatus updateAad(
46       const vector<uint8_t>& input,
47       const optional<HardwareAuthToken>& authToken,
48       const optional<TimeStampToken>& timestampToken) override;
49 
50   ScopedAStatus update(const vector<uint8_t>& input,
51                        const optional<HardwareAuthToken>& authToken,
52                        const optional<TimeStampToken>& timestampToken,
53                        vector<uint8_t>* output) override;
54 
55   ScopedAStatus finish(const optional<vector<uint8_t>>& input,        //
56                        const optional<vector<uint8_t>>& signature,    //
57                        const optional<HardwareAuthToken>& authToken,  //
58                        const optional<TimeStampToken>& timestampToken,
59                        const optional<vector<uint8_t>>& confirmationToken,
60                        vector<uint8_t>* output) override;
61 
62   ScopedAStatus abort() override;
63 
64  protected:
65   ::keymaster::RemoteKeymaster& impl_;
66   keymaster_operation_handle_t opHandle_;
67 };
68 
69 }  // namespace aidl::android::hardware::security::keymint
70