blob: 56458520c1b803699623a139619d14583677b6e4 [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
David Zeuthen28edb102020-04-28 18:54:55 -040046 ndk::ScopedAStatus setExpectedProofOfProvisioningSize(
47 int32_t expectedProofOfProvisioningSize) override;
48
David Zeuthen81603152020-02-11 22:04:24 -050049 ndk::ScopedAStatus startPersonalization(int32_t accessControlProfileCount,
50 const vector<int32_t>& entryCounts) override;
51
52 ndk::ScopedAStatus addAccessControlProfile(
53 int32_t id, const Certificate& readerCertificate, bool userAuthenticationRequired,
54 int64_t timeoutMillis, int64_t secureUserId,
55 SecureAccessControlProfile* outSecureAccessControlProfile) override;
56
57 ndk::ScopedAStatus beginAddEntry(const vector<int32_t>& accessControlProfileIds,
58 const string& nameSpace, const string& name,
59 int32_t entrySize) override;
60
Jooyung Han17be89b2020-02-21 21:17:06 +090061 ndk::ScopedAStatus addEntryValue(const vector<uint8_t>& content,
62 vector<uint8_t>* outEncryptedContent) override;
David Zeuthen81603152020-02-11 22:04:24 -050063
64 ndk::ScopedAStatus finishAddingEntries(
Jooyung Han17be89b2020-02-21 21:17:06 +090065 vector<uint8_t>* outCredentialData,
66 vector<uint8_t>* outProofOfProvisioningSignature) override;
David Zeuthen81603152020-02-11 22:04:24 -050067
David Zeuthen28edb102020-04-28 18:54:55 -040068 private:
David Zeuthen81603152020-02-11 22:04:24 -050069 string docType_;
70 bool testCredential_;
71
Selene Huang459cb802020-01-08 22:59:02 -080072 // This is set in initialize().
David Zeuthen81603152020-02-11 22:04:24 -050073 vector<uint8_t> storageKey_;
Selene Huang92b61d62020-03-04 02:24:16 -080074 bool startPersonalizationCalled_;
75 bool firstEntry_;
Selene Huang459cb802020-01-08 22:59:02 -080076
77 // These are set in getAttestationCertificate().
David Zeuthen81603152020-02-11 22:04:24 -050078 vector<uint8_t> credentialPrivKey_;
79 vector<uint8_t> credentialPubKey_;
Selene Huang459cb802020-01-08 22:59:02 -080080 vector<vector<uint8_t>> certificateChain_;
David Zeuthen81603152020-02-11 22:04:24 -050081
82 // These fields are initialized during startPersonalization()
83 size_t numAccessControlProfileRemaining_;
84 vector<int32_t> remainingEntryCounts_;
85 cppbor::Array signedDataAccessControlProfiles_;
86 cppbor::Map signedDataNamespaces_;
87 cppbor::Array signedDataCurrentNamespace_;
David Zeuthen28edb102020-04-28 18:54:55 -040088 size_t expectedProofOfProvisioningSize_;
David Zeuthen81603152020-02-11 22:04:24 -050089
Selene Huang92b61d62020-03-04 02:24:16 -080090 // This field is initialized in addAccessControlProfile
91 set<int32_t> accessControlProfileIds_;
92
David Zeuthen81603152020-02-11 22:04:24 -050093 // These fields are initialized during beginAddEntry()
94 size_t entryRemainingBytes_;
95 vector<uint8_t> entryAdditionalData_;
96 string entryNameSpace_;
97 string entryName_;
98 vector<int32_t> entryAccessControlProfileIds_;
99 vector<uint8_t> entryBytes_;
Selene Huang92b61d62020-03-04 02:24:16 -0800100 set<string> allNameSpaces_;
David Zeuthen81603152020-02-11 22:04:24 -0500101};
102
103} // namespace aidl::android::hardware::identity
104
105#endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H