blob: 8caef35696bc4f4851b8161495326942c76e1078 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2014 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Alex Deymo923d8fa2014-07-15 17:58:51 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_PAYLOAD_VERIFIER_H_
18#define UPDATE_ENGINE_PAYLOAD_CONSUMER_PAYLOAD_VERIFIER_H_
Alex Deymo923d8fa2014-07-15 17:58:51 -070019
20#include <string>
Alex Deymo923d8fa2014-07-15 17:58:51 -070021
Ben Chan05735a12014-09-03 07:48:22 -070022#include <base/macros.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070023#include <brillo/secure_blob.h>
Ben Chan05735a12014-09-03 07:48:22 -070024
Alex Deymo923d8fa2014-07-15 17:58:51 -070025#include "update_engine/update_metadata.pb.h"
26
27// This class encapsulates methods used for payload signature verification.
28// See payload_generator/payload_signer.h for payload signing.
29
30namespace chromeos_update_engine {
31
Alex Deymo923d8fa2014-07-15 17:58:51 -070032class PayloadVerifier {
33 public:
Alex Deymob552a682015-09-30 09:36:49 -070034 // Interprets |signature_blob| as a protocol buffer containing the Signatures
35 // message and decrypts each signature data using the |public_key_path|.
36 // Returns whether *any* of the decrypted hashes matches the |hash_data|.
37 // In case of any error parsing the signatures or the public key, returns
38 // false.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070039 static bool VerifySignature(const brillo::Blob& signature_blob,
Alex Deymo923d8fa2014-07-15 17:58:51 -070040 const std::string& public_key_path,
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070041 const brillo::Blob& hash_data);
Alex Deymo923d8fa2014-07-15 17:58:51 -070042
43 // Decrypts sig_data with the given public_key_path and populates
44 // out_hash_data with the decoded raw hash. Returns true if successful,
45 // false otherwise.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070046 static bool GetRawHashFromSignature(const brillo::Blob& sig_data,
Alex Deymo923d8fa2014-07-15 17:58:51 -070047 const std::string& public_key_path,
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070048 brillo::Blob* out_hash_data);
Alex Deymo923d8fa2014-07-15 17:58:51 -070049
Alex Deymo923d8fa2014-07-15 17:58:51 -070050 // Pads a SHA256 hash so that it may be encrypted/signed with RSA2048
51 // using the PKCS#1 v1.5 scheme.
52 // hash should be a pointer to vector of exactly 256 bits. The vector
53 // will be modified in place and will result in having a length of
54 // 2048 bits. Returns true on success, false otherwise.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070055 static bool PadRSA2048SHA256Hash(brillo::Blob* hash);
Alex Deymo923d8fa2014-07-15 17:58:51 -070056
Alex Deymo923d8fa2014-07-15 17:58:51 -070057 private:
58 // This should never be constructed
59 DISALLOW_IMPLICIT_CONSTRUCTORS(PayloadVerifier);
60};
61
62} // namespace chromeos_update_engine
63
Alex Deymo39910dc2015-11-09 17:04:30 -080064#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_PAYLOAD_VERIFIER_H_