1 /*
2  * Copyright (C) 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  **
18  ** The original Work has been changed by NXP.
19  **
20  ** Licensed under the Apache License, Version 2.0 (the "License");
21  ** you may not use this file except in compliance with the License.
22  ** You may obtain a copy of the License at
23  **
24  ** http://www.apache.org/licenses/LICENSE-2.0
25  **
26  ** Unless required by applicable law or agreed to in writing, software
27  ** distributed under the License is distributed on an "AS IS" BASIS,
28  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  ** See the License for the specific language governing permissions and
30  ** limitations under the License.
31  **
32  ** Copyright 2023 NXP
33  **
34  *********************************************************************************/
35 
36 #pragma once
37 
38 #include "EseTransportUtils.h"
39 #include "IntervalTimer.h"
40 #include "OmapiTransport.h"
41 #include <aidl/android/hardware/authsecret/BnAuthSecret.h>
42 
43 namespace aidl {
44 namespace android {
45 namespace hardware {
46 namespace authsecret {
47 
48 class AuthSecret : public BnAuthSecret {
49 public:
50   /**
51    * \brief Constructor. Invoked during service start.
52    */
AuthSecret()53   explicit AuthSecret() { clearAuthApprovedStatus(); }
54 
55   /**
56    * \brief Function to clear the Auth Approved status in IAR applet
57    *
58    * \retval None
59    *
60    */
61   void clearAuthApprovedStatus();
62 
63   // Methods from ::android::hardware::authsecret::IAuthSecret follow.
64 
65   /**
66    * \brief Sends the secret blob to IAR applet
67    *
68    * \retval None
69    *
70    * \param[in_secret]  Secret Blob.
71    */
72   ::ndk::ScopedAStatus
73   setPrimaryUserCredential(const std::vector<uint8_t> &in_secret) override;
74 
75 private:
76   IntervalTimer mAuthClearTimer;
77 
78   /**
79    * \brief Function to convert SW byte array to integer
80    *
81    * \retval SW status in integer format
82    *
83    * \param[inputData] Response APDU data.
84    */
getApduStatus(std::vector<uint8_t> & inputData)85   inline uint16_t getApduStatus(std::vector<uint8_t> &inputData) {
86     // Last two bytes are the status SW0SW1
87     uint8_t SW0 = inputData.at(inputData.size() - 2);
88     uint8_t SW1 = inputData.at(inputData.size() - 1);
89     return (SW0 << 8 | SW1);
90   }
91 };
92 
93 } // namespace authsecret
94 } // namespace hardware
95 } // namespace android
96 } // aidl
97