blob: 59affd3d438babbaf91ca20e1a635d3b5fa9cb9d [file] [log] [blame]
Andrew de los Reyes0c440052010-08-20 11:25:54 -07001// 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
3// found in the LICENSE file.
4
5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__
7
8#include <string>
9#include <vector>
10#include "base/basictypes.h"
11
12// This function signs a payload with the OS vendor's private key.
13// It takes an update up to the signature blob and returns the signature
14// blob, which should be appended. See update_metadata.proto for more info.
15
16namespace chromeos_update_engine {
17
18extern const uint32_t kSignatureMessageVersion;
19
20class PayloadSigner {
21 public:
22 static bool SignPayload(const std::string& unsigned_payload_path,
23 const std::string& private_key_path,
24 std::vector<char>* out_signature_blob);
25
26 // 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.
28 static bool SignatureBlobLength(const std::string& private_key_path,
29 uint64_t* out_length);
30
Darin Petkovd7061ab2010-10-06 14:37:09 -070031 // Returns false if the payload signature can't be verified. Returns true
32 // otherwise and sets |out_hash| to the signed payload hash.
33 static bool VerifySignature(const std::vector<char>& signature_blob,
34 const std::string& public_key_path,
35 std::vector<char>* out_hash_data);
36
Andrew de los Reyes0c440052010-08-20 11:25:54 -070037 private:
38 // This should never be constructed
39 DISALLOW_IMPLICIT_CONSTRUCTORS(PayloadSigner);
40};
41
42} // namespace chromeos_update_engine
43
44#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_SIGNER_H__