blob: 49ed0d45b8fe1ba0f35fc5bbbe83fec6d9e1c065 [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_IDENTITYCREDENTIAL_H
18#define ANDROID_HARDWARE_IDENTITY_IDENTITYCREDENTIAL_H
19
20#include <aidl/android/hardware/identity/BnIdentityCredential.h>
21#include <aidl/android/hardware/keymaster/HardwareAuthToken.h>
22#include <android/hardware/identity/support/IdentityCredentialSupport.h>
23
24#include <map>
25#include <set>
26#include <string>
27#include <vector>
28
29#include <cppbor/cppbor.h>
30
31namespace aidl::android::hardware::identity {
32
33using ::aidl::android::hardware::keymaster::HardwareAuthToken;
34using ::std::map;
35using ::std::string;
36using ::std::vector;
37
38using MapStringToVectorOfStrings = map<string, vector<string>>;
39
40class IdentityCredential : public BnIdentityCredential {
41 public:
42 IdentityCredential(const vector<uint8_t>& credentialData)
43 : credentialData_(credentialData), numStartRetrievalCalls_(0), authChallenge_(0) {}
44
45 // Parses and decrypts credentialData_, return a status code from
46 // IIdentityCredentialStore. Must be called right after construction.
47 int initialize();
48
49 // Methods from IIdentityCredential follow.
50 ndk::ScopedAStatus deleteCredential(vector<int8_t>* outProofOfDeletionSignature) override;
51 ndk::ScopedAStatus createEphemeralKeyPair(vector<int8_t>* outKeyPair) override;
52 ndk::ScopedAStatus setReaderEphemeralPublicKey(const vector<int8_t>& publicKey) override;
53 ndk::ScopedAStatus createAuthChallenge(int64_t* outChallenge) override;
54 ndk::ScopedAStatus startRetrieval(
55 const vector<SecureAccessControlProfile>& accessControlProfiles,
56 const HardwareAuthToken& authToken, const vector<int8_t>& itemsRequest,
57 const vector<int8_t>& sessionTranscript, const vector<int8_t>& readerSignature,
58 const vector<int32_t>& requestCounts) override;
59 ndk::ScopedAStatus startRetrieveEntryValue(
60 const string& nameSpace, const string& name, int32_t entrySize,
61 const vector<int32_t>& accessControlProfileIds) override;
62 ndk::ScopedAStatus retrieveEntryValue(const vector<int8_t>& encryptedContent,
63 vector<int8_t>* outContent) override;
64 ndk::ScopedAStatus finishRetrieval(const vector<int8_t>& signingKeyBlob, vector<int8_t>* outMac,
65 vector<int8_t>* outDeviceNameSpaces) override;
66 ndk::ScopedAStatus generateSigningKeyPair(vector<int8_t>* outSigningKeyBlob,
67 Certificate* outSigningKeyCertificate) override;
68
69 private:
70 // Set by constructor
71 vector<uint8_t> credentialData_;
72 int numStartRetrievalCalls_;
73
74 // Set by initialize()
75 string docType_;
76 bool testCredential_;
77 vector<uint8_t> storageKey_;
78 vector<uint8_t> credentialPrivKey_;
79
80 // Set by createEphemeralKeyPair()
81 vector<uint8_t> ephemeralPublicKey_;
82
83 // Set by setReaderEphemeralPublicKey()
84 vector<uint8_t> readerPublicKey_;
85
86 // Set by createAuthChallenge()
87 uint64_t authChallenge_;
88
89 // Set at startRetrieval() time.
90 map<int32_t, int> profileIdToAccessCheckResult_;
91 vector<uint8_t> sessionTranscript_;
92 std::unique_ptr<cppbor::Item> sessionTranscriptItem_;
93 vector<uint8_t> itemsRequest_;
94 vector<int32_t> requestCountsRemaining_;
95 MapStringToVectorOfStrings requestedNameSpacesAndNames_;
96 cppbor::Map deviceNameSpacesMap_;
97 cppbor::Map currentNameSpaceDeviceNameSpacesMap_;
98
99 // Set at startRetrieveEntryValue() time.
100 string currentNameSpace_;
101 string currentName_;
102 size_t entryRemainingBytes_;
103 vector<uint8_t> entryValue_;
104 vector<uint8_t> entryAdditionalData_;
105};
106
107} // namespace aidl::android::hardware::identity
108
109#endif // ANDROID_HARDWARE_IDENTITY_IDENTITYCREDENTIAL_H