1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//! Capability SID → friendly-name resolution.
//!
//! Brokered-capability denials (see [`crate::learning_mode_windows::extractors`]) identify the
//! denied capability by its *capability SID*, not by name. AppContainer
//! capability SIDs live under the well-known `S-1-15-3-…` domain, and there
//! is no OS reverse API — Windows only exposes `DeriveCapabilitySidsFromName`
//! (name → SID). So resolution splits two ways:
//!
//! - A small set of **legacy** capabilities have short, fixed RIDs
//! (`S-1-15-3-1` == `internetClient`, `S-1-15-3-3` ==
//! `privateNetworkClientServer`, …). Those are enumerated in
//! [`WELL_KNOWN`] and resolve to a human-readable name.
//! - Every **modern / custom** capability SID is derived by hashing the
//! capability's UTF-16 name into four 32-bit RIDs (`S-1-15-3-w-x-y-z`).
//! That hash is one-way, so we cannot recover the name — we surface the
//! SID string verbatim, which is still a stable, greppable identifier a
//! consumer can map back to a policy entry.
//!
//! Only the friendly name is directly consumable when a host regenerates its
//! sandbox policy, because the policy `capabilities` field is name-based
//! (MXC converts names → SIDs at launch, never the reverse). Resolving the
//! well-known network/library capabilities — the ones MXC actually uses — is
//! therefore what makes a capability denial actionable for config
//! regeneration; the SID fallback is a best-effort diagnostic identifier.
//!
//! [`resolve`] is the single entry point: it maps a canonical SID string to
//! the friendly name when known, otherwise echoes the SID unchanged.
/// Legacy AppContainer capability SIDs with well-known short RIDs, paired
/// with the capability name used in sandbox policy.
///
/// The RID is the single sub-authority following the `S-1-15-3-` prefix.
/// Names match the manifest / `SandboxPolicy` capability identifiers so a
/// consumer can feed a resolved denial straight back into policy.
const WELL_KNOWN: & = &;
/// Resolves a capability SID string to a friendly capability name.
///
/// Accepts a canonical SID string (as produced by the TDH SID decoder, e.g.
/// `S-1-15-3-1`). Returns the well-known capability name when the SID is a
/// legacy `S-1-15-3-<rid>` with a recognised RID; otherwise returns the
/// input SID unchanged (custom capability SIDs are one-way hashes and cannot
/// be reversed). A non-SID input is echoed back untouched.
/// Returns the single RID of a legacy `S-1-15-3-<rid>` capability SID.
///
/// Returns `None` for anything that is not exactly a three-part
/// `S-1-15-3-<rid>` SID (custom capabilities carry four hashed RIDs and are
/// intentionally excluded).