keymaster_enforcement.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. * Copyright (C) 2014 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. #include <keymaster/keymaster_enforcement.h>
  17. #include <assert.h>
  18. #include <limits.h>
  19. #include <string.h>
  20. #include <openssl/evp.h>
  21. #include <hardware/hw_auth_token.h>
  22. #include <keymaster/android_keymaster_utils.h>
  23. #include <keymaster/logger.h>
  24. #include <keymaster/List.h>
  25. namespace keymaster {
  26. class AccessTimeMap {
  27. public:
  28. explicit AccessTimeMap(uint32_t max_size) : max_size_(max_size) {}
  29. /* If the key is found, returns true and fills \p last_access_time. If not found returns
  30. * false. */
  31. bool LastKeyAccessTime(km_id_t keyid, uint32_t* last_access_time) const;
  32. /* Updates the last key access time with the currentTime parameter. Adds the key if
  33. * needed, returning false if key cannot be added because list is full. */
  34. bool UpdateKeyAccessTime(km_id_t keyid, uint32_t current_time, uint32_t timeout);
  35. private:
  36. struct AccessTime {
  37. km_id_t keyid;
  38. uint32_t access_time;
  39. uint32_t timeout;
  40. };
  41. List<AccessTime> last_access_list_;
  42. const uint32_t max_size_;
  43. };
  44. class AccessCountMap {
  45. public:
  46. explicit AccessCountMap(uint32_t max_size) : max_size_(max_size) {}
  47. /* If the key is found, returns true and fills \p count. If not found returns
  48. * false. */
  49. bool KeyAccessCount(km_id_t keyid, uint32_t* count) const;
  50. /* Increments key access count, adding an entry if the key has never been used. Returns
  51. * false if the list has reached maximum size. */
  52. bool IncrementKeyAccessCount(km_id_t keyid);
  53. private:
  54. struct AccessCount {
  55. km_id_t keyid;
  56. uint64_t access_count;
  57. };
  58. List<AccessCount> access_count_list_;
  59. const uint32_t max_size_;
  60. };
  61. bool is_public_key_algorithm(const AuthProxy& auth_set) {
  62. keymaster_algorithm_t algorithm;
  63. return auth_set.GetTagValue(TAG_ALGORITHM, &algorithm) &&
  64. (algorithm == KM_ALGORITHM_RSA || algorithm == KM_ALGORITHM_EC);
  65. }
  66. static keymaster_error_t authorized_purpose(const keymaster_purpose_t purpose,
  67. const AuthProxy& auth_set) {
  68. switch (purpose) {
  69. case KM_PURPOSE_VERIFY:
  70. case KM_PURPOSE_ENCRYPT:
  71. case KM_PURPOSE_SIGN:
  72. case KM_PURPOSE_DECRYPT:
  73. case KM_PURPOSE_WRAP:
  74. if (auth_set.Contains(TAG_PURPOSE, purpose))
  75. return KM_ERROR_OK;
  76. return KM_ERROR_INCOMPATIBLE_PURPOSE;
  77. default:
  78. return KM_ERROR_UNSUPPORTED_PURPOSE;
  79. }
  80. }
  81. inline bool is_origination_purpose(keymaster_purpose_t purpose) {
  82. return purpose == KM_PURPOSE_ENCRYPT || purpose == KM_PURPOSE_SIGN;
  83. }
  84. inline bool is_usage_purpose(keymaster_purpose_t purpose) {
  85. return purpose == KM_PURPOSE_DECRYPT || purpose == KM_PURPOSE_VERIFY;
  86. }
  87. KeymasterEnforcement::KeymasterEnforcement(uint32_t max_access_time_map_size,
  88. uint32_t max_access_count_map_size)
  89. : access_time_map_(new (std::nothrow) AccessTimeMap(max_access_time_map_size)),
  90. access_count_map_(new (std::nothrow) AccessCountMap(max_access_count_map_size)) {}
  91. KeymasterEnforcement::~KeymasterEnforcement() {
  92. delete access_time_map_;
  93. delete access_count_map_;
  94. }
  95. keymaster_error_t KeymasterEnforcement::AuthorizeOperation(const keymaster_purpose_t purpose,
  96. const km_id_t keyid,
  97. const AuthProxy& auth_set,
  98. const AuthorizationSet& operation_params,
  99. keymaster_operation_handle_t op_handle,
  100. bool is_begin_operation) {
  101. if (is_public_key_algorithm(auth_set)) {
  102. switch (purpose) {
  103. case KM_PURPOSE_ENCRYPT:
  104. case KM_PURPOSE_VERIFY:
  105. /* Public key operations are always authorized. */
  106. return KM_ERROR_OK;
  107. case KM_PURPOSE_DECRYPT:
  108. case KM_PURPOSE_SIGN:
  109. case KM_PURPOSE_DERIVE_KEY:
  110. case KM_PURPOSE_WRAP:
  111. break;
  112. };
  113. };
  114. if (is_begin_operation)
  115. return AuthorizeBegin(purpose, keyid, auth_set, operation_params);
  116. else
  117. return AuthorizeUpdateOrFinish(auth_set, operation_params, op_handle);
  118. }
  119. // For update and finish the only thing to check is user authentication, and then only if it's not
  120. // timeout-based.
  121. keymaster_error_t
  122. KeymasterEnforcement::AuthorizeUpdateOrFinish(const AuthProxy& auth_set,
  123. const AuthorizationSet& operation_params,
  124. keymaster_operation_handle_t op_handle) {
  125. int auth_type_index = -1;
  126. int trusted_confirmation_index = -1;
  127. for (size_t pos = 0; pos < auth_set.size(); ++pos) {
  128. switch (auth_set[pos].tag) {
  129. case KM_TAG_USER_AUTH_TYPE:
  130. auth_type_index = pos;
  131. break;
  132. case KM_TAG_TRUSTED_CONFIRMATION_REQUIRED:
  133. trusted_confirmation_index = pos;
  134. break;
  135. case KM_TAG_NO_AUTH_REQUIRED:
  136. case KM_TAG_AUTH_TIMEOUT:
  137. // If no auth is required or if auth is timeout-based, we have nothing to check.
  138. default:
  139. break;
  140. }
  141. }
  142. // TODO verify trusted confirmation mac once we have a shared secret established
  143. // For now, since we do not have such a service, any token offered here must be invalid.
  144. if (trusted_confirmation_index != -1) {
  145. return KM_ERROR_NO_USER_CONFIRMATION;
  146. }
  147. // Note that at this point we should be able to assume that authentication is required, because
  148. // authentication is required if KM_TAG_NO_AUTH_REQUIRED is absent. However, there are legacy
  149. // keys which have no authentication-related tags, so we assume that absence is equivalent to
  150. // presence of KM_TAG_NO_AUTH_REQUIRED.
  151. //
  152. // So, if we found KM_TAG_USER_AUTH_TYPE or if we find KM_TAG_USER_SECURE_ID then authentication
  153. // is required. If we find neither, then we assume authentication is not required and return
  154. // success.
  155. bool authentication_required = (auth_type_index != -1);
  156. for (auto& param : auth_set) {
  157. if (param.tag == KM_TAG_USER_SECURE_ID) {
  158. authentication_required = true;
  159. int auth_timeout_index = -1;
  160. if (AuthTokenMatches(auth_set, operation_params, param.long_integer, auth_type_index,
  161. auth_timeout_index, op_handle, false /* is_begin_operation */))
  162. return KM_ERROR_OK;
  163. }
  164. }
  165. if (authentication_required) {
  166. return KM_ERROR_KEY_USER_NOT_AUTHENTICATED;
  167. }
  168. return KM_ERROR_OK;
  169. }
  170. keymaster_error_t KeymasterEnforcement::AuthorizeBegin(const keymaster_purpose_t purpose,
  171. const km_id_t keyid,
  172. const AuthProxy& auth_set,
  173. const AuthorizationSet& operation_params) {
  174. // Find some entries that may be needed to handle KM_TAG_USER_SECURE_ID
  175. int auth_timeout_index = -1;
  176. int auth_type_index = -1;
  177. int no_auth_required_index = -1;
  178. for (size_t pos = 0; pos < auth_set.size(); ++pos) {
  179. switch (auth_set[pos].tag) {
  180. case KM_TAG_AUTH_TIMEOUT:
  181. auth_timeout_index = pos;
  182. break;
  183. case KM_TAG_USER_AUTH_TYPE:
  184. auth_type_index = pos;
  185. break;
  186. case KM_TAG_NO_AUTH_REQUIRED:
  187. no_auth_required_index = pos;
  188. break;
  189. default:
  190. break;
  191. }
  192. }
  193. keymaster_error_t error = authorized_purpose(purpose, auth_set);
  194. if (error != KM_ERROR_OK)
  195. return error;
  196. // If successful, and if key has a min time between ops, this will be set to the time limit
  197. uint32_t min_ops_timeout = UINT32_MAX;
  198. bool update_access_count = false;
  199. bool caller_nonce_authorized_by_key = false;
  200. bool authentication_required = false;
  201. bool auth_token_matched = false;
  202. for (auto& param : auth_set) {
  203. // KM_TAG_PADDING_OLD and KM_TAG_DIGEST_OLD aren't actually members of the enum, so we can't
  204. // switch on them. There's nothing to validate for them, though, so just ignore them.
  205. if (param.tag == KM_TAG_PADDING_OLD || param.tag == KM_TAG_DIGEST_OLD)
  206. continue;
  207. switch (param.tag) {
  208. case KM_TAG_ACTIVE_DATETIME:
  209. if (!activation_date_valid(param.date_time))
  210. return KM_ERROR_KEY_NOT_YET_VALID;
  211. break;
  212. case KM_TAG_ORIGINATION_EXPIRE_DATETIME:
  213. if (is_origination_purpose(purpose) && expiration_date_passed(param.date_time))
  214. return KM_ERROR_KEY_EXPIRED;
  215. break;
  216. case KM_TAG_USAGE_EXPIRE_DATETIME:
  217. if (is_usage_purpose(purpose) && expiration_date_passed(param.date_time))
  218. return KM_ERROR_KEY_EXPIRED;
  219. break;
  220. case KM_TAG_MIN_SECONDS_BETWEEN_OPS:
  221. min_ops_timeout = param.integer;
  222. if (!MinTimeBetweenOpsPassed(min_ops_timeout, keyid))
  223. return KM_ERROR_KEY_RATE_LIMIT_EXCEEDED;
  224. break;
  225. case KM_TAG_MAX_USES_PER_BOOT:
  226. update_access_count = true;
  227. if (!MaxUsesPerBootNotExceeded(keyid, param.integer))
  228. return KM_ERROR_KEY_MAX_OPS_EXCEEDED;
  229. break;
  230. case KM_TAG_USER_SECURE_ID:
  231. if (no_auth_required_index != -1) {
  232. // Key has both KM_TAG_USER_SECURE_ID and KM_TAG_NO_AUTH_REQUIRED
  233. return KM_ERROR_INVALID_KEY_BLOB;
  234. }
  235. if (auth_timeout_index != -1) {
  236. authentication_required = true;
  237. if (AuthTokenMatches(auth_set, operation_params, param.long_integer,
  238. auth_type_index, auth_timeout_index, 0 /* op_handle */,
  239. true /* is_begin_operation */))
  240. auth_token_matched = true;
  241. }
  242. break;
  243. case KM_TAG_CALLER_NONCE:
  244. caller_nonce_authorized_by_key = true;
  245. break;
  246. /* Tags should never be in key auths. */
  247. case KM_TAG_INVALID:
  248. case KM_TAG_AUTH_TOKEN:
  249. case KM_TAG_ROOT_OF_TRUST:
  250. case KM_TAG_APPLICATION_DATA:
  251. case KM_TAG_ATTESTATION_CHALLENGE:
  252. case KM_TAG_ATTESTATION_APPLICATION_ID:
  253. case KM_TAG_ATTESTATION_ID_BRAND:
  254. case KM_TAG_ATTESTATION_ID_DEVICE:
  255. case KM_TAG_ATTESTATION_ID_PRODUCT:
  256. case KM_TAG_ATTESTATION_ID_SERIAL:
  257. case KM_TAG_ATTESTATION_ID_IMEI:
  258. case KM_TAG_ATTESTATION_ID_MEID:
  259. case KM_TAG_ATTESTATION_ID_MANUFACTURER:
  260. case KM_TAG_ATTESTATION_ID_MODEL:
  261. return KM_ERROR_INVALID_KEY_BLOB;
  262. /* Tags used for cryptographic parameters in keygen. Nothing to enforce. */
  263. case KM_TAG_PURPOSE:
  264. case KM_TAG_ALGORITHM:
  265. case KM_TAG_KEY_SIZE:
  266. case KM_TAG_BLOCK_MODE:
  267. case KM_TAG_DIGEST:
  268. case KM_TAG_MAC_LENGTH:
  269. case KM_TAG_PADDING:
  270. case KM_TAG_NONCE:
  271. case KM_TAG_MIN_MAC_LENGTH:
  272. case KM_TAG_KDF:
  273. case KM_TAG_EC_CURVE:
  274. /* Tags not used for operations. */
  275. case KM_TAG_BLOB_USAGE_REQUIREMENTS:
  276. case KM_TAG_EXPORTABLE:
  277. /* Algorithm specific parameters not used for access control. */
  278. case KM_TAG_RSA_PUBLIC_EXPONENT:
  279. case KM_TAG_ECIES_SINGLE_HASH_MODE:
  280. /* Informational tags. */
  281. case KM_TAG_CREATION_DATETIME:
  282. case KM_TAG_ORIGIN:
  283. case KM_TAG_ROLLBACK_RESISTANT:
  284. /* Tags handled when KM_TAG_USER_SECURE_ID is handled */
  285. case KM_TAG_NO_AUTH_REQUIRED:
  286. case KM_TAG_USER_AUTH_TYPE:
  287. case KM_TAG_AUTH_TIMEOUT:
  288. /* Tag to provide data to operations. */
  289. case KM_TAG_ASSOCIATED_DATA:
  290. /* Tags that are implicitly verified by secure side */
  291. case KM_TAG_ALL_APPLICATIONS:
  292. case KM_TAG_APPLICATION_ID:
  293. case KM_TAG_OS_VERSION:
  294. case KM_TAG_OS_PATCHLEVEL:
  295. /* Ignored pending removal */
  296. case KM_TAG_ALL_USERS:
  297. /* TODO(swillden): Handle these */
  298. case KM_TAG_INCLUDE_UNIQUE_ID:
  299. case KM_TAG_UNIQUE_ID:
  300. case KM_TAG_RESET_SINCE_ID_ROTATION:
  301. case KM_TAG_ALLOW_WHILE_ON_BODY:
  302. case KM_TAG_TRUSTED_CONFIRMATION_REQUIRED:
  303. break;
  304. /* TODO(bcyoung): This is currently handled in keystore, but may move to keymaster in the
  305. * future */
  306. case KM_TAG_USER_ID:
  307. case KM_TAG_UNLOCKED_DEVICE_REQUIRED:
  308. break;
  309. case KM_TAG_BOOTLOADER_ONLY:
  310. return KM_ERROR_INVALID_KEY_BLOB;
  311. }
  312. }
  313. if (authentication_required && !auth_token_matched) {
  314. LOG_E("Auth required but no matching auth token found", 0);
  315. return KM_ERROR_KEY_USER_NOT_AUTHENTICATED;
  316. }
  317. if (!caller_nonce_authorized_by_key && is_origination_purpose(purpose) &&
  318. operation_params.find(KM_TAG_NONCE) != -1)
  319. return KM_ERROR_CALLER_NONCE_PROHIBITED;
  320. if (min_ops_timeout != UINT32_MAX) {
  321. if (!access_time_map_) {
  322. LOG_S("Rate-limited keys table not allocated. Rate-limited keys disabled", 0);
  323. return KM_ERROR_MEMORY_ALLOCATION_FAILED;
  324. }
  325. if (!access_time_map_->UpdateKeyAccessTime(keyid, get_current_time(), min_ops_timeout)) {
  326. LOG_E("Rate-limited keys table full. Entries will time out.", 0);
  327. return KM_ERROR_TOO_MANY_OPERATIONS;
  328. }
  329. }
  330. if (update_access_count) {
  331. if (!access_count_map_) {
  332. LOG_S("Usage-count limited keys tabel not allocated. Count-limited keys disabled", 0);
  333. return KM_ERROR_MEMORY_ALLOCATION_FAILED;
  334. }
  335. if (!access_count_map_->IncrementKeyAccessCount(keyid)) {
  336. LOG_E("Usage count-limited keys table full, until reboot.", 0);
  337. return KM_ERROR_TOO_MANY_OPERATIONS;
  338. }
  339. }
  340. return KM_ERROR_OK;
  341. }
  342. bool KeymasterEnforcement::MinTimeBetweenOpsPassed(uint32_t min_time_between, const km_id_t keyid) {
  343. if (!access_time_map_)
  344. return false;
  345. uint32_t last_access_time;
  346. if (!access_time_map_->LastKeyAccessTime(keyid, &last_access_time))
  347. return true;
  348. return min_time_between <= static_cast<int64_t>(get_current_time()) - last_access_time;
  349. }
  350. bool KeymasterEnforcement::MaxUsesPerBootNotExceeded(const km_id_t keyid, uint32_t max_uses) {
  351. if (!access_count_map_)
  352. return false;
  353. uint32_t key_access_count;
  354. if (!access_count_map_->KeyAccessCount(keyid, &key_access_count))
  355. return true;
  356. return key_access_count < max_uses;
  357. }
  358. bool KeymasterEnforcement::AuthTokenMatches(const AuthProxy& auth_set,
  359. const AuthorizationSet& operation_params,
  360. const uint64_t user_secure_id,
  361. const int auth_type_index, const int auth_timeout_index,
  362. const keymaster_operation_handle_t op_handle,
  363. bool is_begin_operation) const {
  364. assert(auth_type_index < static_cast<int>(auth_set.size()));
  365. assert(auth_timeout_index < static_cast<int>(auth_set.size()));
  366. keymaster_blob_t auth_token_blob;
  367. if (!operation_params.GetTagValue(TAG_AUTH_TOKEN, &auth_token_blob)) {
  368. LOG_E("Authentication required, but auth token not provided", 0);
  369. return false;
  370. }
  371. if (auth_token_blob.data_length != sizeof(hw_auth_token_t)) {
  372. LOG_E("Bug: Auth token is the wrong size (%d expected, %d found)", sizeof(hw_auth_token_t),
  373. auth_token_blob.data_length);
  374. return false;
  375. }
  376. hw_auth_token_t auth_token;
  377. memcpy(&auth_token, auth_token_blob.data, sizeof(hw_auth_token_t));
  378. if (auth_token.version != HW_AUTH_TOKEN_VERSION) {
  379. LOG_E("Bug: Auth token is the version %d (or is not an auth token). Expected %d",
  380. auth_token.version, HW_AUTH_TOKEN_VERSION);
  381. return false;
  382. }
  383. if (!ValidateTokenSignature(auth_token)) {
  384. LOG_E("Auth token signature invalid", 0);
  385. return false;
  386. }
  387. if (auth_timeout_index == -1 && op_handle && op_handle != auth_token.challenge) {
  388. LOG_E("Auth token has the challenge %llu, need %llu", auth_token.challenge, op_handle);
  389. return false;
  390. }
  391. if (user_secure_id != auth_token.user_id && user_secure_id != auth_token.authenticator_id) {
  392. LOG_I("Auth token SIDs %llu and %llu do not match key SID %llu", auth_token.user_id,
  393. auth_token.authenticator_id, user_secure_id);
  394. return false;
  395. }
  396. if (auth_type_index < 0 || auth_type_index > static_cast<int>(auth_set.size())) {
  397. LOG_E("Auth required but no auth type found", 0);
  398. return false;
  399. }
  400. assert(auth_set[auth_type_index].tag == KM_TAG_USER_AUTH_TYPE);
  401. if (auth_set[auth_type_index].tag != KM_TAG_USER_AUTH_TYPE)
  402. return false;
  403. uint32_t key_auth_type_mask = auth_set[auth_type_index].integer;
  404. uint32_t token_auth_type = ntoh(auth_token.authenticator_type);
  405. if ((key_auth_type_mask & token_auth_type) == 0) {
  406. LOG_E("Key requires match of auth type mask 0%uo, but token contained 0%uo",
  407. key_auth_type_mask, token_auth_type);
  408. return false;
  409. }
  410. if (auth_timeout_index != -1 && is_begin_operation) {
  411. assert(auth_set[auth_timeout_index].tag == KM_TAG_AUTH_TIMEOUT);
  412. if (auth_set[auth_timeout_index].tag != KM_TAG_AUTH_TIMEOUT)
  413. return false;
  414. if (auth_token_timed_out(auth_token, auth_set[auth_timeout_index].integer)) {
  415. LOG_E("Auth token has timed out", 0);
  416. return false;
  417. }
  418. }
  419. // Survived the whole gauntlet. We have authentage!
  420. return true;
  421. }
  422. bool AccessTimeMap::LastKeyAccessTime(km_id_t keyid, uint32_t* last_access_time) const {
  423. for (auto& entry : last_access_list_)
  424. if (entry.keyid == keyid) {
  425. *last_access_time = entry.access_time;
  426. return true;
  427. }
  428. return false;
  429. }
  430. bool AccessTimeMap::UpdateKeyAccessTime(km_id_t keyid, uint32_t current_time, uint32_t timeout) {
  431. List<AccessTime>::iterator iter;
  432. for (iter = last_access_list_.begin(); iter != last_access_list_.end();) {
  433. if (iter->keyid == keyid) {
  434. iter->access_time = current_time;
  435. return true;
  436. }
  437. // Expire entry if possible.
  438. assert(current_time >= iter->access_time);
  439. if (current_time - iter->access_time >= iter->timeout)
  440. iter = last_access_list_.erase(iter);
  441. else
  442. ++iter;
  443. }
  444. if (last_access_list_.size() >= max_size_)
  445. return false;
  446. AccessTime new_entry;
  447. new_entry.keyid = keyid;
  448. new_entry.access_time = current_time;
  449. new_entry.timeout = timeout;
  450. last_access_list_.push_front(new_entry);
  451. return true;
  452. }
  453. bool AccessCountMap::KeyAccessCount(km_id_t keyid, uint32_t* count) const {
  454. for (auto& entry : access_count_list_)
  455. if (entry.keyid == keyid) {
  456. *count = entry.access_count;
  457. return true;
  458. }
  459. return false;
  460. }
  461. bool AccessCountMap::IncrementKeyAccessCount(km_id_t keyid) {
  462. for (auto& entry : access_count_list_)
  463. if (entry.keyid == keyid) {
  464. // Note that the 'if' below will always be true because KM_TAG_MAX_USES_PER_BOOT is a
  465. // uint32_t, and as soon as entry.access_count reaches the specified maximum value
  466. // operation requests will be rejected and access_count won't be incremented any more.
  467. // And, besides, UINT64_MAX is huge. But we ensure that it doesn't wrap anyway, out of
  468. // an abundance of caution.
  469. if (entry.access_count < UINT64_MAX)
  470. ++entry.access_count;
  471. return true;
  472. }
  473. if (access_count_list_.size() >= max_size_)
  474. return false;
  475. AccessCount new_entry;
  476. new_entry.keyid = keyid;
  477. new_entry.access_count = 1;
  478. access_count_list_.push_front(new_entry);
  479. return true;
  480. }
  481. }; /* namespace keymaster */