1 // 2 // Copyright (C) 2020 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 #pragma once 17 18 #include <keymaster/keymaster_enforcement.h> 19 20 #include "host/commands/secure_env/tpm_gatekeeper.h" 21 #include "host/commands/secure_env/tpm_resource_manager.h" 22 23 /** 24 * Implementation of keymaster::KeymasterEnforcement that depends on having a 25 * TPM available. See the definitions in 26 * system/keymaster/include/keymaster/keymaster_enforcement.h 27 */ 28 class TpmKeymasterEnforcement : public keymaster::KeymasterEnforcement { 29 public: 30 TpmKeymasterEnforcement( 31 TpmResourceManager& resource_manager, TpmGatekeeper& gatekeeper); 32 ~TpmKeymasterEnforcement(); 33 34 bool activation_date_valid(uint64_t activation_date) const override; 35 bool expiration_date_passed(uint64_t expiration_date) const override; 36 bool auth_token_timed_out( 37 const hw_auth_token_t& token, uint32_t timeout) const override; 38 uint64_t get_current_time_ms() const override; 39 40 keymaster_security_level_t SecurityLevel() const override; 41 bool ValidateTokenSignature(const hw_auth_token_t& token) const override; 42 43 keymaster_error_t GetHmacSharingParameters( 44 keymaster::HmacSharingParameters* params) override; 45 keymaster_error_t ComputeSharedHmac( 46 const keymaster::HmacSharingParametersArray& params_array, 47 keymaster::KeymasterBlob* sharingCheck) override; 48 49 keymaster::VerifyAuthorizationResponse VerifyAuthorization( 50 const keymaster::VerifyAuthorizationRequest& request) override; 51 52 bool CreateKeyId( 53 const keymaster_key_blob_t& key_blob, 54 keymaster::km_id_t* keyid) const override; 55 56 private: 57 TpmResourceManager& resource_manager_; 58 TpmGatekeeper& gatekeeper_; 59 bool have_saved_params_ = false; 60 keymaster::HmacSharingParameters saved_params_; 61 }; 62