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) {} |
| 32 | ~ScopedPathUnlinker() { |
| 33 | if (!base::DeleteFile(file_, false)) { |
| 34 | PLOG(ERROR) << "Unable to unlink path " << file_.value(); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | private: |
| 39 | const base::FilePath file_; |
| 40 | DISALLOW_COPY_AND_ASSIGN(ScopedPathUnlinker); |
| 41 | }; |
| 42 | |
Amin Hassani | b842fa4 | 2018-10-12 15:53:42 -0700 | [diff] [blame] | 43 | // Using |priv_key|, signs |src| file, and writes the digest into |dst|. |
| 44 | bool Sign(const base::FilePath& priv_key, |
| 45 | const base::FilePath& src, |
| 46 | const base::FilePath& dst); |
| 47 | |
| 48 | // Using |priv_key|, signs |src_content|, and writes the digest into |dst|. |
| 49 | bool Sign(const base::FilePath& priv_key, |
| 50 | const std::string& src_content, |
| 51 | const base::FilePath& dst); |
Amin Hassani | 6baacf1 | 2018-09-25 16:31:25 -0700 | [diff] [blame] | 52 | |
Amin Hassani | bea9ab1 | 2018-10-12 17:31:42 -0700 | [diff] [blame] | 53 | // Reads the |pub_key_file| into |pub_key| (a data structure usable by |
| 54 | // libcrypto.) |
| 55 | bool ReadPublicKey(const base::FilePath& pub_key_file, |
| 56 | crypto::ScopedEVP_PKEY* pub_key); |
| 57 | |
| 58 | // Verifies the |signature| of a |message| using the default and already |
| 59 | // verified public key |pub_key|. |
| 60 | bool VerifySignature(const std::string& message, |
| 61 | const std::string& signature, |
| 62 | const crypto::ScopedEVP_PKEY& pub_key); |
| 63 | |
Amin Hassani | fd40bd9 | 2018-09-21 11:03:52 -0700 | [diff] [blame] | 64 | } // namespace oobe_config |
| 65 | |
Amin Hassani | 795cd43 | 2018-10-17 10:30:13 -0700 | [diff] [blame] | 66 | #endif // OOBE_CONFIG_USB_UTILS_H_ |