blob: b1828628628fbf67beeb95a5158dc9171968bab7 [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
Selene Huang459cb802020-01-08 22:59:02 -080067 // This is set in initialize().
David Zeuthen81603152020-02-11 22:04:24 -050068 vector<uint8_t> storageKey_;
Selene Huang459cb802020-01-08 22:59:02 -080069
70 // These are set in getAttestationCertificate().
David Zeuthen81603152020-02-11 22:04:24 -050071 vector<uint8_t> credentialPrivKey_;
72 vector<uint8_t> credentialPubKey_;
Selene Huang459cb802020-01-08 22:59:02 -080073 vector<vector<uint8_t>> certificateChain_;
David Zeuthen81603152020-02-11 22:04:24 -050074
75 // These fields are initialized during startPersonalization()
76 size_t numAccessControlProfileRemaining_;
77 vector<int32_t> remainingEntryCounts_;
78 cppbor::Array signedDataAccessControlProfiles_;
79 cppbor::Map signedDataNamespaces_;
80 cppbor::Array signedDataCurrentNamespace_;
81
82 // These fields are initialized during beginAddEntry()
83 size_t entryRemainingBytes_;
84 vector<uint8_t> entryAdditionalData_;
85 string entryNameSpace_;
86 string entryName_;
87 vector<int32_t> entryAccessControlProfileIds_;
88 vector<uint8_t> entryBytes_;
89};
90
91} // namespace aidl::android::hardware::identity
92
93#endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H