summaryrefslogtreecommitdiffstats
path: root/identity/1.0/default/WritableIdentityCredential.h
blob: b1deb1675017cfc97777ee8438cdefa50e4df4b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright 2019, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H
#define ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H

#include <android/hardware/identity/1.0/IWritableIdentityCredential.h>

#include <android/hardware/identity/support/IdentityCredentialSupport.h>

#include <cppbor.h>

namespace android {
namespace hardware {
namespace identity {
namespace implementation {

using ::std::string;
using ::std::vector;

using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::identity::V1_0::IWritableIdentityCredential;
using ::android::hardware::identity::V1_0::Result;
using ::android::hardware::identity::V1_0::ResultCode;
using ::android::hardware::identity::V1_0::SecureAccessControlProfile;

class WritableIdentityCredential : public IWritableIdentityCredential {
  public:
    WritableIdentityCredential(const hidl_string& docType, bool testCredential)
        : docType_(docType), testCredential_(testCredential) {}

    // Creates the Credential Key. Returns false on failure. Must be called
    // right after construction.
    bool initialize();

    // Methods from ::android::hardware::identity::IWritableIdentityCredential
    // follow.
    Return<void> getAttestationCertificate(const hidl_vec<uint8_t>& attestationApplicationId,
                                           const hidl_vec<uint8_t>& attestationChallenge,
                                           getAttestationCertificate_cb _hidl_cb) override;

    Return<void> startPersonalization(uint16_t accessControlProfileCount,
                                      const hidl_vec<uint16_t>& entryCounts,
                                      startPersonalization_cb _hidl_cb) override;

    Return<void> addAccessControlProfile(uint16_t id, const hidl_vec<uint8_t>& readerCertificate,
                                         bool userAuthenticationRequired, uint64_t timeoutMillis,
                                         uint64_t secureUserId,
                                         addAccessControlProfile_cb _hidl_cb) override;

    Return<void> beginAddEntry(const hidl_vec<uint16_t>& accessControlProfileIds,
                               const hidl_string& nameSpace, const hidl_string& name,
                               uint32_t entrySize, beginAddEntry_cb _hidl_cb) override;

    Return<void> addEntryValue(const hidl_vec<uint8_t>& content,
                               addEntryValue_cb _hidl_cb) override;

    Return<void> finishAddingEntries(finishAddingEntries_cb _hidl_cb) override;

  private:
    string docType_;
    bool testCredential_;

    // These are set in initialize().
    vector<uint8_t> storageKey_;
    vector<uint8_t> credentialPrivKey_;
    vector<uint8_t> credentialPubKey_;

    // These fields are initialized during startPersonalization()
    size_t numAccessControlProfileRemaining_;
    vector<uint16_t> remainingEntryCounts_;
    cppbor::Array signedDataAccessControlProfiles_;
    cppbor::Map signedDataNamespaces_;
    cppbor::Array signedDataCurrentNamespace_;

    // These fields are initialized during beginAddEntry()
    size_t entryRemainingBytes_;
    vector<uint8_t> entryAdditionalData_;
    string entryNameSpace_;
    string entryName_;
    vector<uint16_t> entryAccessControlProfileIds_;
    vector<uint8_t> entryBytes_;
};

}  // namespace implementation
}  // namespace identity
}  // namespace hardware
}  // namespace android

#endif  // ANDROID_HARDWARE_IDENTITY_WRITABLEIDENTITYCREDENTIAL_H