legacy_keymaster_device_wrapper.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifndef LEGACY_KEYMASTER_DEVICE_WRAPPER_H_
  18. #define LEGACY_KEYMASTER_DEVICE_WRAPPER_H_
  19. #include <android/hardware/keymaster/3.0/IKeymasterDevice.h>
  20. #include <hidl/Status.h>
  21. #include <hidl/MQDescriptor.h>
  22. struct keymaster2_device;
  23. typedef struct keymaster2_device keymaster2_device_t;
  24. namespace android {
  25. namespace keystore {
  26. using ::android::hardware::keymaster::V3_0::ErrorCode;
  27. using ::android::hardware::keymaster::V3_0::IKeymasterDevice;
  28. using ::android::hardware::keymaster::V3_0::KeyCharacteristics;
  29. using ::android::hardware::keymaster::V3_0::KeyFormat;
  30. using ::android::hardware::keymaster::V3_0::KeyParameter;
  31. using ::android::hardware::keymaster::V3_0::KeyPurpose;
  32. using ::android::hardware::keymaster::V3_0::Tag;
  33. using ::android::hardware::Return;
  34. using ::android::hardware::Void;
  35. using ::android::hardware::hidl_vec;
  36. using ::android::hardware::hidl_string;
  37. using ::android::sp;
  38. class LegacyKeymasterDeviceWrapper : public IKeymasterDevice {
  39. public:
  40. explicit LegacyKeymasterDeviceWrapper(keymaster2_device_t* dev);
  41. virtual ~LegacyKeymasterDeviceWrapper();
  42. // Methods from ::android::hardware::keymaster::V3_0::IKeymasterDevice follow.
  43. Return<void> getHardwareFeatures(getHardwareFeatures_cb _hidl_cb);
  44. Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override;
  45. Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
  46. generateKey_cb _hidl_cb) override;
  47. Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
  48. const hidl_vec<uint8_t>& clientId,
  49. const hidl_vec<uint8_t>& appData,
  50. getKeyCharacteristics_cb _hidl_cb) override;
  51. Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
  52. const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override;
  53. Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob,
  54. const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData,
  55. exportKey_cb _hidl_cb) override;
  56. Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
  57. const hidl_vec<KeyParameter>& attestParams,
  58. attestKey_cb _hidl_cb) override;
  59. Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
  60. const hidl_vec<KeyParameter>& upgradeParams,
  61. upgradeKey_cb _hidl_cb) override;
  62. Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override;
  63. Return<ErrorCode> deleteAllKeys() override;
  64. Return<ErrorCode> destroyAttestationIds() override;
  65. Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
  66. const hidl_vec<KeyParameter>& inParams, begin_cb _hidl_cb) override;
  67. Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
  68. const hidl_vec<uint8_t>& input, update_cb _hidl_cb) override;
  69. Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
  70. const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature,
  71. finish_cb _hidl_cb) override;
  72. Return<ErrorCode> abort(uint64_t operationHandle) override;
  73. private:
  74. keymaster2_device_t* keymaster_device_;
  75. };
  76. sp<IKeymasterDevice> makeSoftwareKeymasterDevice();
  77. } // namespace keystore
  78. } // namespace android
  79. #endif // LEGACY_KEYMASTER_DEVICE_WRAPPER_H_