blob: 495841be4258f9a471ee67133572515506dc1fb8 [file] [log] [blame]
David Zeuthenab3e5652019-10-28 13:32:48 -04001/*
2 * Copyright (c) 2019, 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 SYSTEM_SECURITY_CREDENTIAL_STORE_H_
18#define SYSTEM_SECURITY_CREDENTIAL_STORE_H_
19
Tri Vo3ab6f052022-11-22 10:26:16 -080020#include <future>
David Zeuthenab3e5652019-10-28 13:32:48 -040021#include <string>
22#include <vector>
23
David Zeuthena6f9fba2020-02-11 22:08:27 -050024#include <android/hardware/identity/IIdentityCredentialStore.h>
David Zeuthenab3e5652019-10-28 13:32:48 -040025#include <android/security/identity/BnCredentialStore.h>
Seth Moore81db3782022-01-18 15:58:47 -080026#include <android/security/remoteprovisioning/IRemotelyProvisionedKeyPool.h>
Tri Vo3ab6f052022-11-22 10:26:16 -080027#include <android/security/rkp/IRemoteProvisioning.h>
28
29#include "RemotelyProvisionedKey.h"
David Zeuthenab3e5652019-10-28 13:32:48 -040030
31namespace android {
32namespace security {
33namespace identity {
34
35using ::android::sp;
36using ::android::binder::Status;
David Zeuthen045a2c82021-09-11 13:52:17 -040037using ::std::optional;
David Zeuthenab3e5652019-10-28 13:32:48 -040038using ::std::string;
39using ::std::unique_ptr;
40using ::std::vector;
41
David Zeuthena6f9fba2020-02-11 22:08:27 -050042using ::android::hardware::identity::HardwareInformation;
43using ::android::hardware::identity::IIdentityCredentialStore;
David Zeuthen045a2c82021-09-11 13:52:17 -040044using ::android::hardware::identity::IPresentationSession;
Seth Moore81db3782022-01-18 15:58:47 -080045using ::android::hardware::identity::IWritableIdentityCredential;
Tri Vo3ab6f052022-11-22 10:26:16 -080046using ::android::hardware::security::keymint::IRemotelyProvisionedComponent;
Seth Moore81db3782022-01-18 15:58:47 -080047using ::android::security::remoteprovisioning::IRemotelyProvisionedKeyPool;
David Zeuthenab3e5652019-10-28 13:32:48 -040048
49class CredentialStore : public BnCredentialStore {
50 public:
51 CredentialStore(const string& dataPath, sp<IIdentityCredentialStore> hal);
52 ~CredentialStore();
53
54 bool init();
55
David Zeuthen045a2c82021-09-11 13:52:17 -040056 // Used by both getCredentialByName() and Session::getCredential()
57 //
58 Status getCredentialCommon(const string& credentialName, int32_t cipherSuite,
59 sp<IPresentationSession> halSessionBinder,
60 sp<ICredential>* _aidl_return);
61
David Zeuthenab3e5652019-10-28 13:32:48 -040062 // ICredentialStore overrides
63 Status getSecurityHardwareInfo(SecurityHardwareInfoParcel* _aidl_return) override;
64
65 Status createCredential(const string& credentialName, const string& docType,
66 sp<IWritableCredential>* _aidl_return) override;
67
68 Status getCredentialByName(const string& credentialName, int32_t cipherSuite,
69 sp<ICredential>* _aidl_return) override;
70
David Zeuthen045a2c82021-09-11 13:52:17 -040071 Status createPresentationSession(int32_t cipherSuite, sp<ISession>* _aidl_return) override;
72
David Zeuthenab3e5652019-10-28 13:32:48 -040073 private:
Seth Moore81db3782022-01-18 15:58:47 -080074 Status setRemotelyProvisionedAttestationKey(IWritableIdentityCredential* halWritableCredential);
75
David Zeuthenab3e5652019-10-28 13:32:48 -040076 string dataPath_;
77
78 sp<IIdentityCredentialStore> hal_;
David Zeuthen472e6c82020-10-16 11:50:13 -040079 int halApiVersion_;
David Zeuthenab3e5652019-10-28 13:32:48 -040080
David Zeuthena6f9fba2020-02-11 22:08:27 -050081 HardwareInformation hwInfo_;
Tri Vo3ab6f052022-11-22 10:26:16 -080082
83 bool useRkpd_;
84 sp<IRemotelyProvisionedComponent> rpc_;
85 sp<IRemotelyProvisionedKeyPool> keyPool_;
86 std::future<std::optional<RemotelyProvisionedKey>> rpcKeyFuture_;
David Zeuthenab3e5652019-10-28 13:32:48 -040087};
88
89} // namespace identity
90} // namespace security
91} // namespace android
92
93#endif // SYSTEM_SECURITY_CREDENTIAL_STORE_H_