blob: 838b9564bda4a3c3bac320d5b4f1d5604d9568ba [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_WRITABLE_CREDENTIAL_H_
18#define SYSTEM_SECURITY_WRITABLE_CREDENTIAL_H_
19
20#include <string>
21#include <vector>
22
23#include <android/security/identity/BnWritableCredential.h>
24
David Zeuthena6f9fba2020-02-11 22:08:27 -050025#include <android/hardware/identity/IIdentityCredentialStore.h>
David Zeuthenab3e5652019-10-28 13:32:48 -040026
David Zeuthen27407a52021-03-04 16:32:43 -050027#include "Credential.h"
28
David Zeuthenab3e5652019-10-28 13:32:48 -040029namespace android {
30namespace security {
31namespace identity {
32
33using ::android::binder::Status;
David Zeuthen472e6c82020-10-16 11:50:13 -040034using ::android::hardware::identity::HardwareInformation;
David Zeuthena6f9fba2020-02-11 22:08:27 -050035using ::android::hardware::identity::IWritableIdentityCredential;
David Zeuthenab3e5652019-10-28 13:32:48 -040036using ::std::string;
37using ::std::vector;
38
39class WritableCredential : public BnWritableCredential {
40 public:
41 WritableCredential(const string& dataPath, const string& credentialName, const string& docType,
David Zeuthen472e6c82020-10-16 11:50:13 -040042 bool isUpdate, HardwareInformation hwInfo,
David Zeuthen27407a52021-03-04 16:32:43 -050043 sp<IWritableIdentityCredential> halBinder);
David Zeuthenab3e5652019-10-28 13:32:48 -040044 ~WritableCredential();
45
David Zeuthen472e6c82020-10-16 11:50:13 -040046 // Used when updating a credential
47 void setAttestationCertificate(const vector<uint8_t>& attestationCertificate);
48 void setAvailableAuthenticationKeys(int keyCount, int maxUsesPerKey);
David Zeuthen27407a52021-03-04 16:32:43 -050049
50 // Used by Credential::update()
51 void setCredentialToReloadWhenUpdated(sp<Credential> credential);
David Zeuthen472e6c82020-10-16 11:50:13 -040052
David Zeuthenab3e5652019-10-28 13:32:48 -040053 // IWritableCredential overrides
54 Status getCredentialKeyCertificateChain(const vector<uint8_t>& challenge,
55 vector<uint8_t>* _aidl_return) override;
56
57 Status personalize(const vector<AccessControlProfileParcel>& accessControlProfiles,
58 const vector<EntryNamespaceParcel>& entryNamespaces, int64_t secureUserId,
59 vector<uint8_t>* _aidl_return) override;
60
61 private:
62 string dataPath_;
63 string credentialName_;
David Zeuthene2a78a42020-04-27 13:34:38 -040064 string docType_;
David Zeuthen472e6c82020-10-16 11:50:13 -040065 bool isUpdate_;
66 HardwareInformation hwInfo_;
David Zeuthenab3e5652019-10-28 13:32:48 -040067 sp<IWritableIdentityCredential> halBinder_;
David Zeuthen472e6c82020-10-16 11:50:13 -040068
David Zeuthenab3e5652019-10-28 13:32:48 -040069 vector<uint8_t> attestationCertificate_;
David Zeuthen472e6c82020-10-16 11:50:13 -040070 int keyCount_ = 0;
71 int maxUsesPerKey_ = 1;
72
David Zeuthen27407a52021-03-04 16:32:43 -050073 sp<Credential> credentialToReloadWhenUpdated_;
David Zeuthenab3e5652019-10-28 13:32:48 -040074
David Zeuthene2a78a42020-04-27 13:34:38 -040075 ssize_t calcExpectedProofOfProvisioningSize(
76 const vector<AccessControlProfileParcel>& accessControlProfiles,
77 const vector<EntryNamespaceParcel>& entryNamespaces);
78
David Zeuthenab3e5652019-10-28 13:32:48 -040079 Status ensureAttestationCertificateExists(const vector<uint8_t>& challenge);
80};
81
82} // namespace identity
83} // namespace security
84} // namespace android
85
86#endif // SYSTEM_SECURITY_WRITABLE_CREDENTIAL_H_