1 /*
2 **
3 ** Copyright 2017, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #ifndef INCLUDE_KEYMASTER_SOFT_KEYMASTER_ENFORCEMENT_H_
19 #define INCLUDE_KEYMASTER_SOFT_KEYMASTER_ENFORCEMENT_H_
20 
21 #include <keymaster/android_keymaster_messages.h>
22 #include <keymaster/keymaster_enforcement.h>
23 
24 namespace keymaster {
25 
26 class SoftKeymasterEnforcement : public KeymasterEnforcement {
27   public:
SoftKeymasterEnforcement(uint32_t max_access_time_map_size,uint32_t max_access_count_map_size)28     SoftKeymasterEnforcement(uint32_t max_access_time_map_size, uint32_t max_access_count_map_size)
29         : KeymasterEnforcement(max_access_time_map_size, max_access_count_map_size) {}
~SoftKeymasterEnforcement()30     virtual ~SoftKeymasterEnforcement() {}
activation_date_valid(uint64_t)31     bool activation_date_valid(uint64_t /*activation_date*/) const override { return true; }
expiration_date_passed(uint64_t)32     bool expiration_date_passed(uint64_t /*expiration_date*/) const override { return false; }
auth_token_timed_out(const hw_auth_token_t &,uint32_t)33     bool auth_token_timed_out(const hw_auth_token_t& /*token*/,
34                               uint32_t /*timeout*/) const override {
35         return false;
36     }
37     uint64_t get_current_time_ms() const override;
SecurityLevel()38     keymaster_security_level_t SecurityLevel() const override { return KM_SECURITY_LEVEL_SOFTWARE; }
ValidateTokenSignature(const hw_auth_token_t &)39     bool ValidateTokenSignature(const hw_auth_token_t& /*token*/) const override { return true; }
40     bool CreateKeyId(const keymaster_key_blob_t& key_blob, km_id_t* keyid) const override;
41 
42     keymaster_error_t GetHmacSharingParameters(HmacSharingParameters* params) override;
43     keymaster_error_t ComputeSharedHmac(const HmacSharingParametersArray& params_array,
44                                         KeymasterBlob* sharingCheck) override;
45     VerifyAuthorizationResponse
46     VerifyAuthorization(const VerifyAuthorizationRequest& request) override;
47 
48   private:
49     bool have_saved_params_ = false;
50     HmacSharingParameters saved_params_;
51     KeymasterKeyBlob hmac_key_;
52 };
53 
54 }  // namespace keymaster
55 
56 #endif  // INCLUDE_KEYMASTER_SOFT_KEYMASTER_ENFORCEMENT_H_
57