OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 | |
5 #ifndef EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ | |
6 #define EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/files/file_path.h" | |
13 #include "base/version.h" | |
14 | |
15 namespace extensions { | |
16 | |
17 // This class encapsulates the data in a "verified_contents.json" file | |
18 // generated by the webstore for a .crx file. That data includes a set of | |
19 // signed expected hashes of file content which can be used to check for | |
20 // corruption of extension files on local disk. | |
21 class VerifiedContents { | |
22 public: | |
23 VerifiedContents(const uint8* public_key, int public_key_size); | |
Ken Rockot(use gerrit already)
2014/05/08 20:05:17
nit: I'm a little wary of constructing this over a
asargent_no_longer_on_chrome
2014/05/08 21:05:45
This is going to be used in some performance sensi
| |
24 ~VerifiedContents(); | |
25 | |
26 // Returns true if we successfully parsed the verified_contents.json file at | |
27 // |path| and validated the enclosed signature. The | |
28 // |ignore_invalid_signature| argument can be set to make this still succeed | |
29 // if the contents of the file were parsed successfully but the signature did | |
30 // not validate. (Use with caution!) | |
31 bool InitFrom(const base::FilePath& path, bool ignore_invalid_signature); | |
32 | |
33 int block_size() const { return block_size_; } | |
34 const std::string& extension_id() const { return extension_id_; } | |
35 const base::Version& version() const { return version_; } | |
36 | |
37 // This returns a pointer to the binary form of an expected sha256 root hash | |
38 // for |relative_path| computing using a tree hash algorithm. | |
39 const std::string* GetTreeHashRoot(const base::FilePath& relative_path); | |
40 | |
41 // If InitFrom has not been called yet, or was used in "ignore invalid | |
42 // signature" mode, this can return false. | |
43 bool valid_signature() { return valid_signature_; } | |
44 | |
45 private: | |
46 DISALLOW_COPY_AND_ASSIGN(VerifiedContents); | |
47 | |
48 // Returns the base64url-decoded "payload" field from the json at |path|, if | |
49 // the signature was valid (or ignore_invalid_signature was set to true). | |
50 bool GetPayload(const base::FilePath& path, | |
51 std::string* payload, | |
52 bool ignore_invalid_signature); | |
53 | |
54 // The |protected_value| and |payload| arguments should be base64url encoded | |
55 // strings, and |signature_bytes| should be a byte array. See comments in the | |
56 // .cc file on GetPayload for where these come from in the overall input | |
57 // file. | |
58 bool VerifySignature(const std::string& protected_value, | |
59 const std::string& payload, | |
60 const std::string& signature_bytes); | |
61 | |
62 // The public key we should use for signature verification. | |
63 const uint8* public_key_; | |
64 const int public_key_size_; | |
65 | |
66 // Indicates whether the signature was successfully validated or not. | |
67 bool valid_signature_; | |
68 | |
69 // The block size used for computing the treehash root hashes. | |
70 int block_size_; | |
71 | |
72 // Information about which extension these signed hashes are for. | |
73 std::string extension_id_; | |
74 base::Version version_; | |
75 | |
76 // The expected treehash root hashes for each file. | |
77 std::map<base::FilePath, std::string> root_hashes_; | |
78 }; | |
79 | |
80 } // namespace extensions | |
81 | |
82 #endif // EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ | |
OLD | NEW |