#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/persistence/linux_key_persistence_delegate.h"
#include <fcntl.h>
#include <grp.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <optional>
#include <string>
#include <utility>
#include "base/base64.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/posix/eintr_wrapper.h"
#include "base/syslog_logging.h"
#include "base/values.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/ec_signing_key.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/persistence/metrics_utils.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/shared_command_constants.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/signing_key_pair.h"
#include "components/policy/core/common/policy_paths.h"
#include "components/policy/proto/device_management_backend.pb.h"
#include "crypto/unexportable_key.h"
BPKUR;
BPKUP;
namespace enterprise_connectors {
namespace {
constexpr int kFileMode = …;
constexpr int kMaxBufferSize = …;
constexpr char kSigningKeyName[] = …;
constexpr char kSigningKeyTrustLevel[] = …;
std::optional<base::FilePath>& GetTestFilePathStorage() { … }
base::FilePath GetSigningKeyFilePath() { … }
base::File OpenSigningKeyFile(uint32_t flags) { … }
bool RecordFailure(KeyPersistenceOperation operation,
KeyPersistenceError error,
const std::string& log_message) { … }
}
LinuxKeyPersistenceDelegate::LinuxKeyPersistenceDelegate() = default;
LinuxKeyPersistenceDelegate::~LinuxKeyPersistenceDelegate() = default;
bool LinuxKeyPersistenceDelegate::CheckRotationPermissions() { … }
bool LinuxKeyPersistenceDelegate::StoreKeyPair(
KeyPersistenceDelegate::KeyTrustLevel trust_level,
std::vector<uint8_t> wrapped) { … }
scoped_refptr<SigningKeyPair> LinuxKeyPersistenceDelegate::LoadKeyPair(
KeyStorageType type,
LoadPersistedKeyResult* result) { … }
scoped_refptr<SigningKeyPair> LinuxKeyPersistenceDelegate::CreateKeyPair() { … }
bool LinuxKeyPersistenceDelegate::PromoteTemporaryKeyPair() { … }
bool LinuxKeyPersistenceDelegate::DeleteKeyPair(KeyStorageType type) { … }
void LinuxKeyPersistenceDelegate::SetFilePathForTesting(
const base::FilePath& file_path) { … }
}