OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include "base/basictypes.h" | |
11 | 10 |
12 // This function signs a payload with the OS vendor's private key. | 11 #include <base/basictypes.h> |
13 // It takes an update up to the signature blob and returns the signature | 12 |
14 // blob, which should be appended. See update_metadata.proto for more info. | 13 // This class encapsulates methods used for payload signing and signature |
| 14 // verification. See update_metadata.proto for more info. |
15 | 15 |
16 namespace chromeos_update_engine { | 16 namespace chromeos_update_engine { |
17 | 17 |
18 extern const uint32_t kSignatureMessageVersion; | 18 extern const uint32_t kSignatureMessageVersion; |
19 | 19 |
20 class PayloadSigner { | 20 class PayloadSigner { |
21 public: | 21 public: |
| 22 // Given a raw |hash| and a private key in |private_key_path| calculates the |
| 23 // raw signature in |out_signature|. Returns true on success, false otherwise. |
| 24 static bool SignHash(const std::vector<char>& hash, |
| 25 const std::string& private_key_path, |
| 26 std::vector<char>* out_signature); |
| 27 |
| 28 // Given an unsigned payload in |unsigned_payload_path| and a private key in |
| 29 // |private_key_path|, calculates the signature blob into |
| 30 // |out_signature_blob|. Note that the payload must already have an updated |
| 31 // manifest that includes the dummy signature op. Returns true on success, |
| 32 // false otherwise. |
22 static bool SignPayload(const std::string& unsigned_payload_path, | 33 static bool SignPayload(const std::string& unsigned_payload_path, |
23 const std::string& private_key_path, | 34 const std::string& private_key_path, |
24 std::vector<char>* out_signature_blob); | 35 std::vector<char>* out_signature_blob); |
25 | 36 |
26 // Returns the length of out_signature_blob that will result in a call | 37 // Returns the length of out_signature_blob that will result in a call |
27 // to SignPayload with a given private key. Returns true on success. | 38 // to SignPayload with a given private key. Returns true on success. |
28 static bool SignatureBlobLength(const std::string& private_key_path, | 39 static bool SignatureBlobLength(const std::string& private_key_path, |
29 uint64_t* out_length); | 40 uint64_t* out_length); |
30 | 41 |
31 // Returns false if the payload signature can't be verified. Returns true | 42 // Returns false if the payload signature can't be verified. Returns true |
32 // otherwise and sets |out_hash| to the signed payload hash. | 43 // otherwise and sets |out_hash| to the signed payload hash. |
33 static bool VerifySignature(const std::vector<char>& signature_blob, | 44 static bool VerifySignature(const std::vector<char>& signature_blob, |
34 const std::string& public_key_path, | 45 const std::string& public_key_path, |
35 std::vector<char>* out_hash_data); | 46 std::vector<char>* out_hash_data); |
36 | 47 |
| 48 |
| 49 // Given an unsigned payload in |payload_path| (with no dummy signature op) |
| 50 // and the raw |signature_size| calculates the raw hash that needs to be |
| 51 // signed in |out_hash_data|. Returns true on success, false otherwise. |
| 52 static bool HashPayloadForSigning(const std::string& payload_path, |
| 53 int signature_size, |
| 54 std::vector<char>* out_hash_data); |
| 55 |
| 56 // Given an unsigned payload in |payload_path| (with no dummy signature op) |
| 57 // and the raw |signature| updates the payload to include the signature thus |
| 58 // turning it into a signed payload. The new payload is stored in |
| 59 // |signed_payload_path|. |payload_path| and |signed_payload_path| can point |
| 60 // to the same file. Returns true on success, false otherwise. |
| 61 static bool AddSignatureToPayload(const std::string& payload_path, |
| 62 const std::vector<char>& signature, |
| 63 const std::string& signed_payload_path); |
| 64 |
37 private: | 65 private: |
38 // This should never be constructed | 66 // This should never be constructed |
39 DISALLOW_IMPLICIT_CONSTRUCTORS(PayloadSigner); | 67 DISALLOW_IMPLICIT_CONSTRUCTORS(PayloadSigner); |
40 }; | 68 }; |
41 | 69 |
42 } // namespace chromeos_update_engine | 70 } // namespace chromeos_update_engine |
43 | 71 |
44 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__ | 72 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__ |
OLD | NEW |