Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
kerrnel | 2b08c52a | 2015-11-02 23:40:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
michaelpg | 33eea59 | 2017-01-19 01:34:56 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_SAFE_BROWSING_SIGNATURE_EVALUATOR_MAC_H_ |
| 6 | #define CHROME_BROWSER_SAFE_BROWSING_SIGNATURE_EVALUATOR_MAC_H_ |
kerrnel | 2b08c52a | 2015-11-02 23:40:53 | [diff] [blame] | 7 | |
| 8 | #include <Security/Security.h> |
| 9 | |
| 10 | #include <string> |
| 11 | |
Avi Drissman | a09d7dd | 2023-08-17 16:26:58 | [diff] [blame] | 12 | #include "base/apple/scoped_cftyperef.h" |
kerrnel | 2b08c52a | 2015-11-02 23:40:53 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
kerrnel | 2b08c52a | 2015-11-02 23:40:53 | [diff] [blame] | 14 | #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incident.h" |
| 15 | |
| 16 | namespace safe_browsing { |
| 17 | |
Avi Drissman | ec58388 | 2023-05-30 22:57:23 | [diff] [blame] | 18 | // Wraps the macOS SecStaticCode API, to evaluate a given file object |
kerrnel | 2b08c52a | 2015-11-02 23:40:53 | [diff] [blame] | 19 | // with a given code requirement, and produce a list of incident reports |
| 20 | // for files that fail code signature validity checks. |
| 21 | class MacSignatureEvaluator { |
| 22 | public: |
| 23 | explicit MacSignatureEvaluator(const base::FilePath& signed_object_path); |
| 24 | |
| 25 | // The requirement string must be a valid "Code Signing Requirement Language |
| 26 | // string, which describes the identity of the signer. |
| 27 | MacSignatureEvaluator(const base::FilePath& signed_object_path, |
| 28 | const std::string& requirement); |
| 29 | |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 30 | MacSignatureEvaluator(const MacSignatureEvaluator&) = delete; |
| 31 | MacSignatureEvaluator& operator=(const MacSignatureEvaluator&) = delete; |
| 32 | |
kerrnel | 2b08c52a | 2015-11-02 23:40:53 | [diff] [blame] | 33 | ~MacSignatureEvaluator(); |
| 34 | |
| 35 | // Creates the static code object and requirement string, and returns |
| 36 | // true if the object creation succeeds, else false. |
| 37 | bool Initialize(); |
| 38 | |
| 39 | // Evaluate the signature and return a list of any binary integrity incident |
| 40 | // reports. Returns true if and only if the signed code object is valid. |
| 41 | bool PerformEvaluation( |
| 42 | ClientIncidentReport_IncidentData_BinaryIntegrityIncident* incident); |
| 43 | |
| 44 | // Returns relative path component between a parent and a child. |
| 45 | // For example, /foo/bar and /foo/bar/y returns y. Note that |
| 46 | // this knows nothing about symlinks. Exposed for testing. |
| 47 | static bool GetRelativePathComponent(const base::FilePath& parent, |
| 48 | const base::FilePath& child, |
| 49 | std::string* out); |
| 50 | |
| 51 | private: |
| 52 | // The path to the code object on disk. |
| 53 | base::FilePath path_; |
| 54 | |
| 55 | // A Code Signing Requirement string. |
| 56 | std::string requirement_str_; |
| 57 | |
| 58 | // Records whether or not a requirement string was specified. |
| 59 | bool has_requirement_; |
| 60 | |
| 61 | // The static code object constructed from the code object on disk. |
Avi Drissman | 28154a6 | 2023-08-22 04:06:45 | [diff] [blame] | 62 | base::apple::ScopedCFTypeRef<SecStaticCodeRef> code_; |
kerrnel | 2b08c52a | 2015-11-02 23:40:53 | [diff] [blame] | 63 | |
| 64 | // The requirement object constructed from the requirement string. |
Avi Drissman | 28154a6 | 2023-08-22 04:06:45 | [diff] [blame] | 65 | base::apple::ScopedCFTypeRef<SecRequirementRef> requirement_; |
kerrnel | 2b08c52a | 2015-11-02 23:40:53 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace safe_browsing |
| 69 | |
michaelpg | 33eea59 | 2017-01-19 01:34:56 | [diff] [blame] | 70 | #endif // CHROME_BROWSER_SAFE_BROWSING_SIGNATURE_EVALUATOR_MAC_H_ |