Home | History | Annotate | Download | only in keystore
      1 /*
      2  **
      3  ** Copyright 2016, The Android Open Source Project
      4  **
      5  ** Licensed under the Apache License, Version 2.0 (the "License");
      6  ** you may not use this file except in compliance with the License.
      7  ** You may obtain a copy of the License at
      8  **
      9  **     http://www.apache.org/licenses/LICENSE-2.0
     10  **
     11  ** Unless required by applicable law or agreed to in writing, software
     12  ** distributed under the License is distributed on an "AS IS" BASIS,
     13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  ** See the License for the specific language governing permissions and
     15  ** limitations under the License.
     16  */
     17 
     18 #ifndef LEGACY_KEYMASTER_DEVICE_WRAPPER_H_
     19 #define LEGACY_KEYMASTER_DEVICE_WRAPPER_H_
     20 
     21 #include <android/hardware/keymaster/3.0/IKeymasterDevice.h>
     22 #include <hidl/Status.h>
     23 #include <hidl/MQDescriptor.h>
     24 
     25 struct keymaster2_device;
     26 typedef struct keymaster2_device keymaster2_device_t;
     27 
     28 namespace android {
     29 namespace keystore {
     30 
     31 using ::android::hardware::keymaster::V3_0::ErrorCode;
     32 using ::android::hardware::keymaster::V3_0::IKeymasterDevice;
     33 using ::android::hardware::keymaster::V3_0::KeyCharacteristics;
     34 using ::android::hardware::keymaster::V3_0::KeyFormat;
     35 using ::android::hardware::keymaster::V3_0::KeyParameter;
     36 using ::android::hardware::keymaster::V3_0::KeyPurpose;
     37 using ::android::hardware::keymaster::V3_0::Tag;
     38 using ::android::hardware::Return;
     39 using ::android::hardware::Void;
     40 using ::android::hardware::hidl_vec;
     41 using ::android::hardware::hidl_string;
     42 using ::android::sp;
     43 
     44 class LegacyKeymasterDeviceWrapper : public IKeymasterDevice {
     45   public:
     46     LegacyKeymasterDeviceWrapper(keymaster2_device_t* dev);
     47     virtual ~LegacyKeymasterDeviceWrapper();
     48 
     49     // Methods from ::android::hardware::keymaster::V3_0::IKeymasterDevice follow.
     50     Return<void> getHardwareFeatures(getHardwareFeatures_cb _hidl_cb);
     51     Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override;
     52     Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
     53                              generateKey_cb _hidl_cb) override;
     54     Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
     55                                        const hidl_vec<uint8_t>& clientId,
     56                                        const hidl_vec<uint8_t>& appData,
     57                                        getKeyCharacteristics_cb _hidl_cb) override;
     58     Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
     59                            const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override;
     60     Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob,
     61                            const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData,
     62                            exportKey_cb _hidl_cb) override;
     63     Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
     64                            const hidl_vec<KeyParameter>& attestParams,
     65                            attestKey_cb _hidl_cb) override;
     66     Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
     67                             const hidl_vec<KeyParameter>& upgradeParams,
     68                             upgradeKey_cb _hidl_cb) override;
     69     Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override;
     70     Return<ErrorCode> deleteAllKeys() override;
     71     Return<ErrorCode> destroyAttestationIds() override;
     72     Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
     73                        const hidl_vec<KeyParameter>& inParams, begin_cb _hidl_cb) override;
     74     Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
     75                         const hidl_vec<uint8_t>& input, update_cb _hidl_cb) override;
     76     Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
     77                         const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature,
     78                         finish_cb _hidl_cb) override;
     79     Return<ErrorCode> abort(uint64_t operationHandle) override;
     80 
     81   private:
     82     keymaster2_device_t* keymaster_device_;
     83 };
     84 
     85 sp<IKeymasterDevice> makeSoftwareKeymasterDevice();
     86 
     87 }  // namespace keystore
     88 }  // namespace android
     89 
     90 #endif  // LEGACY_KEYMASTER_DEVICE_WRAPPER_H_
     91