blob: 976686ad25da5aa40dc8dad362c68cda1d040a51 [file] [log] [blame]
David Zeuthen81603152020-02-11 22:04:24 -05001/*
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 <aidl/android/hardware/identity/BnWritableIdentityCredential.h>
21#include <android/hardware/identity/support/IdentityCredentialSupport.h>
22
23#include <cppbor.h>
Selene Huang92b61d62020-03-04 02:24:16 -080024#include <set>
David Zeuthen81603152020-02-11 22:04:24 -050025
26namespace aidl::android::hardware::identity {
27
Selene Huang92b61d62020-03-04 02:24:16 -080028using ::std::set;
David Zeuthen81603152020-02-11 22:04:24 -050029using ::std::string;
30using ::std::vector;
31
32class WritableIdentityCredential : public BnWritableIdentityCredential {
33 public:
34 WritableIdentityCredential(const string& docType, bool testCredential)
35 : docType_(docType), testCredential_(testCredential) {}
36
37 // Creates the Credential Key. Returns false on failure. Must be called
38 // right after construction.
39 bool initialize();
40
41 // Methods from IWritableIdentityCredential follow.
Jooyung Han17be89b2020-02-21 21:17:06 +090042 ndk::ScopedAStatus getAttestationCertificate(const vector<uint8_t>& attestationApplicationId,
43 const vector<uint8_t>& attestationChallenge,
David Zeuthen81603152020-02-11 22:04:24 -050044 vector<Certificate>* outCertificateChain) override;
45
46 ndk::ScopedAStatus startPersonalization(int32_t accessControlProfileCount,
47 const vector<int32_t>& entryCounts) override;
48
49 ndk::ScopedAStatus addAccessControlProfile(
50 int32_t id, const Certificate& readerCertificate, bool userAuthenticationRequired,
51 int64_t timeoutMillis, int64_t secureUserId,
52 SecureAccessControlProfile* outSecureAccessControlProfile) override;
53
54 ndk::ScopedAStatus beginAddEntry(const vector<int32_t>& accessControlProfileIds,
55 const string& nameSpace, const string& name,
56 int32_t entrySize) override;
57
Jooyung Han17be89b2020-02-21 21:17:06 +090058 ndk::ScopedAStatus addEntryValue(const vector<uint8_t>& content,
59 vector<uint8_t>* outEncryptedContent) override;
David Zeuthen81603152020-02-11 22:04:24 -050060
61 ndk::ScopedAStatus finishAddingEntries(
Jooyung Han17be89b2020-02-21 21:17:06 +090062 vector<uint8_t>* outCredentialData,
63 vector<uint8_t>* outProofOfProvisioningSignature) override;
David Zeuthen81603152020-02-11 22:04:24 -050064
65 // private:
66 string docType_;
67 bool testCredential_;
68
Selene Huang459cb802020-01-08 22:59:02 -080069 // This is set in initialize().
David Zeuthen81603152020-02-11 22:04:24 -050070 vector<uint8_t> storageKey_;
Selene Huang92b61d62020-03-04 02:24:16 -080071 bool startPersonalizationCalled_;
72 bool firstEntry_;
Selene Huang459cb802020-01-08 22:59:02 -080073
74 // These are set in getAttestationCertificate().
David Zeuthen81603152020-02-11 22:04:24 -050075 vector<uint8_t> credentialPrivKey_;
76 vector<uint8_t> credentialPubKey_;
Selene Huang459cb802020-01-08 22:59:02 -080077 vector<vector<uint8_t>> certificateChain_;
David Zeuthen81603152020-02-11 22:04:24 -050078
79 // These fields are initialized during startPersonalization()
80 size_t numAccessControlProfileRemaining_;
81 vector<int32_t> remainingEntryCounts_;
82 cppbor::Array signedDataAccessControlProfiles_;
83 cppbor::Map signedDataNamespaces_;
84 cppbor::Array signedDataCurrentNamespace_;
85
Selene Huang92b61d62020-03-04 02:24:16 -080086 // This field is initialized in addAccessControlProfile
87 set<int32_t> accessControlProfileIds_;
88
David Zeuthen81603152020-02-11 22:04:24 -050089 // These fields are initialized during beginAddEntry()
90 size_t entryRemainingBytes_;
91 vector<uint8_t> entryAdditionalData_;
92 string entryNameSpace_;
93 string entryName_;
94 vector<int32_t> entryAccessControlProfileIds_;
95 vector<uint8_t> entryBytes_;
Selene Huang92b61d62020-03-04 02:24:16 -080096 set<string> allNameSpaces_;
David Zeuthen81603152020-02-11 22:04:24 -050097};
98
99} // namespace aidl::android::hardware::identity
100
101#endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H