blob: 19b8c0160ad7d1215b562500a116ce044c041d5e [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2015 The Chromium Authors
kerrnel2b08c52a2015-11-02 23:40:532// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
michaelpg33eea592017-01-19 01:34:565#ifndef CHROME_BROWSER_SAFE_BROWSING_SIGNATURE_EVALUATOR_MAC_H_
6#define CHROME_BROWSER_SAFE_BROWSING_SIGNATURE_EVALUATOR_MAC_H_
kerrnel2b08c52a2015-11-02 23:40:537
8#include <Security/Security.h>
9
10#include <string>
11
Avi Drissmana09d7dd2023-08-17 16:26:5812#include "base/apple/scoped_cftyperef.h"
kerrnel2b08c52a2015-11-02 23:40:5313#include "base/files/file_path.h"
kerrnel2b08c52a2015-11-02 23:40:5314#include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incident.h"
15
16namespace safe_browsing {
17
Avi Drissmanec583882023-05-30 22:57:2318// Wraps the macOS SecStaticCode API, to evaluate a given file object
kerrnel2b08c52a2015-11-02 23:40:5319// with a given code requirement, and produce a list of incident reports
20// for files that fail code signature validity checks.
21class 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öm53c6c5952021-09-17 09:41:2630 MacSignatureEvaluator(const MacSignatureEvaluator&) = delete;
31 MacSignatureEvaluator& operator=(const MacSignatureEvaluator&) = delete;
32
kerrnel2b08c52a2015-11-02 23:40:5333 ~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 Drissman28154a62023-08-22 04:06:4562 base::apple::ScopedCFTypeRef<SecStaticCodeRef> code_;
kerrnel2b08c52a2015-11-02 23:40:5363
64 // The requirement object constructed from the requirement string.
Avi Drissman28154a62023-08-22 04:06:4565 base::apple::ScopedCFTypeRef<SecRequirementRef> requirement_;
kerrnel2b08c52a2015-11-02 23:40:5366};
67
68} // namespace safe_browsing
69
michaelpg33eea592017-01-19 01:34:5670#endif // CHROME_BROWSER_SAFE_BROWSING_SIGNATURE_EVALUATOR_MAC_H_