Alex Deymo | 923d8fa | 2014-07-15 17:58:51 -0700 | [diff] [blame^] | 1 | // Copyright 2014 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 | |
| 5 | #ifndef UPDATE_ENGINE_PAYLOAD_VERIFIER_H_ |
| 6 | #define UPDATE_ENGINE_PAYLOAD_VERIFIER_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/basictypes.h> |
| 12 | #include "update_engine/update_metadata.pb.h" |
| 13 | |
| 14 | // This class encapsulates methods used for payload signature verification. |
| 15 | // See payload_generator/payload_signer.h for payload signing. |
| 16 | |
| 17 | namespace chromeos_update_engine { |
| 18 | |
| 19 | extern const uint32_t kSignatureMessageOriginalVersion; |
| 20 | extern const uint32_t kSignatureMessageCurrentVersion; |
| 21 | |
| 22 | class PayloadVerifier { |
| 23 | public: |
| 24 | // Returns false if the payload signature can't be verified. Returns true |
| 25 | // otherwise and sets |out_hash| to the signed payload hash. |
| 26 | static bool VerifySignature(const std::vector<char>& signature_blob, |
| 27 | const std::string& public_key_path, |
| 28 | std::vector<char>* out_hash_data); |
| 29 | |
| 30 | // Interprets signature_blob as a protocol buffer containing the Signatures |
| 31 | // message and decrypts the signature data using the public_key_path and |
| 32 | // stores the resultant raw hash data in out_hash_data. Returns true if |
| 33 | // everything is successful. False otherwise. It also takes the client_version |
| 34 | // and interprets the signature blob according to that version. |
| 35 | static bool VerifySignatureBlob(const std::vector<char>& signature_blob, |
| 36 | const std::string& public_key_path, |
| 37 | uint32_t client_version, |
| 38 | std::vector<char>* out_hash_data); |
| 39 | |
| 40 | // Decrypts sig_data with the given public_key_path and populates |
| 41 | // out_hash_data with the decoded raw hash. Returns true if successful, |
| 42 | // false otherwise. |
| 43 | static bool GetRawHashFromSignature(const std::vector<char>& sig_data, |
| 44 | const std::string& public_key_path, |
| 45 | std::vector<char>* out_hash_data); |
| 46 | |
| 47 | // Returns true if the payload in |payload_path| is signed and its hash can be |
| 48 | // verified using the public key in |public_key_path| with the signature |
| 49 | // of a given version in the signature blob. Returns false otherwise. |
| 50 | static bool VerifySignedPayload(const std::string& payload_path, |
| 51 | const std::string& public_key_path, |
| 52 | uint32_t client_key_check_version); |
| 53 | |
| 54 | // Pads a SHA256 hash so that it may be encrypted/signed with RSA2048 |
| 55 | // using the PKCS#1 v1.5 scheme. |
| 56 | // hash should be a pointer to vector of exactly 256 bits. The vector |
| 57 | // will be modified in place and will result in having a length of |
| 58 | // 2048 bits. Returns true on success, false otherwise. |
| 59 | static bool PadRSA2048SHA256Hash(std::vector<char>* hash); |
| 60 | |
| 61 | // Reads the payload from the given |payload_path| into the |out_payload| |
| 62 | // vector. It also parses the manifest protobuf in the payload and returns it |
| 63 | // in |out_manifest| along with the size of the entire metadata in |
| 64 | // |out_metadata_size|. |
| 65 | static bool LoadPayload(const std::string& payload_path, |
| 66 | std::vector<char>* out_payload, |
| 67 | DeltaArchiveManifest* out_manifest, |
| 68 | uint64_t* out_metadata_size); |
| 69 | |
| 70 | private: |
| 71 | // This should never be constructed |
| 72 | DISALLOW_IMPLICIT_CONSTRUCTORS(PayloadVerifier); |
| 73 | }; |
| 74 | |
| 75 | } // namespace chromeos_update_engine |
| 76 | |
| 77 | #endif // UPDATE_ENGINE_PAYLOAD_VERIFIER_H_ |