blob: e171ab34d409c9a04a15c26dac0600eaeca3ab27 [file] [log] [blame]
Tonko Sabolčec43615a92018-09-12 12:43:411// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_OS_CRYPT_ENCRYPTION_KEY_CREATION_UTIL_H_
6#define COMPONENTS_OS_CRYPT_ENCRYPTION_KEY_CREATION_UTIL_H_
7
8#include "base/component_export.h"
9
Vasilii Sukhanov5bb3b4682018-12-04 12:00:0410namespace crypto {
11class AppleKeychain;
12}
13
Tonko Sabolčec43615a92018-09-12 12:43:4114namespace os_crypt {
15
Vasilii Sukhanovf1ab9382018-11-22 15:54:5316// An interface for the utility that logs statistics on the encryption key on
Tonko Sabolčec43615a92018-09-12 12:43:4117// Mac.
Vasilii Sukhanovf1ab9382018-11-22 15:54:5318// This class is used on Mac and iOS, but does nothing on iOS. The object for
Tonko Sabolčec43615a92018-09-12 12:43:4119// the Mac class has to be created on the main thread.
20class EncryptionKeyCreationUtil {
21 public:
Vasilii Sukhanovf1ab9382018-11-22 15:54:5322 // The action that is taken by KeychainPassword::GetPassword method.
Tonko Sabolčecb32d0552018-09-13 14:27:1323 // This enum is used for reporting metrics.
24 enum class GetKeyAction {
25 // Key was found in the Keychain and the preference that it was created in
26 // the past is set.
27 kKeyFound = 0,
28 // Key was found in the Keychain, but the preference that it was created in
Vasilii Sukhanovf1ab9382018-11-22 15:54:5329 // the past was not set.
Tonko Sabolčecb32d0552018-09-13 14:27:1330 kKeyFoundFirstTime = 1,
Vasilii Sukhanovf1ab9382018-11-22 15:54:5331 kOverwritingPrevented_OBSOLETE = 2,
Tonko Sabolčecb32d0552018-09-13 14:27:1332 // Key was added to the Keychain and the preference is set.
33 kNewKeyAddedToKeychain = 3,
Vasilii Sukhanovf1ab9382018-11-22 15:54:5334 // Some other error occurred during lookup.
Tonko Sabolčecb32d0552018-09-13 14:27:1335 kKeychainLookupFailed = 4,
Vasilii Sukhanovf1ab9382018-11-22 15:54:5336 // The preference was set but a new key was added to the Keychain.
37 kKeyPotentiallyOverwritten = 5,
38 // The preference was set but a new key was not created due to an error.
39 kKeyOverwriteFailed = 6,
40 // A new key should be created but an error occured.
41 kNewKeyAddError = 7,
42 kMaxValue = kNewKeyAddError,
Tonko Sabolčecb32d0552018-09-13 14:27:1343 };
44
Vasilii Sukhanov5bb3b4682018-12-04 12:00:0445 // Result of FindGenericPassword. This enum is used for reporting metrics.
46 // These values are persisted to logs. Entries should not be renumbered and
47 // numeric values should never be reused.
48 enum class FindPasswordResult {
49 kOtherError = 0,
50 kFound = 1,
51 kNotFound = 2,
52 kMaxValue = kNotFound,
53 };
54
Tonko Sabolčec43615a92018-09-12 12:43:4155 virtual ~EncryptionKeyCreationUtil() = default;
56
Tonko Sabolčecb32d0552018-09-13 14:27:1357 // This method is called when the encryption key is successfully retrieved
Vasilii Sukhanovf1ab9382018-11-22 15:54:5358 // from the Keychain. If this is called for the very first time, it
Tonko Sabolčecb32d0552018-09-13 14:27:1359 // asynchronously updates the preference on the main thread that the key was
60 // created. This method doesn't need to be called on the main thread.
Vasilii Sukhanovf1ab9382018-11-22 15:54:5361 virtual void OnKeyWasFound() = 0;
Tonko Sabolčecb32d0552018-09-13 14:27:1362
Vasilii Sukhanov5bb3b4682018-12-04 12:00:0463 // Called when the encryption key was not in the Keychain just before a new
64 // key is stored. This method doesn't need to be called on the main thread.
65 virtual void OnKeyNotFound(const crypto::AppleKeychain& keychain) = 0;
66
Vasilii Sukhanovf1ab9382018-11-22 15:54:5367 // Called when the encryption key was not in the Keychain. |new_key_stored|
68 // is true iff a new key was stored successfully. This method doesn't need to
69 // be called on the main thread.
Vasilii Sukhanov5bb3b4682018-12-04 12:00:0470 virtual void OnKeyStored(bool new_key_stored) = 0;
Tonko Sabolčecb32d0552018-09-13 14:27:1371
72 // This method is called when the Keychain returns error other than
73 // errSecItemNotFound (e.g., user is not authorized to use Keychain, or
74 // Keychain is unavailable for some other reasons).
Vasilii Sukhanov5bb3b4682018-12-04 12:00:0475 virtual void OnKeychainLookupFailed(int error) = 0;
Tonko Sabolčec43615a92018-09-12 12:43:4176};
77
78} // namespace os_crypt
79
80#endif // COMPONENTS_OS_CRYPT_ENCRYPTION_KEY_CREATION_UTIL_H_