blob: c6f0628caef15faae6a9c317ca689c1c80956cb7 [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
David Zeuthen630de2a2020-05-11 14:04:54 -040026#include "IdentityCredentialStore.h"
27#include "SecureHardwareProxy.h"
28
David Zeuthen81603152020-02-11 22:04:24 -050029namespace aidl::android::hardware::identity {
30
David Zeuthen630de2a2020-05-11 14:04:54 -040031using ::android::sp;
32using ::android::hardware::identity::SecureHardwareProvisioningProxy;
Selene Huang92b61d62020-03-04 02:24:16 -080033using ::std::set;
David Zeuthen81603152020-02-11 22:04:24 -050034using ::std::string;
35using ::std::vector;
36
37class WritableIdentityCredential : public BnWritableIdentityCredential {
38 public:
David Zeuthen630de2a2020-05-11 14:04:54 -040039 WritableIdentityCredential(sp<SecureHardwareProvisioningProxy> hwProxy, const string& docType,
40 bool testCredential)
41 : hwProxy_(hwProxy), docType_(docType), testCredential_(testCredential) {}
42
43 ~WritableIdentityCredential();
David Zeuthen81603152020-02-11 22:04:24 -050044
45 // Creates the Credential Key. Returns false on failure. Must be called
46 // right after construction.
47 bool initialize();
48
49 // Methods from IWritableIdentityCredential follow.
Jooyung Han17be89b2020-02-21 21:17:06 +090050 ndk::ScopedAStatus getAttestationCertificate(const vector<uint8_t>& attestationApplicationId,
51 const vector<uint8_t>& attestationChallenge,
David Zeuthen81603152020-02-11 22:04:24 -050052 vector<Certificate>* outCertificateChain) override;
53
David Zeuthen28edb102020-04-28 18:54:55 -040054 ndk::ScopedAStatus setExpectedProofOfProvisioningSize(
55 int32_t expectedProofOfProvisioningSize) override;
56
David Zeuthen81603152020-02-11 22:04:24 -050057 ndk::ScopedAStatus startPersonalization(int32_t accessControlProfileCount,
58 const vector<int32_t>& entryCounts) override;
59
60 ndk::ScopedAStatus addAccessControlProfile(
61 int32_t id, const Certificate& readerCertificate, bool userAuthenticationRequired,
62 int64_t timeoutMillis, int64_t secureUserId,
63 SecureAccessControlProfile* outSecureAccessControlProfile) override;
64
65 ndk::ScopedAStatus beginAddEntry(const vector<int32_t>& accessControlProfileIds,
66 const string& nameSpace, const string& name,
67 int32_t entrySize) override;
Jooyung Han17be89b2020-02-21 21:17:06 +090068 ndk::ScopedAStatus addEntryValue(const vector<uint8_t>& content,
69 vector<uint8_t>* outEncryptedContent) override;
David Zeuthen81603152020-02-11 22:04:24 -050070
71 ndk::ScopedAStatus finishAddingEntries(
Jooyung Han17be89b2020-02-21 21:17:06 +090072 vector<uint8_t>* outCredentialData,
73 vector<uint8_t>* outProofOfProvisioningSignature) override;
David Zeuthen81603152020-02-11 22:04:24 -050074
David Zeuthen28edb102020-04-28 18:54:55 -040075 private:
David Zeuthen630de2a2020-05-11 14:04:54 -040076 // Set by constructor.
77 sp<SecureHardwareProvisioningProxy> hwProxy_;
David Zeuthen81603152020-02-11 22:04:24 -050078 string docType_;
79 bool testCredential_;
80
Selene Huang459cb802020-01-08 22:59:02 -080081 // This is set in initialize().
Selene Huang92b61d62020-03-04 02:24:16 -080082 bool startPersonalizationCalled_;
83 bool firstEntry_;
Selene Huang459cb802020-01-08 22:59:02 -080084
David Zeuthen630de2a2020-05-11 14:04:54 -040085 // This is set in getAttestationCertificate().
86 bool getAttestationCertificateAlreadyCalled_ = false;
David Zeuthen81603152020-02-11 22:04:24 -050087
88 // These fields are initialized during startPersonalization()
89 size_t numAccessControlProfileRemaining_;
90 vector<int32_t> remainingEntryCounts_;
91 cppbor::Array signedDataAccessControlProfiles_;
92 cppbor::Map signedDataNamespaces_;
93 cppbor::Array signedDataCurrentNamespace_;
David Zeuthen28edb102020-04-28 18:54:55 -040094 size_t expectedProofOfProvisioningSize_;
David Zeuthen81603152020-02-11 22:04:24 -050095
Selene Huang92b61d62020-03-04 02:24:16 -080096 // This field is initialized in addAccessControlProfile
97 set<int32_t> accessControlProfileIds_;
98
David Zeuthen81603152020-02-11 22:04:24 -050099 // These fields are initialized during beginAddEntry()
100 size_t entryRemainingBytes_;
David Zeuthen81603152020-02-11 22:04:24 -0500101 string entryNameSpace_;
102 string entryName_;
103 vector<int32_t> entryAccessControlProfileIds_;
104 vector<uint8_t> entryBytes_;
Selene Huang92b61d62020-03-04 02:24:16 -0800105 set<string> allNameSpaces_;
David Zeuthen81603152020-02-11 22:04:24 -0500106};
107
108} // namespace aidl::android::hardware::identity
109
110#endif // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H