| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ | 5 #ifndef EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ |
| 6 #define EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ | 6 #define EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // |path| and validated the enclosed signature. The | 39 // |path| and validated the enclosed signature. The |
| 40 // |ignore_invalid_signature| argument can be set to make this still succeed | 40 // |ignore_invalid_signature| argument can be set to make this still succeed |
| 41 // if the contents of the file were parsed successfully but the signature did | 41 // if the contents of the file were parsed successfully but the signature did |
| 42 // not validate. (Use with caution!) | 42 // not validate. (Use with caution!) |
| 43 bool InitFrom(const base::FilePath& path, bool ignore_invalid_signature); | 43 bool InitFrom(const base::FilePath& path, bool ignore_invalid_signature); |
| 44 | 44 |
| 45 int block_size() const { return block_size_; } | 45 int block_size() const { return block_size_; } |
| 46 const std::string& extension_id() const { return extension_id_; } | 46 const std::string& extension_id() const { return extension_id_; } |
| 47 const base::Version& version() const { return version_; } | 47 const base::Version& version() const { return version_; } |
| 48 | 48 |
| 49 // This returns a pointer to the binary form of an expected sha256 root hash | 49 bool HasTreeHashRoot(const base::FilePath& relative_path) const; |
| 50 // for |relative_path| computing using a tree hash algorithm. | 50 |
| 51 const std::string* GetTreeHashRoot(const base::FilePath& relative_path); | 51 bool TreeHashRootEquals(const base::FilePath& relative_path, |
| 52 const std::string& expected) const; |
| 52 | 53 |
| 53 // If InitFrom has not been called yet, or was used in "ignore invalid | 54 // If InitFrom has not been called yet, or was used in "ignore invalid |
| 54 // signature" mode, this can return false. | 55 // signature" mode, this can return false. |
| 55 bool valid_signature() { return valid_signature_; } | 56 bool valid_signature() { return valid_signature_; } |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 // Returns the base64url-decoded "payload" field from the json at |path|, if | 59 // Returns the base64url-decoded "payload" field from the json at |path|, if |
| 59 // the signature was valid (or ignore_invalid_signature was set to true). | 60 // the signature was valid (or ignore_invalid_signature was set to true). |
| 60 bool GetPayload(const base::FilePath& path, | 61 bool GetPayload(const base::FilePath& path, |
| 61 std::string* payload, | 62 std::string* payload, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 76 // Indicates whether the signature was successfully validated or not. | 77 // Indicates whether the signature was successfully validated or not. |
| 77 bool valid_signature_; | 78 bool valid_signature_; |
| 78 | 79 |
| 79 // The block size used for computing the treehash root hashes. | 80 // The block size used for computing the treehash root hashes. |
| 80 int block_size_; | 81 int block_size_; |
| 81 | 82 |
| 82 // Information about which extension these signed hashes are for. | 83 // Information about which extension these signed hashes are for. |
| 83 std::string extension_id_; | 84 std::string extension_id_; |
| 84 base::Version version_; | 85 base::Version version_; |
| 85 | 86 |
| 86 // The expected treehash root hashes for each file. | 87 // The expected treehash root hashes for each file, lower cased so we can do |
| 87 std::map<base::FilePath, std::string> root_hashes_; | 88 // case-insensitive lookups. |
| 89 // |
| 90 // We use a multi-map here so that we can do fast lookups of paths from |
| 91 // requests on case-insensitive systems (windows, mac) where the request path |
| 92 // might not have the exact right capitalization, but not break |
| 93 // case-sensitive systems (linux, chromeos). TODO(asargent) - we should give |
| 94 // developers client-side warnings in each of those cases, and have the |
| 95 // webstore reject the cases they can statically detect. See crbug.com/29941 |
| 96 typedef std::multimap<base::FilePath::StringType, std::string> RootHashes; |
| 97 RootHashes root_hashes_; |
| 88 | 98 |
| 89 DISALLOW_COPY_AND_ASSIGN(VerifiedContents); | 99 DISALLOW_COPY_AND_ASSIGN(VerifiedContents); |
| 90 }; | 100 }; |
| 91 | 101 |
| 92 } // namespace extensions | 102 } // namespace extensions |
| 93 | 103 |
| 94 #endif // EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ | 104 #endif // EXTENSIONS_BROWSER_VERIFIED_CONTENTS_H_ |
| OLD | NEW |