blob: 4cb174a82c732d8a4af801bca003073d727e356f [file] [log] [blame]
David Zeuthen1eb12b22021-09-11 13:59:43 -04001/*
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
30namespace aidl::android::hardware::identity {
31
32using ::aidl::android::hardware::keymaster::HardwareAuthToken;
33using ::aidl::android::hardware::keymaster::VerificationToken;
34using ::android::sp;
35using ::android::hardware::identity::SecureHardwareSessionProxy;
36using ::std::vector;
37
38class PresentationSession : public BnPresentationSession {
39 public:
40 PresentationSession(sp<SecureHardwareProxyFactory> hwProxyFactory,
Seth Moore1bf823c2022-01-25 23:04:37 +000041 sp<SecureHardwareSessionProxy> hwProxy,
42 HardwareInformation hardwareInformation)
43 : hwProxyFactory_(std::move(hwProxyFactory)),
44 hwProxy_(std::move(hwProxy)),
45 hardwareInformation_(std::move(hardwareInformation)) {}
David Zeuthen1eb12b22021-09-11 13:59:43 -040046
47 virtual ~PresentationSession();
48
49 // Creates ephemeral key and auth-challenge in TA. Returns a status code from
50 // IIdentityCredentialStore. Must be called right after construction.
51 int initialize();
52
53 uint64_t getSessionId();
54
55 vector<uint8_t> getSessionTranscript();
56 vector<uint8_t> getReaderEphemeralPublicKey();
57
58 // Methods from IPresentationSession follow.
59 ndk::ScopedAStatus getEphemeralKeyPair(vector<uint8_t>* outKeyPair) override;
60 ndk::ScopedAStatus getAuthChallenge(int64_t* outChallenge) override;
61 ndk::ScopedAStatus setReaderEphemeralPublicKey(const vector<uint8_t>& publicKey) override;
62 ndk::ScopedAStatus setSessionTranscript(const vector<uint8_t>& sessionTranscript) override;
63
64 ndk::ScopedAStatus getCredential(const vector<uint8_t>& credentialData,
65 shared_ptr<IIdentityCredential>* outCredential) override;
66
67 private:
68 // Set by constructor
69 sp<SecureHardwareProxyFactory> hwProxyFactory_;
70 sp<SecureHardwareSessionProxy> hwProxy_;
Seth Moore1bf823c2022-01-25 23:04:37 +000071 HardwareInformation hardwareInformation_;
David Zeuthen1eb12b22021-09-11 13:59:43 -040072
73 // Set by initialize()
74 uint64_t id_;
75 vector<uint8_t> ephemeralKeyPair_;
76 uint64_t authChallenge_;
77
78 // Set by setReaderEphemeralPublicKey()
79 vector<uint8_t> readerPublicKey_;
80
81 // Set by setSessionTranscript()
82 vector<uint8_t> sessionTranscript_;
83};
84
85} // namespace aidl::android::hardware::identity
86
87#endif // ANDROID_HARDWARE_IDENTITY_PRESENTATIONSESSION_H