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