crx_build_action_main.cc 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2021 The Chromium 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. #include <cstdint>
  5. #include <string>
  6. #include <vector>
  7. #include "base/files/file_path.h"
  8. #include "base/files/file_util.h"
  9. #include "base/logging.h"
  10. #include "components/crx_file/crx_creator.h"
  11. #include "crypto/rsa_private_key.h"
  12. // This program, invoked via `crx_build_action out zip key` constructs a CRX3 at
  13. // `out` from the input zip archive at `zip` and signed with the key at `key`.
  14. // The file at `key` should be a DER-formatted PKCS #8 PrivateKeyInfo block.
  15. //
  16. // Consult crx3.gni for more information.
  17. int main(int argc, char* argv[]) {
  18. std::string key_file;
  19. if (!base::ReadFileToString(base::FilePath::FromASCII(argv[3]), &key_file)) {
  20. VLOG(0) << "Failed to read key material from " << argv[3];
  21. return -1;
  22. }
  23. return static_cast<int>(crx_file::Create(
  24. base::FilePath::FromASCII(argv[1]), base::FilePath::FromASCII(argv[2]),
  25. crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(
  26. std::vector<uint8_t>(key_file.begin(), key_file.end()))
  27. .get()));
  28. }