@oxy.so/app-preset 6.2.0 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/bin/oxy-check-keychain-entitlements.js +170 -0
- package/package.json +7 -1
- package/plugin/oxyKeychainGroups.js +207 -46
- package/plugin/withOxyBuildProperties.js +1 -0
- package/plugin/withOxyKeychain.js +21 -7
package/README.md
CHANGED
|
@@ -82,8 +82,8 @@ plugins: [
|
|
|
82
82
|
|
|
83
83
|
This adds the iOS `keychain-access-groups` entitlement
|
|
84
84
|
(`$(AppIdentifierPrefix)group.so.oxy.shared`; only Commons and the Peable wallet get
|
|
85
|
-
more,
|
|
86
|
-
|
|
85
|
+
more, their `.dev` builds the `.dev` groups — ADR 0062 of the oxy repo, see
|
|
86
|
+
[Keychain access groups](#keychain-access-groups)), the Oxy `expo-build-properties`
|
|
87
87
|
defaults (iOS `deploymentTarget 16.4`; Android ProGuard + resource shrinking — the
|
|
88
88
|
Android compile/target SDK and build tools are the Expo SDK's own, never pinned here), and `@oxy.so/services/plugins/withOxySharedPermissions`:
|
|
89
89
|
the app declares and requests the signature-level `so.oxy.permission.IDENTITY` and
|
|
@@ -102,6 +102,30 @@ The iOS and build-property pieces are overridable:
|
|
|
102
102
|
}]
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
+
##### Keychain access groups
|
|
106
|
+
|
|
107
|
+
Since 6.4.0 an app's `keychain-access-groups` must be EXACTLY its bundle id's list, in
|
|
108
|
+
order (the first entry is the default group, which decides the app's role):
|
|
109
|
+
|
|
110
|
+
| Bundle id | Groups (each `$(AppIdentifierPrefix)<group>`) |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `so.oxy.commons` | `so.oxy.identity`, `so.oxy.wallet`, `group.so.oxy.shared` |
|
|
113
|
+
| `so.oxy.commons.dev` | `so.oxy.identity.dev`, `so.oxy.wallet.dev`, `group.so.oxy.shared` |
|
|
114
|
+
| `to.peable.app` | `so.oxy.wallet`, `group.so.oxy.shared` |
|
|
115
|
+
| `to.peable.app.dev` | `so.oxy.wallet.dev`, `group.so.oxy.shared` |
|
|
116
|
+
| every other app | `group.so.oxy.shared` |
|
|
117
|
+
|
|
118
|
+
optionally followed by the app's own `$(AppIdentifierPrefix)<its bundle id>` (a holder may
|
|
119
|
+
also still list the shared group alone, before its split build). Anything else fails
|
|
120
|
+
prebuild, in particular another app's bundle id: `<TEAM>.<bundle id>` is that app's private
|
|
121
|
+
group, where its session lives. Each entry is spelled exactly `$(AppIdentifierPrefix)<group>`.
|
|
122
|
+
The check runs at prebuild (`withOxyKeychain`, and `withOxyKeychainPolicy` through
|
|
123
|
+
`withOxyUpdates` for apps that declare `ios.entitlements` themselves), and
|
|
124
|
+
`oxy-check-keychain-entitlements <bundle-id> <ios-dir-or-file> [--team-id <TEAMID>]` runs it
|
|
125
|
+
over what a prebuild or a codesign wrote: Oxy's shared native release workflow runs it on
|
|
126
|
+
every release, which therefore needs this package at 6.4.0 or later.
|
|
127
|
+
See `docs/identity/ios-keychain-access-groups.md` in the oxy repo.
|
|
128
|
+
|
|
105
129
|
##### Dropping React Native's GIF / WebP decoders (opt-in, Expo SDK 58+)
|
|
106
130
|
|
|
107
131
|
An app that renders no GIF and no animated WebP through react-native's own
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* oxy-check-keychain-entitlements — the keychain access-group policy
|
|
4
|
+
* (`plugin/oxyKeychainGroups.js`) run over entitlements that were actually
|
|
5
|
+
* WRITTEN, not over an app config: what `expo prebuild` left in `ios/`, or what
|
|
6
|
+
* a signed binary carries.
|
|
7
|
+
*
|
|
8
|
+
* oxy-check-keychain-entitlements <bundle-id> <path> [--team-id <TEAMID>]
|
|
9
|
+
*
|
|
10
|
+
* `<path>` is an entitlements plist (`.entitlements`, `.xcent`, the XML of
|
|
11
|
+
* `codesign -d --entitlements - --xml <app>`) or a directory searched for
|
|
12
|
+
* `*.entitlements` (an `ios/` folder after prebuild; `Pods`, `build` and
|
|
13
|
+
* `node_modules` are skipped). Every file found is checked. `--team-id` says
|
|
14
|
+
* the file is codesigned output of that team, whose entries are expanded
|
|
15
|
+
* (`<TEAMID>.so.oxy.wallet`, not `$(AppIdentifierPrefix)so.oxy.wallet`).
|
|
16
|
+
*
|
|
17
|
+
* Exits 0 when every file passes, 1 on a policy violation, 2 on a usage or
|
|
18
|
+
* read error. A directory with no entitlements file is an error: there was
|
|
19
|
+
* nothing to check.
|
|
20
|
+
*/
|
|
21
|
+
const { readFileSync, readdirSync, statSync } = require('node:fs');
|
|
22
|
+
const { join, resolve } = require('node:path');
|
|
23
|
+
const { assertOxyKeychainGroups } = require('../plugin/oxyKeychainGroups');
|
|
24
|
+
|
|
25
|
+
const KEY = 'keychain-access-groups';
|
|
26
|
+
const SKIPPED_DIRS = new Set(['Pods', 'build', 'node_modules', 'DerivedData']);
|
|
27
|
+
|
|
28
|
+
class UsageError extends Error {}
|
|
29
|
+
|
|
30
|
+
/** `@expo/plist`, from the app first, then through Expo's own config plugins. */
|
|
31
|
+
function loadPlist(projectRoot = process.cwd()) {
|
|
32
|
+
const attempts = [
|
|
33
|
+
() => require.resolve('@expo/plist', { paths: [projectRoot] }),
|
|
34
|
+
() =>
|
|
35
|
+
require.resolve('@expo/plist', {
|
|
36
|
+
paths: [require.resolve('expo/config-plugins', { paths: [projectRoot] })],
|
|
37
|
+
}),
|
|
38
|
+
() => require.resolve('@expo/plist', { paths: [require.resolve('expo/config-plugins')] }),
|
|
39
|
+
() => require.resolve('@expo/plist'),
|
|
40
|
+
];
|
|
41
|
+
for (const attempt of attempts) {
|
|
42
|
+
try {
|
|
43
|
+
const plist = require(attempt());
|
|
44
|
+
return plist.default ?? plist;
|
|
45
|
+
} catch {
|
|
46
|
+
// Try the next resolution.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw new UsageError(
|
|
50
|
+
'@expo/plist could not be loaded: run this from an Expo app (expo installs it)',
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The `keychain-access-groups` value of one entitlements plist. */
|
|
55
|
+
function readKeychainGroups(file, plist = loadPlist()) {
|
|
56
|
+
const text = readFileSync(file, 'utf8');
|
|
57
|
+
if (text.startsWith('bplist')) {
|
|
58
|
+
throw new UsageError(`${file} is a binary plist: convert it with \`plutil -convert xml1\``);
|
|
59
|
+
}
|
|
60
|
+
let parsed;
|
|
61
|
+
try {
|
|
62
|
+
parsed = plist.parse(text);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new UsageError(`${file} is not a readable plist: ${error.message}`);
|
|
65
|
+
}
|
|
66
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
67
|
+
throw new UsageError(`${file} is not an entitlements dictionary`);
|
|
68
|
+
}
|
|
69
|
+
return parsed[KEY];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Every `*.entitlements` under `dir`, sorted. */
|
|
73
|
+
function findEntitlements(dir) {
|
|
74
|
+
const found = [];
|
|
75
|
+
const walk = (current) => {
|
|
76
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
77
|
+
const path = join(current, entry.name);
|
|
78
|
+
if (entry.isDirectory()) {
|
|
79
|
+
if (!SKIPPED_DIRS.has(entry.name)) walk(path);
|
|
80
|
+
} else if (entry.isFile() && entry.name.endsWith('.entitlements')) {
|
|
81
|
+
found.push(path);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
walk(dir);
|
|
86
|
+
return found.sort();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Check `target` for `bundleId`. Throws the policy's Error on a violation and
|
|
91
|
+
* a UsageError when there is nothing readable to check.
|
|
92
|
+
*
|
|
93
|
+
* @param {{ bundleId: string, target: string, teamId?: string, plist?: { parse(text: string): unknown } }} options
|
|
94
|
+
* @returns {{ file: string, groups: unknown }[]}
|
|
95
|
+
*/
|
|
96
|
+
function checkKeychainEntitlements({ bundleId, target, teamId, plist }) {
|
|
97
|
+
const path = resolve(target);
|
|
98
|
+
let stats;
|
|
99
|
+
try {
|
|
100
|
+
stats = statSync(path);
|
|
101
|
+
} catch {
|
|
102
|
+
throw new UsageError(`${target} does not exist`);
|
|
103
|
+
}
|
|
104
|
+
const files = stats.isDirectory() ? findEntitlements(path) : [path];
|
|
105
|
+
if (files.length === 0) {
|
|
106
|
+
throw new UsageError(`no *.entitlements file under ${target}`);
|
|
107
|
+
}
|
|
108
|
+
const parser = plist ?? loadPlist();
|
|
109
|
+
return files.map((file) => {
|
|
110
|
+
const groups = readKeychainGroups(file, parser);
|
|
111
|
+
try {
|
|
112
|
+
assertOxyKeychainGroups(bundleId, groups, teamId === undefined ? {} : { teamId });
|
|
113
|
+
} catch (error) {
|
|
114
|
+
error.message = `${file}: ${error.message}`;
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
return { file, groups };
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function parseArgs(argv) {
|
|
122
|
+
const positional = [];
|
|
123
|
+
let teamId;
|
|
124
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
125
|
+
const arg = argv[i];
|
|
126
|
+
if (arg === '--team-id') {
|
|
127
|
+
teamId = argv[i + 1];
|
|
128
|
+
if (teamId === undefined) throw new UsageError('--team-id needs a value');
|
|
129
|
+
i += 1;
|
|
130
|
+
} else if (arg.startsWith('--team-id=')) {
|
|
131
|
+
teamId = arg.slice('--team-id='.length);
|
|
132
|
+
} else if (arg.startsWith('-')) {
|
|
133
|
+
throw new UsageError(`unknown option ${arg}`);
|
|
134
|
+
} else {
|
|
135
|
+
positional.push(arg);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (positional.length !== 2) {
|
|
139
|
+
throw new UsageError(
|
|
140
|
+
'usage: oxy-check-keychain-entitlements <bundle-id> <entitlements-file-or-ios-dir> [--team-id <TEAMID>]',
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return { bundleId: positional[0], target: positional[1], teamId };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The CLI. Returns the exit code. */
|
|
147
|
+
function main(argv = process.argv.slice(2), { log = console.log, error = console.error } = {}) {
|
|
148
|
+
try {
|
|
149
|
+
const results = checkKeychainEntitlements(parseArgs(argv));
|
|
150
|
+
for (const { file, groups } of results) {
|
|
151
|
+
log(`ok ${file}: ${JSON.stringify(groups ?? [])}`);
|
|
152
|
+
}
|
|
153
|
+
return 0;
|
|
154
|
+
} catch (failure) {
|
|
155
|
+
error(failure.message);
|
|
156
|
+
return failure instanceof UsageError ? 2 : 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = {
|
|
161
|
+
checkKeychainEntitlements,
|
|
162
|
+
findEntitlements,
|
|
163
|
+
main,
|
|
164
|
+
readKeychainGroups,
|
|
165
|
+
UsageError,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
if (require.main === module) {
|
|
169
|
+
process.exitCode = main();
|
|
170
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/app-preset",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
|
|
5
5
|
"main": "./app.plugin.js",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"oxy-check-keychain-entitlements": "./bin/oxy-check-keychain-entitlements.js"
|
|
11
|
+
},
|
|
9
12
|
"exports": {
|
|
10
13
|
".": "./app.plugin.js",
|
|
11
14
|
"./app.plugin.js": "./app.plugin.js",
|
|
12
15
|
"./plugin/withOxyAppPreset": "./plugin/withOxyAppPreset.js",
|
|
13
16
|
"./plugin/withOxyKeychain": "./plugin/withOxyKeychain.js",
|
|
17
|
+
"./plugin/oxyKeychainGroups": "./plugin/oxyKeychainGroups.js",
|
|
18
|
+
"./check-entitlements": "./bin/oxy-check-keychain-entitlements.js",
|
|
14
19
|
"./plugin/withOxyBuildProperties": "./plugin/withOxyBuildProperties.js",
|
|
15
20
|
"./plugin/withOxyAndroidRelease": "./plugin/withOxyAndroidRelease.js",
|
|
16
21
|
"./plugin/withOxyAndroidWebp": "./plugin/withOxyAndroidWebp.js",
|
|
@@ -29,6 +34,7 @@
|
|
|
29
34
|
"NOTICE",
|
|
30
35
|
"app.plugin.js",
|
|
31
36
|
"plugin",
|
|
37
|
+
"bin",
|
|
32
38
|
"metro",
|
|
33
39
|
"babel",
|
|
34
40
|
"build-id",
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* Who may name which Oxy iOS keychain access group
|
|
3
3
|
* (docs/identity/ios-keychain-access-groups.md, ADR 0062 in the oxy repo).
|
|
4
4
|
*
|
|
5
|
-
* | Group | Holders
|
|
6
|
-
*
|
|
7
|
-
* | `so.oxy.identity` | Commons only, FIRST in its list
|
|
8
|
-
* | `so.oxy.wallet` | Commons, the Peable wallet
|
|
9
|
-
* | `
|
|
5
|
+
* | Group | Holders | Holds |
|
|
6
|
+
* |------------------------|-------------------------------------------|----------------------------------------|
|
|
7
|
+
* | `so.oxy.identity` | Commons only, FIRST in its list | the personal root, phrases, org index |
|
|
8
|
+
* | `so.oxy.wallet` | Commons, the Peable wallet | private keys the wallet signs with |
|
|
9
|
+
* | `so.oxy.identity.dev` | Commons' DEV build only, FIRST | the same, for the dev build |
|
|
10
|
+
* | `so.oxy.wallet.dev` | the DEV builds of Commons and the wallet | the same, for the dev builds |
|
|
11
|
+
* | `group.so.oxy.shared` | every Oxy app | public keys, the device-session credential |
|
|
10
12
|
*
|
|
11
13
|
* The first entry of `keychain-access-groups` is the app's DEFAULT group, and
|
|
12
14
|
* `@oxy.so/core` reads its role from it at runtime: identity first is Commons,
|
|
@@ -14,39 +16,115 @@
|
|
|
14
16
|
* ORDER is part of the policy, not only the membership: Commons lists
|
|
15
17
|
* `[identity, wallet, shared]`, the Peable wallet `[wallet, shared]`.
|
|
16
18
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* The DEV builds (`so.oxy.commons.dev`, `to.peable.app.dev`) sit next to the
|
|
20
|
+
* production apps on the same phone, are signed by the same team and run
|
|
21
|
+
* JavaScript from a dev server, so they never get the production restricted
|
|
22
|
+
* groups: they hold the `.dev` ones, and a production id may not name those.
|
|
23
|
+
*
|
|
24
|
+
* Every entry is spelled EXACTLY `$(AppIdentifierPrefix)<group>` (or
|
|
25
|
+
* `<TEAMID>.<group>` when checking built entitlements for that team). Any other
|
|
26
|
+
* entry is NORMALISED (`normalizeGroupName`: leading build variables such as
|
|
27
|
+
* `$(TeamIdentifierPrefix)` or `${…}`, nested, a leading ten-character team id
|
|
28
|
+
* and surrounding whitespace are stripped, case is ignored) only to say why it
|
|
29
|
+
* is refused: another spelling of an allowed group, a restricted group this
|
|
30
|
+
* app does not hold, or a group that is not this app's at all. An entry still
|
|
31
|
+
* carrying a build variable or a wildcard after normalisation cannot be judged.
|
|
32
|
+
*
|
|
33
|
+
* The list is EXACT, not a floor (R5-4). An app may list:
|
|
34
|
+
*
|
|
35
|
+
* | Bundle id | `keychain-access-groups` |
|
|
36
|
+
* |---------------------------------|--------------------------------------------------|
|
|
37
|
+
* | `so.oxy.commons` | `[identity, wallet, shared]` |
|
|
38
|
+
* | `so.oxy.commons.dev` | `[identity.dev, wallet.dev, shared]` |
|
|
39
|
+
* | `to.peable.app` | `[wallet, shared]` |
|
|
40
|
+
* | `to.peable.app.dev` | `[wallet.dev, shared]` |
|
|
41
|
+
* | every other app | `[shared]` |
|
|
42
|
+
*
|
|
43
|
+
* each optionally followed by the app's OWN application group,
|
|
44
|
+
* `$(AppIdentifierPrefix)<its own bundle id>`, which Apple grants it anyway.
|
|
45
|
+
* A holder may also still list `[shared]` alone: the build before its split,
|
|
46
|
+
* which reads nothing secret. Nothing else, in particular no other bundle id:
|
|
47
|
+
* `<TEAM>.<bundle id>` is each app's private group (ADR 0062 D6, its session
|
|
48
|
+
* and its own items live there), and every app of the team may list any of the
|
|
49
|
+
* team's groups, so an app naming another app's id reads that app's items.
|
|
50
|
+
* The entitlement is native, so prebuild is the one place it can be stopped
|
|
51
|
+
* before it ships; `oxy-check-keychain-entitlements` checks what a prebuild or
|
|
52
|
+
* a codesign wrote, in CI and in every release build.
|
|
20
53
|
*/
|
|
21
54
|
const PREFIX = '$(AppIdentifierPrefix)';
|
|
22
55
|
|
|
23
56
|
const OXY_KEYCHAIN_GROUPS = Object.freeze({
|
|
24
57
|
identity: 'so.oxy.identity',
|
|
25
58
|
wallet: 'so.oxy.wallet',
|
|
59
|
+
identityDev: 'so.oxy.identity.dev',
|
|
60
|
+
walletDev: 'so.oxy.wallet.dev',
|
|
26
61
|
shared: 'group.so.oxy.shared',
|
|
27
62
|
});
|
|
28
63
|
|
|
29
|
-
const
|
|
30
|
-
const PEABLE_WALLET = ['to.peable.app', 'to.peable.app.dev'];
|
|
64
|
+
const G = OXY_KEYCHAIN_GROUPS;
|
|
31
65
|
|
|
32
66
|
/** The exact leading entries each holder lists, by bundle id. */
|
|
33
67
|
const HOLDER_LAYOUTS = Object.freeze({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
]),
|
|
39
|
-
),
|
|
40
|
-
...Object.fromEntries(
|
|
41
|
-
PEABLE_WALLET.map((id) => [id, [OXY_KEYCHAIN_GROUPS.wallet, OXY_KEYCHAIN_GROUPS.shared]]),
|
|
42
|
-
),
|
|
68
|
+
'so.oxy.commons': Object.freeze([G.identity, G.wallet, G.shared]),
|
|
69
|
+
'so.oxy.commons.dev': Object.freeze([G.identityDev, G.walletDev, G.shared]),
|
|
70
|
+
'to.peable.app': Object.freeze([G.wallet, G.shared]),
|
|
71
|
+
'to.peable.app.dev': Object.freeze([G.walletDev, G.shared]),
|
|
43
72
|
});
|
|
44
73
|
|
|
45
|
-
|
|
74
|
+
/** Lower-cased restricted name → its canonical spelling. */
|
|
75
|
+
const RESTRICTED = new Map(
|
|
76
|
+
[G.identity, G.wallet, G.identityDev, G.walletDev].map((name) => [name.toLowerCase(), name]),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const TEAM_ID = /^[A-Z0-9]{10}$/;
|
|
80
|
+
const LEADING_TEAM_ID = /^[A-Z0-9]{10}\./i;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Length of the build variable (`$(…)` or `${…}`, nesting allowed) at the start
|
|
84
|
+
* of `text`, or 0 when it does not start with a complete one.
|
|
85
|
+
*/
|
|
86
|
+
function leadingVariableLength(text) {
|
|
87
|
+
if (text[0] !== '$' || (text[1] !== '(' && text[1] !== '{')) return 0;
|
|
88
|
+
const stack = [];
|
|
89
|
+
for (let i = 1; i < text.length; i += 1) {
|
|
90
|
+
const ch = text[i];
|
|
91
|
+
if (ch === '(' || ch === '{') stack.push(ch === '(' ? ')' : '}');
|
|
92
|
+
else if (ch === ')' || ch === '}') {
|
|
93
|
+
if (stack.pop() !== ch) return 0;
|
|
94
|
+
if (stack.length === 0) return i + 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The group an entry names, with every way of spelling its team prefix
|
|
102
|
+
* removed: `$(AppIdentifierPrefix)so.oxy.wallet`, `$(TeamIdentifierPrefix)
|
|
103
|
+
* so.oxy.wallet`, `ABCDE12345.so.oxy.wallet` → `so.oxy.wallet`. Case is kept;
|
|
104
|
+
* compare with `restrictedGroup`, which ignores it.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} entry
|
|
107
|
+
*/
|
|
108
|
+
function normalizeGroupName(entry) {
|
|
109
|
+
let rest = entry.trim();
|
|
110
|
+
for (;;) {
|
|
111
|
+
const variable = leadingVariableLength(rest);
|
|
112
|
+
if (variable > 0) {
|
|
113
|
+
rest = rest.slice(variable).trim();
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const team = LEADING_TEAM_ID.exec(rest);
|
|
117
|
+
if (team) {
|
|
118
|
+
rest = rest.slice(team[0].length).trim();
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
return rest;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
46
124
|
|
|
47
|
-
/**
|
|
48
|
-
function
|
|
49
|
-
return
|
|
125
|
+
/** The canonical restricted group a normalised name is, in any case, or undefined. */
|
|
126
|
+
function restrictedGroup(name) {
|
|
127
|
+
return RESTRICTED.get(name.toLowerCase());
|
|
50
128
|
}
|
|
51
129
|
|
|
52
130
|
/** The entitlement entries for these group names, in order. */
|
|
@@ -59,48 +137,131 @@ function keychainEntries(groups) {
|
|
|
59
137
|
* @param {string|undefined} bundleId
|
|
60
138
|
*/
|
|
61
139
|
function keychainGroupsFor(bundleId) {
|
|
62
|
-
return HOLDER_LAYOUTS
|
|
140
|
+
return Object.hasOwn(HOLDER_LAYOUTS, bundleId ?? '') ? [...HOLDER_LAYOUTS[bundleId]] : [G.shared];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function refuse(message) {
|
|
144
|
+
throw new Error(`[@oxy.so/app-preset] ${message} (docs/identity/ios-keychain-access-groups.md)`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The spelling an allowed group must have: `$(AppIdentifierPrefix)<name>`, or `<teamId>.<name>`. */
|
|
148
|
+
function pinnedEntry(name, teamId) {
|
|
149
|
+
return teamId === undefined ? `${PREFIX}${name}` : `${teamId}.${name}`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The lists this bundle id may ship, without its optional trailing own group:
|
|
154
|
+
* its holder layout (or the shared group alone, before its split build), or
|
|
155
|
+
* the shared group for every other app. An empty list is allowed too: it names
|
|
156
|
+
* no group, like an app without the entitlement.
|
|
157
|
+
* @param {string|undefined} bundleId
|
|
158
|
+
* @returns {readonly (readonly string[])[]}
|
|
159
|
+
*/
|
|
160
|
+
function allowedKeychainLayouts(bundleId) {
|
|
161
|
+
const layouts = [[], [G.shared]];
|
|
162
|
+
if (Object.hasOwn(HOLDER_LAYOUTS, bundleId ?? '')) layouts.push(HOLDER_LAYOUTS[bundleId]);
|
|
163
|
+
return layouts;
|
|
63
164
|
}
|
|
64
165
|
|
|
65
166
|
/**
|
|
66
167
|
* Throw unless `entries` (a `keychain-access-groups` value) is one this bundle
|
|
67
|
-
* id may ship:
|
|
68
|
-
*
|
|
168
|
+
* id may ship: every entry judgeable and in its one spelling, each one of the
|
|
169
|
+
* Oxy groups this bundle id holds or its own application group, and the whole
|
|
170
|
+
* list exactly its layout (`allowedKeychainLayouts`), in order, optionally
|
|
171
|
+
* followed by its own application group.
|
|
69
172
|
*
|
|
70
173
|
* @param {string|undefined} bundleId
|
|
71
174
|
* @param {unknown} entries
|
|
175
|
+
* @param {{ teamId?: string }} [options] `teamId`: the entries are BUILT
|
|
176
|
+
* (codesigned) entitlements of that team, so a group is spelled
|
|
177
|
+
* `<teamId>.<group>` instead of `$(AppIdentifierPrefix)<group>`.
|
|
72
178
|
*/
|
|
73
|
-
function assertOxyKeychainGroups(bundleId, entries) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
179
|
+
function assertOxyKeychainGroups(bundleId, entries, options = {}) {
|
|
180
|
+
// An app's implicit own group must never alias a restricted shared group,
|
|
181
|
+
// even when its entitlements omit keychain-access-groups altogether.
|
|
182
|
+
if (typeof bundleId === 'string' && restrictedGroup(bundleId) !== undefined) {
|
|
183
|
+
refuse(`${bundleId} is reserved for an Oxy restricted keychain group, not an app bundle id`);
|
|
184
|
+
}
|
|
185
|
+
if (entries === undefined || entries === null) return;
|
|
186
|
+
const app = bundleId ?? 'This app';
|
|
187
|
+
if (!Array.isArray(entries)) {
|
|
188
|
+
refuse(`${app}: keychain-access-groups must be an array of strings`);
|
|
189
|
+
}
|
|
190
|
+
const { teamId } = options;
|
|
191
|
+
if (teamId !== undefined && !TEAM_ID.test(teamId)) {
|
|
192
|
+
refuse(`"${teamId}" is not an Apple team id (ten upper-case letters and digits)`);
|
|
193
|
+
}
|
|
194
|
+
const layout = keychainGroupsFor(bundleId);
|
|
195
|
+
// The groups this app may name: its layout's, and its own application group.
|
|
196
|
+
const own = typeof bundleId === 'string' && bundleId !== '' ? bundleId : undefined;
|
|
197
|
+
const allowed = own === undefined ? [...layout] : [...layout, own];
|
|
198
|
+
const allowedByName = new Map(allowed.map((name) => [name.toLowerCase(), name]));
|
|
199
|
+
const ownHint =
|
|
200
|
+
own === undefined ? '' : ` and, after them, its own application group "${PREFIX}${own}"`;
|
|
201
|
+
|
|
202
|
+
/** The allowed group `entry` names, in its one spelling; throws for anything else. */
|
|
203
|
+
const judge = (entry) => {
|
|
204
|
+
if (typeof entry !== 'string') {
|
|
205
|
+
refuse(`${app}: every keychain-access-groups entry must be a string`);
|
|
206
|
+
}
|
|
207
|
+
// The exact spelling first: a bundle id whose first label is ten
|
|
208
|
+
// characters would otherwise be read as a team prefix below.
|
|
209
|
+
const exact = allowed.find((name) => entry === pinnedEntry(name, teamId));
|
|
210
|
+
if (exact !== undefined) return exact;
|
|
211
|
+
|
|
212
|
+
const name = normalizeGroupName(entry);
|
|
213
|
+
if (name === '' || /[$*?\s]/.test(name)) {
|
|
214
|
+
refuse(
|
|
215
|
+
`${app}: the keychain access group "${entry}" cannot be checked (a build variable, wildcard or ` +
|
|
216
|
+
'whitespace past its team prefix). Name the group literally after $(AppIdentifierPrefix).',
|
|
83
217
|
);
|
|
84
218
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
219
|
+
const canonical = allowedByName.get(name.toLowerCase());
|
|
220
|
+
if (canonical !== undefined) {
|
|
221
|
+
refuse(
|
|
222
|
+
`${app} must spell the keychain access group "${entry}" exactly "${pinnedEntry(canonical, teamId)}"`,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
const restricted = restrictedGroup(name);
|
|
226
|
+
if (restricted !== undefined) {
|
|
227
|
+
refuse(
|
|
228
|
+
`${app} may not list the keychain access group "${entry}" (${restricted}): only Commons holds ` +
|
|
229
|
+
'the identity group and only Commons and the Peable wallet the wallet group, the production ' +
|
|
230
|
+
'apps the production groups and their dev builds the .dev groups. Every other Oxy app lists ' +
|
|
231
|
+
'group.so.oxy.shared',
|
|
94
232
|
);
|
|
95
233
|
}
|
|
234
|
+
refuse(
|
|
235
|
+
`${app} may not list the keychain access group "${entry}": it is not one of this app's groups ` +
|
|
236
|
+
`[${layout.join(', ')}]${ownHint}. "<TEAM>.<bundle id>" is that app's own private group ` +
|
|
237
|
+
"(ADR 0062 D6), so naming another app's bundle id, or any other group, lets this app read " +
|
|
238
|
+
'items that are not its own',
|
|
239
|
+
);
|
|
240
|
+
};
|
|
241
|
+
const names = [];
|
|
242
|
+
for (const entry of entries) names.push(judge(entry));
|
|
243
|
+
|
|
244
|
+
const base = own !== undefined && names.at(-1) === own ? names.slice(0, -1) : names;
|
|
245
|
+
const fits = allowedKeychainLayouts(bundleId).some(
|
|
246
|
+
(candidate) => candidate.join(',') === base.join(','),
|
|
247
|
+
);
|
|
248
|
+
if (!fits) {
|
|
249
|
+
refuse(
|
|
250
|
+
`${app} must list its keychain access groups as exactly [${layout.join(', ')}], in that order` +
|
|
251
|
+
`${own === undefined ? '' : `, optionally followed by its own application group ${PREFIX}${own}`}` +
|
|
252
|
+
` (got [${names.join(', ')}]): the first entry is the default group, which decides where the ` +
|
|
253
|
+
'identity is written and what @oxy.so/core lets this app read',
|
|
254
|
+
);
|
|
96
255
|
}
|
|
97
256
|
}
|
|
98
257
|
|
|
99
258
|
module.exports = {
|
|
100
259
|
OXY_KEYCHAIN_GROUPS,
|
|
101
260
|
HOLDER_LAYOUTS,
|
|
261
|
+
allowedKeychainLayouts,
|
|
102
262
|
assertOxyKeychainGroups,
|
|
103
263
|
keychainEntries,
|
|
104
264
|
keychainGroupsFor,
|
|
105
|
-
|
|
265
|
+
normalizeGroupName,
|
|
266
|
+
restrictedGroup,
|
|
106
267
|
};
|
|
@@ -60,6 +60,7 @@ function resolveBuildPropertiesPlugin(projectRoot) {
|
|
|
60
60
|
"[@oxy.so/app-preset] withOxyBuildProperties requires the peer dependency 'expo-build-properties'. " +
|
|
61
61
|
'Install it with `npx expo install expo-build-properties`, or disable it by passing ' +
|
|
62
62
|
'`{ ios: false, android: false }` to the preset.',
|
|
63
|
+
{ cause: error },
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
66
|
const plugin = typeof mod === 'function' ? mod : mod.withBuildProperties || mod.default;
|
|
@@ -7,13 +7,19 @@
|
|
|
7
7
|
* the shared group (`group.so.oxy.shared`: public keys and the device-session
|
|
8
8
|
* credential), Commons `[so.oxy.identity, so.oxy.wallet, group.so.oxy.shared]`
|
|
9
9
|
* and the Peable wallet `[so.oxy.wallet, group.so.oxy.shared]` — the first
|
|
10
|
-
* entry is the default group, so it is part of the rule.
|
|
11
|
-
*
|
|
10
|
+
* entry is the default group, so it is part of the rule. Their dev builds
|
|
11
|
+
* (`.dev` bundle ids) get the `.dev` restricted groups instead. The Android
|
|
12
|
+
* half is Commons' identity host (`withOxySharedPermissions` in
|
|
13
|
+
* @oxy.so/services).
|
|
12
14
|
*
|
|
13
15
|
* The Oxy groups are put FIRST, in their order; entries the app or another
|
|
14
16
|
* plugin already declared are kept after them. Then the policy is checked on
|
|
15
|
-
* the result, and on the app's own `ios.entitlements`:
|
|
16
|
-
*
|
|
17
|
+
* the result, and on the app's own `ios.entitlements`: the list must be
|
|
18
|
+
* EXACTLY the bundle id's layout, optionally followed by the app's own
|
|
19
|
+
* `$(AppIdentifierPrefix)<bundle id>`. An app that is not a holder and names
|
|
20
|
+
* the identity or wallet group, or any app naming another group (another app's
|
|
21
|
+
* bundle id above all: that is the other app's private group, ADR 0062 D6),
|
|
22
|
+
* fails prebuild.
|
|
17
23
|
*
|
|
18
24
|
* @param {import('expo/config').ExpoConfig} config
|
|
19
25
|
* @param {string|string[]} [keychainGroups] Group name(s) without the prefix.
|
|
@@ -22,9 +28,10 @@
|
|
|
22
28
|
const { withEntitlementsPlist } = require('expo/config-plugins');
|
|
23
29
|
const {
|
|
24
30
|
assertOxyKeychainGroups,
|
|
25
|
-
groupName,
|
|
26
31
|
keychainEntries,
|
|
27
32
|
keychainGroupsFor,
|
|
33
|
+
normalizeGroupName,
|
|
34
|
+
restrictedGroup,
|
|
28
35
|
} = require('./oxyKeychainGroups');
|
|
29
36
|
|
|
30
37
|
const KEY = 'keychain-access-groups';
|
|
@@ -54,8 +61,15 @@ function withOxyKeychain(config, keychainGroups) {
|
|
|
54
61
|
|
|
55
62
|
const next = withEntitlementsPlist(config, (config) => {
|
|
56
63
|
const existing = Array.isArray(config.modResults[KEY]) ? config.modResults[KEY] : [];
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
// Drop what `wanted` already lists. Another spelling of a restricted group
|
|
65
|
+
// is KEPT, so the check below refuses it instead of quietly repairing it.
|
|
66
|
+
const wantedNames = new Set(wanted.map((entry) => normalizeGroupName(entry).toLowerCase()));
|
|
67
|
+
const rest = existing.filter((entry) => {
|
|
68
|
+
if (wanted.includes(entry)) return false;
|
|
69
|
+
if (typeof entry !== 'string') return true;
|
|
70
|
+
const name = normalizeGroupName(entry);
|
|
71
|
+
return restrictedGroup(name) !== undefined || !wantedNames.has(name.toLowerCase());
|
|
72
|
+
});
|
|
59
73
|
const groups = [...wanted, ...rest];
|
|
60
74
|
assertOxyKeychainGroups(bundleId, groups);
|
|
61
75
|
config.modResults[KEY] = groups;
|