blob: e5460594a0dad9ea04268c3bf49e5ae96e5808c3 [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
12#include "base/files/file_path.h"
13#include "base/mac/scoped_cftyperef.h"
kerrnel2b08c52a2015-11-02 23:40:5314#include "base/memory/ref_counted.h"
15#include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incident.h"
16
17namespace safe_browsing {
18
19// Wraps the OS X SecStaticCode API, to evaluate a given file object
20// with a given code requirement, and produce a list of incident reports
21// for files that fail code signature validity checks.
22class MacSignatureEvaluator {
23 public:
24 explicit MacSignatureEvaluator(const base::FilePath& signed_object_path);
25
26 // The requirement string must be a valid "Code Signing Requirement Language
27 // string, which describes the identity of the signer.
28 MacSignatureEvaluator(const base::FilePath& signed_object_path,
29 const std::string& requirement);
30
Peter Boström53c6c5952021-09-17 09:41:2631 MacSignatureEvaluator(const MacSignatureEvaluator&) = delete;
32 MacSignatureEvaluator& operator=(const MacSignatureEvaluator&) = delete;
33
kerrnel2b08c52a2015-11-02 23:40:5334 ~MacSignatureEvaluator();
35
36 // Creates the static code object and requirement string, and returns
37 // true if the object creation succeeds, else false.
38 bool Initialize();
39
40 // Evaluate the signature and return a list of any binary integrity incident
41 // reports. Returns true if and only if the signed code object is valid.
42 bool PerformEvaluation(
43 ClientIncidentReport_IncidentData_BinaryIntegrityIncident* incident);
44
45 // Returns relative path component between a parent and a child.
46 // For example, /foo/bar and /foo/bar/y returns y. Note that
47 // this knows nothing about symlinks. Exposed for testing.
48 static bool GetRelativePathComponent(const base::FilePath& parent,
49 const base::FilePath& child,
50 std::string* out);
51
52 private:
53 // The path to the code object on disk.
54 base::FilePath path_;
55
56 // A Code Signing Requirement string.
57 std::string requirement_str_;
58
59 // Records whether or not a requirement string was specified.
60 bool has_requirement_;
61
62 // The static code object constructed from the code object on disk.
63 base::ScopedCFTypeRef<SecStaticCodeRef> code_;
64
65 // The requirement object constructed from the requirement string.
66 base::ScopedCFTypeRef<SecRequirementRef> requirement_;
kerrnel2b08c52a2015-11-02 23:40:5367};
68
69} // namespace safe_browsing
70
michaelpg33eea592017-01-19 01:34:5671#endif // CHROME_BROWSER_SAFE_BROWSING_SIGNATURE_EVALUATOR_MAC_H_