blob: 83168c91aa0c57a5bd1d31c0fe6146458a71040b [file] [log] [blame]
Amin Hassanifd40bd92018-09-21 11:03:52 -07001// Copyright 2018 The Chromium OS 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
Amin Hassani795cd432018-10-17 10:30:13 -07005#ifndef OOBE_CONFIG_USB_UTILS_H_
6#define OOBE_CONFIG_USB_UTILS_H_
Amin Hassanifd40bd92018-09-21 11:03:52 -07007
8#include <string>
9#include <vector>
10
Amin Hassani6baacf12018-09-25 16:31:25 -070011#include <base/files/file_path.h>
Amin Hassani3bf15772018-10-12 15:37:54 -070012#include <base/files/file_util.h>
Amin Hassanibea9ab12018-10-12 17:31:42 -070013#include <crypto/scoped_openssl_types.h>
Amin Hassani6baacf12018-09-25 16:31:25 -070014
Amin Hassanifd40bd92018-09-21 11:03:52 -070015namespace oobe_config {
16
Amin Hassani795cd432018-10-17 10:30:13 -070017extern const char kStatefulDir[];
18extern const char kUnencryptedOobeConfigDir[];
19extern const char kConfigFile[];
20extern const char kDomainFile[];
21extern const char kKeyFile[];
22extern const char kDevDiskById[];
23extern const char kUsbDevicePathSigFile[];
Amin Hassanieec38f32018-11-27 17:41:51 -080024extern const char kStoreDir[];
25extern const char kOobeConfigRestoreUser[];
Amin Hassani795cd432018-10-17 10:30:13 -070026
Amin Hassani3bf15772018-10-12 15:37:54 -070027// Use of this class removes a file after it goes out of scope. This means we do
28// not have to worry about keeping tracking which files to delete when.
29class ScopedPathUnlinker {
30 public:
31 explicit ScopedPathUnlinker(const base::FilePath& file) : file_(file) {}
Qijiang Fan6bc59e12020-11-11 02:51:06 +090032 ScopedPathUnlinker(const ScopedPathUnlinker&) = delete;
33 ScopedPathUnlinker& operator=(const ScopedPathUnlinker&) = delete;
34
Amin Hassani3bf15772018-10-12 15:37:54 -070035 ~ScopedPathUnlinker() {
hscham53cf73a2020-11-30 15:58:42 +090036 if (!base::DeleteFile(file_)) {
Amin Hassani3bf15772018-10-12 15:37:54 -070037 PLOG(ERROR) << "Unable to unlink path " << file_.value();
38 }
39 }
40
41 private:
42 const base::FilePath file_;
Amin Hassani3bf15772018-10-12 15:37:54 -070043};
44
Amin Hassanib842fa42018-10-12 15:53:42 -070045// Using |priv_key|, signs |src| file, and writes the digest into |dst|.
46bool Sign(const base::FilePath& priv_key,
47 const base::FilePath& src,
48 const base::FilePath& dst);
49
50// Using |priv_key|, signs |src_content|, and writes the digest into |dst|.
51bool Sign(const base::FilePath& priv_key,
52 const std::string& src_content,
53 const base::FilePath& dst);
Amin Hassani6baacf12018-09-25 16:31:25 -070054
Amin Hassanibea9ab12018-10-12 17:31:42 -070055// Reads the |pub_key_file| into |pub_key| (a data structure usable by
56// libcrypto.)
57bool ReadPublicKey(const base::FilePath& pub_key_file,
58 crypto::ScopedEVP_PKEY* pub_key);
59
60// Verifies the |signature| of a |message| using the default and already
61// verified public key |pub_key|.
62bool VerifySignature(const std::string& message,
63 const std::string& signature,
64 const crypto::ScopedEVP_PKEY& pub_key);
65
Amin Hassanifd40bd92018-09-21 11:03:52 -070066} // namespace oobe_config
67
Amin Hassani795cd432018-10-17 10:30:13 -070068#endif // OOBE_CONFIG_USB_UTILS_H_