blob: b380f897a177ffa82212705775927e534c392cb5 [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>
24
25namespace aidl::android::hardware::identity {
26
27using ::std::string;
28using ::std::vector;
29
30class WritableIdentityCredential : public BnWritableIdentityCredential {
31 public:
32 WritableIdentityCredential(const string& docType, bool testCredential)
33 : docType_(docType), testCredential_(testCredential) {}
34
35 // Creates the Credential Key. Returns false on failure. Must be called
36 // right after construction.
37 bool initialize();
38
39 // Methods from IWritableIdentityCredential follow.
40 ndk::ScopedAStatus getAttestationCertificate(const vector<int8_t>& attestationApplicationId,
41 const vector<int8_t>& attestationChallenge,
42 vector<Certificate>* outCertificateChain) override;
43
44 ndk::ScopedAStatus startPersonalization(int32_t accessControlProfileCount,
45 const vector<int32_t>& entryCounts) override;
46
47 ndk::ScopedAStatus addAccessControlProfile(
48 int32_t id, const Certificate& readerCertificate, bool userAuthenticationRequired,
49 int64_t timeoutMillis, int64_t secureUserId,
50 SecureAccessControlProfile* outSecureAccessControlProfile) override;
51
52 ndk::ScopedAStatus beginAddEntry(const vector<int32_t>& accessControlProfileIds,
53 const string& nameSpace, const string& name,
54 int32_t entrySize) override;
55
56 ndk::ScopedAStatus addEntryValue(const vector<int8_t>& content,
57 vector<int8_t>* outEncryptedContent) override;
58
59 ndk::ScopedAStatus finishAddingEntries(
60 vector<int8_t>* outCredentialData,
61 vector<int8_t>* outProofOfProvisioningSignature) override;
62
63 // private:
64 string docType_;
65 bool testCredential_;
66
67 // These are set in initialize().
68 vector<uint8_t> storageKey_;
69 vector<uint8_t> credentialPrivKey_;
70 vector<uint8_t> credentialPubKey_;
71
72 // These fields are initialized during startPersonalization()
73 size_t numAccessControlProfileRemaining_;
74 vector<int32_t> remainingEntryCounts_;
75 cppbor::Array signedDataAccessControlProfiles_;
76 cppbor::Map signedDataNamespaces_;
77 cppbor::Array signedDataCurrentNamespace_;
78
79 // These fields are initialized during beginAddEntry()
80 size_t entryRemainingBytes_;
81 vector<uint8_t> entryAdditionalData_;
82 string entryNameSpace_;
83 string entryName_;
84 vector<int32_t> entryAccessControlProfileIds_;
85 vector<uint8_t> entryBytes_;
86};
87
88} // namespace aidl::android::hardware::identity
89
90#endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H