blob: b1deb1675017cfc97777ee8438cdefa50e4df4b9 [file] [log] [blame]
David Zeuthenc75ac312019-10-28 13:16:45 -04001/*
2 * Copyright 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 ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H
18#define ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H
19
20#include <android/hardware/identity/1.0/IWritableIdentityCredential.h>
21
22#include <android/hardware/identity/support/IdentityCredentialSupport.h>
23
24#include <cppbor.h>
25
26namespace android {
27namespace hardware {
28namespace identity {
29namespace implementation {
30
31using ::std::string;
32using ::std::vector;
33
34using ::android::hardware::hidl_string;
35using ::android::hardware::hidl_vec;
36using ::android::hardware::Return;
37using ::android::hardware::Void;
38using ::android::hardware::identity::V1_0::IWritableIdentityCredential;
39using ::android::hardware::identity::V1_0::Result;
40using ::android::hardware::identity::V1_0::ResultCode;
41using ::android::hardware::identity::V1_0::SecureAccessControlProfile;
42
43class WritableIdentityCredential : public IWritableIdentityCredential {
44 public:
45 WritableIdentityCredential(const hidl_string& docType, bool testCredential)
46 : docType_(docType), testCredential_(testCredential) {}
47
48 // Creates the Credential Key. Returns false on failure. Must be called
49 // right after construction.
50 bool initialize();
51
52 // Methods from ::android::hardware::identity::IWritableIdentityCredential
53 // follow.
David Zeuthen87cb07b2020-01-30 16:15:50 -050054 Return<void> getAttestationCertificate(const hidl_vec<uint8_t>& attestationApplicationId,
55 const hidl_vec<uint8_t>& attestationChallenge,
David Zeuthenc75ac312019-10-28 13:16:45 -040056 getAttestationCertificate_cb _hidl_cb) override;
57
58 Return<void> startPersonalization(uint16_t accessControlProfileCount,
59 const hidl_vec<uint16_t>& entryCounts,
60 startPersonalization_cb _hidl_cb) override;
61
62 Return<void> addAccessControlProfile(uint16_t id, const hidl_vec<uint8_t>& readerCertificate,
63 bool userAuthenticationRequired, uint64_t timeoutMillis,
64 uint64_t secureUserId,
65 addAccessControlProfile_cb _hidl_cb) override;
66
67 Return<void> beginAddEntry(const hidl_vec<uint16_t>& accessControlProfileIds,
68 const hidl_string& nameSpace, const hidl_string& name,
69 uint32_t entrySize, beginAddEntry_cb _hidl_cb) override;
70
71 Return<void> addEntryValue(const hidl_vec<uint8_t>& content,
72 addEntryValue_cb _hidl_cb) override;
73
74 Return<void> finishAddingEntries(finishAddingEntries_cb _hidl_cb) override;
75
76 private:
77 string docType_;
78 bool testCredential_;
79
80 // These are set in initialize().
81 vector<uint8_t> storageKey_;
82 vector<uint8_t> credentialPrivKey_;
83 vector<uint8_t> credentialPubKey_;
84
85 // These fields are initialized during startPersonalization()
86 size_t numAccessControlProfileRemaining_;
87 vector<uint16_t> remainingEntryCounts_;
88 cppbor::Array signedDataAccessControlProfiles_;
89 cppbor::Map signedDataNamespaces_;
90 cppbor::Array signedDataCurrentNamespace_;
91
92 // These fields are initialized during beginAddEntry()
93 size_t entryRemainingBytes_;
94 vector<uint8_t> entryAdditionalData_;
95 string entryNameSpace_;
96 string entryName_;
97 vector<uint16_t> entryAccessControlProfileIds_;
98 vector<uint8_t> entryBytes_;
99};
100
101} // namespace implementation
102} // namespace identity
103} // namespace hardware
104} // namespace android
105
106#endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H