blob: 408db2a3517434b3ec0d4bdda4ff0ebddd2ff11a [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) {}
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 Hassanib842fa42018-10-12 15:53:42 -070043// Using |priv_key|, signs |src| file, and writes the digest into |dst|.
44bool 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|.
49bool Sign(const base::FilePath& priv_key,
50 const std::string& src_content,
51 const base::FilePath& dst);
Amin Hassani6baacf12018-09-25 16:31:25 -070052
Amin Hassanibea9ab12018-10-12 17:31:42 -070053// Reads the |pub_key_file| into |pub_key| (a data structure usable by
54// libcrypto.)
55bool 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|.
60bool VerifySignature(const std::string& message,
61 const std::string& signature,
62 const crypto::ScopedEVP_PKEY& pub_key);
63
Amin Hassanifd40bd92018-09-21 11:03:52 -070064} // namespace oobe_config
65
Amin Hassani795cd432018-10-17 10:30:13 -070066#endif // OOBE_CONFIG_USB_UTILS_H_