David Zeuthen | 1eb12b2 | 2021-09-11 13:59:43 -0400 | [diff] [blame^] | 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 | #ifndef ANDROID_HARDWARE_IDENTITY_PRESENTATIONSESSION_H |
| 18 | #define ANDROID_HARDWARE_IDENTITY_PRESENTATIONSESSION_H |
| 19 | |
| 20 | #include <aidl/android/hardware/identity/BnPresentationSession.h> |
| 21 | #include <android/hardware/identity/support/IdentityCredentialSupport.h> |
| 22 | |
| 23 | #include <vector> |
| 24 | |
| 25 | #include <cppbor.h> |
| 26 | |
| 27 | #include "IdentityCredentialStore.h" |
| 28 | #include "SecureHardwareProxy.h" |
| 29 | |
| 30 | namespace aidl::android::hardware::identity { |
| 31 | |
| 32 | using ::aidl::android::hardware::keymaster::HardwareAuthToken; |
| 33 | using ::aidl::android::hardware::keymaster::VerificationToken; |
| 34 | using ::android::sp; |
| 35 | using ::android::hardware::identity::SecureHardwareSessionProxy; |
| 36 | using ::std::vector; |
| 37 | |
| 38 | class PresentationSession : public BnPresentationSession { |
| 39 | public: |
| 40 | PresentationSession(sp<SecureHardwareProxyFactory> hwProxyFactory, |
| 41 | sp<SecureHardwareSessionProxy> hwProxy) |
| 42 | : hwProxyFactory_(std::move(hwProxyFactory)), hwProxy_(std::move(hwProxy)) {} |
| 43 | |
| 44 | virtual ~PresentationSession(); |
| 45 | |
| 46 | // Creates ephemeral key and auth-challenge in TA. Returns a status code from |
| 47 | // IIdentityCredentialStore. Must be called right after construction. |
| 48 | int initialize(); |
| 49 | |
| 50 | uint64_t getSessionId(); |
| 51 | |
| 52 | vector<uint8_t> getSessionTranscript(); |
| 53 | vector<uint8_t> getReaderEphemeralPublicKey(); |
| 54 | |
| 55 | // Methods from IPresentationSession follow. |
| 56 | ndk::ScopedAStatus getEphemeralKeyPair(vector<uint8_t>* outKeyPair) override; |
| 57 | ndk::ScopedAStatus getAuthChallenge(int64_t* outChallenge) override; |
| 58 | ndk::ScopedAStatus setReaderEphemeralPublicKey(const vector<uint8_t>& publicKey) override; |
| 59 | ndk::ScopedAStatus setSessionTranscript(const vector<uint8_t>& sessionTranscript) override; |
| 60 | |
| 61 | ndk::ScopedAStatus getCredential(const vector<uint8_t>& credentialData, |
| 62 | shared_ptr<IIdentityCredential>* outCredential) override; |
| 63 | |
| 64 | private: |
| 65 | // Set by constructor |
| 66 | sp<SecureHardwareProxyFactory> hwProxyFactory_; |
| 67 | sp<SecureHardwareSessionProxy> hwProxy_; |
| 68 | |
| 69 | // Set by initialize() |
| 70 | uint64_t id_; |
| 71 | vector<uint8_t> ephemeralKeyPair_; |
| 72 | uint64_t authChallenge_; |
| 73 | |
| 74 | // Set by setReaderEphemeralPublicKey() |
| 75 | vector<uint8_t> readerPublicKey_; |
| 76 | |
| 77 | // Set by setSessionTranscript() |
| 78 | vector<uint8_t> sessionTranscript_; |
| 79 | }; |
| 80 | |
| 81 | } // namespace aidl::android::hardware::identity |
| 82 | |
| 83 | #endif // ANDROID_HARDWARE_IDENTITY_PRESENTATIONSESSION_H |