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