/* * 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_IDENTITYCREDENTIAL_H #define ANDROID_HARDWARE_IDENTITY_IDENTITYCREDENTIAL_H #include #include #include #include #include #include #include #include #include #include "IdentityCredentialStore.h" #include "SecureHardwareProxy.h" namespace aidl::android::hardware::identity { using ::aidl::android::hardware::keymaster::HardwareAuthToken; using ::aidl::android::hardware::keymaster::VerificationToken; using ::android::sp; using ::android::hardware::identity::SecureHardwarePresentationProxy; using ::std::map; using ::std::set; using ::std::string; using ::std::vector; class IdentityCredential : public BnIdentityCredential { public: IdentityCredential(sp hwProxyFactory, sp hwProxy, const vector& credentialData) : hwProxyFactory_(hwProxyFactory), hwProxy_(hwProxy), credentialData_(credentialData), numStartRetrievalCalls_(0), expectedDeviceNameSpacesSize_(0) {} // Parses and decrypts credentialData_, return a status code from // IIdentityCredentialStore. Must be called right after construction. int initialize(); // Methods from IIdentityCredential follow. ndk::ScopedAStatus deleteCredential(vector* outProofOfDeletionSignature) override; ndk::ScopedAStatus deleteCredentialWithChallenge( const vector& challenge, vector* outProofOfDeletionSignature) override; ndk::ScopedAStatus proveOwnership(const vector& challenge, vector* outProofOfOwnershipSignature) override; ndk::ScopedAStatus createEphemeralKeyPair(vector* outKeyPair) override; ndk::ScopedAStatus setReaderEphemeralPublicKey(const vector& publicKey) override; ndk::ScopedAStatus createAuthChallenge(int64_t* outChallenge) override; ndk::ScopedAStatus setRequestedNamespaces( const vector& requestNamespaces) override; ndk::ScopedAStatus setVerificationToken(const VerificationToken& verificationToken) override; ndk::ScopedAStatus startRetrieval( const vector& accessControlProfiles, const HardwareAuthToken& authToken, const vector& itemsRequest, const vector& signingKeyBlob, const vector& sessionTranscript, const vector& readerSignature, const vector& requestCounts) override; ndk::ScopedAStatus startRetrieveEntryValue( const string& nameSpace, const string& name, int32_t entrySize, const vector& accessControlProfileIds) override; ndk::ScopedAStatus retrieveEntryValue(const vector& encryptedContent, vector* outContent) override; ndk::ScopedAStatus finishRetrieval(vector* outMac, vector* outDeviceNameSpaces) override; ndk::ScopedAStatus generateSigningKeyPair(vector* outSigningKeyBlob, Certificate* outSigningKeyCertificate) override; ndk::ScopedAStatus updateCredential( shared_ptr* outWritableCredential) override; private: ndk::ScopedAStatus deleteCredentialCommon(const vector& challenge, bool includeChallenge, vector* outProofOfDeletionSignature); // Set by constructor sp hwProxyFactory_; sp hwProxy_; vector credentialData_; int numStartRetrievalCalls_; // Set by initialize() string docType_; bool testCredential_; vector encryptedCredentialKeys_; // Set by createEphemeralKeyPair() vector ephemeralPublicKey_; // Set by setReaderEphemeralPublicKey() vector readerPublicKey_; // Set by setRequestedNamespaces() vector requestNamespaces_; // Set by setVerificationToken(). VerificationToken verificationToken_; // Set at startRetrieval() time. vector signingKeyBlob_; vector sessionTranscript_; vector itemsRequest_; vector requestCountsRemaining_; map> requestedNameSpacesAndNames_; cppbor::Map deviceNameSpacesMap_; cppbor::Map currentNameSpaceDeviceNameSpacesMap_; // Calculated at startRetrieval() time. size_t expectedDeviceNameSpacesSize_; vector expectedNumEntriesPerNamespace_; // Set at startRetrieveEntryValue() time. string currentNameSpace_; string currentName_; vector currentAccessControlProfileIds_; size_t entryRemainingBytes_; vector entryValue_; void calcDeviceNameSpacesSize(uint32_t accessControlProfileMask); }; } // namespace aidl::android::hardware::identity #endif // ANDROID_HARDWARE_IDENTITY_IDENTITYCREDENTIAL_H