apple_codesign/
entitlements.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5/*! Code entitlements handling. */
6
7use {crate::code_directory::ExecutableSegmentFlags, plist::Value};
8
9/// Convert an entitlements plist to [ExecutableSegmentFlags].
10///
11/// Some entitlements plist values imply features in executable segment flags.
12/// This function resolves those implied features.
13pub fn plist_to_executable_segment_flags(value: &Value) -> ExecutableSegmentFlags {
14    let mut flags = ExecutableSegmentFlags::empty();
15
16    if let Value::Dictionary(d) = value {
17        if matches!(d.get("get-task-allow"), Some(Value::Boolean(true))) {
18            flags |= ExecutableSegmentFlags::ALLOW_UNSIGNED;
19        }
20        if matches!(d.get("run-unsigned-code"), Some(Value::Boolean(true))) {
21            flags |= ExecutableSegmentFlags::ALLOW_UNSIGNED;
22        }
23        if matches!(
24            d.get("com.apple.private.cs.debugger"),
25            Some(Value::Boolean(true))
26        ) {
27            flags |= ExecutableSegmentFlags::DEBUGGER;
28        }
29        if matches!(d.get("dynamic-codesigning"), Some(Value::Boolean(true))) {
30            flags |= ExecutableSegmentFlags::JIT;
31        }
32        if matches!(
33            d.get("com.apple.private.skip-library-validation"),
34            Some(Value::Boolean(true))
35        ) {
36            flags |= ExecutableSegmentFlags::SKIP_LIBRARY_VALIDATION;
37        }
38        if matches!(
39            d.get("com.apple.private.amfi.can-load-cdhash"),
40            Some(Value::Boolean(true))
41        ) {
42            flags |= ExecutableSegmentFlags::CAN_LOAD_CD_HASH;
43        }
44        if matches!(
45            d.get("com.apple.private.amfi.can-execute-cdhash"),
46            Some(Value::Boolean(true))
47        ) {
48            flags |= ExecutableSegmentFlags::CAN_EXEC_CD_HASH;
49        }
50    }
51
52    flags
53}