blob: 9f4e303ac42e7cdca29fd00381887a67b41c4370 [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.
54 Return<void> getAttestationCertificate(const hidl_vec<uint8_t>& attestationChallenge,
55 getAttestationCertificate_cb _hidl_cb) override;
56
57 Return<void> startPersonalization(uint16_t accessControlProfileCount,
58 const hidl_vec<uint16_t>& entryCounts,
59 startPersonalization_cb _hidl_cb) override;
60
61 Return<void> addAccessControlProfile(uint16_t id, const hidl_vec<uint8_t>& readerCertificate,
62 bool userAuthenticationRequired, uint64_t timeoutMillis,
63 uint64_t secureUserId,
64 addAccessControlProfile_cb _hidl_cb) override;
65
66 Return<void> beginAddEntry(const hidl_vec<uint16_t>& accessControlProfileIds,
67 const hidl_string& nameSpace, const hidl_string& name,
68 uint32_t entrySize, beginAddEntry_cb _hidl_cb) override;
69
70 Return<void> addEntryValue(const hidl_vec<uint8_t>& content,
71 addEntryValue_cb _hidl_cb) override;
72
73 Return<void> finishAddingEntries(finishAddingEntries_cb _hidl_cb) override;
74
75 private:
76 string docType_;
77 bool testCredential_;
78
79 // These are set in initialize().
80 vector<uint8_t> storageKey_;
81 vector<uint8_t> credentialPrivKey_;
82 vector<uint8_t> credentialPubKey_;
83
84 // These fields are initialized during startPersonalization()
85 size_t numAccessControlProfileRemaining_;
86 vector<uint16_t> remainingEntryCounts_;
87 cppbor::Array signedDataAccessControlProfiles_;
88 cppbor::Map signedDataNamespaces_;
89 cppbor::Array signedDataCurrentNamespace_;
90
91 // These fields are initialized during beginAddEntry()
92 size_t entryRemainingBytes_;
93 vector<uint8_t> entryAdditionalData_;
94 string entryNameSpace_;
95 string entryName_;
96 vector<uint16_t> entryAccessControlProfileIds_;
97 vector<uint8_t> entryBytes_;
98};
99
100} // namespace implementation
101} // namespace identity
102} // namespace hardware
103} // namespace android
104
105#endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H