Amin Hassani | fd40bd9 | 2018-09-21 11:03:52 -0700 | [diff] [blame] | 1 | // 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 Hassani | 795cd43 | 2018-10-17 10:30:13 -0700 | [diff] [blame] | 5 | #ifndef OOBE_CONFIG_USB_UTILS_H_ |
| 6 | #define OOBE_CONFIG_USB_UTILS_H_ |
Amin Hassani | fd40bd9 | 2018-09-21 11:03:52 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Amin Hassani | 6baacf1 | 2018-09-25 16:31:25 -0700 | [diff] [blame] | 11 | #include <base/files/file_path.h> |
Amin Hassani | 3bf1577 | 2018-10-12 15:37:54 -0700 | [diff] [blame] | 12 | #include <base/files/file_util.h> |
Amin Hassani | bea9ab1 | 2018-10-12 17:31:42 -0700 | [diff] [blame] | 13 | #include <crypto/scoped_openssl_types.h> |
Amin Hassani | 6baacf1 | 2018-09-25 16:31:25 -0700 | [diff] [blame] | 14 | |
Amin Hassani | fd40bd9 | 2018-09-21 11:03:52 -0700 | [diff] [blame] | 15 | namespace oobe_config { |
| 16 | |
Amin Hassani | 795cd43 | 2018-10-17 10:30:13 -0700 | [diff] [blame] | 17 | extern const char kStatefulDir[]; |
| 18 | extern const char kUnencryptedOobeConfigDir[]; |
| 19 | extern const char kConfigFile[]; |
| 20 | extern const char kDomainFile[]; |
| 21 | extern const char kKeyFile[]; |
| 22 | extern const char kDevDiskById[]; |
| 23 | extern const char kUsbDevicePathSigFile[]; |
Amin Hassani | eec38f3 | 2018-11-27 17:41:51 -0800 | [diff] [blame] | 24 | extern const char kStoreDir[]; |
| 25 | extern const char kOobeConfigRestoreUser[]; |
Amin Hassani | 795cd43 | 2018-10-17 10:30:13 -0700 | [diff] [blame] | 26 | |
Amin Hassani | 3bf1577 | 2018-10-12 15:37:54 -0700 | [diff] [blame] | 27 | // 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. |
| 29 | class ScopedPathUnlinker { |
| 30 | public: |
| 31 | explicit ScopedPathUnlinker(const base::FilePath& file) : file_(file) {} |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 32 | ScopedPathUnlinker(const ScopedPathUnlinker&) = delete; |
| 33 | ScopedPathUnlinker& operator=(const ScopedPathUnlinker&) = delete; |
| 34 | |
Amin Hassani | 3bf1577 | 2018-10-12 15:37:54 -0700 | [diff] [blame] | 35 | ~ScopedPathUnlinker() { |
hscham | 53cf73a | 2020-11-30 15:58:42 +0900 | [diff] [blame] | 36 | if (!base::DeleteFile(file_)) { |
Amin Hassani | 3bf1577 | 2018-10-12 15:37:54 -0700 | [diff] [blame] | 37 | PLOG(ERROR) << "Unable to unlink path " << file_.value(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | const base::FilePath file_; |
Amin Hassani | 3bf1577 | 2018-10-12 15:37:54 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Amin Hassani | b842fa4 | 2018-10-12 15:53:42 -0700 | [diff] [blame] | 45 | // Using |priv_key|, signs |src| file, and writes the digest into |dst|. |
| 46 | bool 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|. |
| 51 | bool Sign(const base::FilePath& priv_key, |
| 52 | const std::string& src_content, |
| 53 | const base::FilePath& dst); |
Amin Hassani | 6baacf1 | 2018-09-25 16:31:25 -0700 | [diff] [blame] | 54 | |
Amin Hassani | bea9ab1 | 2018-10-12 17:31:42 -0700 | [diff] [blame] | 55 | // Reads the |pub_key_file| into |pub_key| (a data structure usable by |
| 56 | // libcrypto.) |
| 57 | bool 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|. |
| 62 | bool VerifySignature(const std::string& message, |
| 63 | const std::string& signature, |
| 64 | const crypto::ScopedEVP_PKEY& pub_key); |
| 65 | |
Amin Hassani | fd40bd9 | 2018-09-21 11:03:52 -0700 | [diff] [blame] | 66 | } // namespace oobe_config |
| 67 | |
Amin Hassani | 795cd43 | 2018-10-17 10:30:13 -0700 | [diff] [blame] | 68 | #endif // OOBE_CONFIG_USB_UTILS_H_ |