@oxy.so/app-preset 6.3.0 → 6.5.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 -4
- package/bin/oxy-check-keychain-entitlements.js +145 -4
- package/package.json +1 -1
- package/plugin/oxyKeychainGroups.js +125 -35
- package/plugin/withOxyKeychain.js +6 -2
package/README.md
CHANGED
|
@@ -82,10 +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, their `.dev` builds the `.dev` groups
|
|
86
|
-
|
|
87
|
-
`oxy-check-keychain-entitlements <bundle-id> ios` runs the same policy over what prebuild
|
|
88
|
-
wrote), the Oxy `expo-build-properties`
|
|
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`
|
|
89
87
|
defaults (iOS `deploymentTarget 16.4`; Android ProGuard + resource shrinking — the
|
|
90
88
|
Android compile/target SDK and build tools are the Expo SDK's own, never pinned here), and `@oxy.so/services/plugins/withOxySharedPermissions`:
|
|
91
89
|
the app declares and requests the signature-level `so.oxy.permission.IDENTITY` and
|
|
@@ -104,6 +102,30 @@ The iOS and build-property pieces are overridable:
|
|
|
104
102
|
}]
|
|
105
103
|
```
|
|
106
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
|
+
|
|
107
129
|
##### Dropping React Native's GIF / WebP decoders (opt-in, Expo SDK 58+)
|
|
108
130
|
|
|
109
131
|
An app that renders no GIF and no animated WebP through react-native's own
|
|
@@ -14,12 +14,24 @@
|
|
|
14
14
|
* the file is codesigned output of that team, whose entries are expanded
|
|
15
15
|
* (`<TEAMID>.so.oxy.wallet`, not `$(AppIdentifierPrefix)so.oxy.wallet`).
|
|
16
16
|
*
|
|
17
|
+
* `<path>` may also be a SIGNED build (security review R6-15): an `.app`, an
|
|
18
|
+
* `.xcarchive` or an `.ipa`. Then what is checked is what the binary will
|
|
19
|
+
* actually run with: `codesign -d --entitlements - --xml` (macOS) over the
|
|
20
|
+
* app and every extension it embeds (`PlugIns/*.appex`, `Extensions/*.appex`).
|
|
21
|
+
* Each bundle's id and team come from its OWN signed `application-identifier`
|
|
22
|
+
* and `com.apple.developer.team-identifier`, never from the command line; the
|
|
23
|
+
* app's id must be `<bundle-id>` (compared without case, as Apple does), and
|
|
24
|
+
* each extension is judged under its own id. Run it on every archive before it
|
|
25
|
+
* is uploaded (docs/engineering/build-and-deploy.md).
|
|
26
|
+
*
|
|
17
27
|
* Exits 0 when every file passes, 1 on a policy violation, 2 on a usage or
|
|
18
28
|
* read error. A directory with no entitlements file is an error: there was
|
|
19
29
|
* nothing to check.
|
|
20
30
|
*/
|
|
21
|
-
const {
|
|
22
|
-
const {
|
|
31
|
+
const { execFileSync } = require('node:child_process');
|
|
32
|
+
const { mkdtempSync, readFileSync, readdirSync, rmSync, statSync } = require('node:fs');
|
|
33
|
+
const { tmpdir } = require('node:os');
|
|
34
|
+
const { basename, join, resolve } = require('node:path');
|
|
23
35
|
const { assertOxyKeychainGroups } = require('../plugin/oxyKeychainGroups');
|
|
24
36
|
|
|
25
37
|
const KEY = 'keychain-access-groups';
|
|
@@ -86,6 +98,121 @@ function findEntitlements(dir) {
|
|
|
86
98
|
return found.sort();
|
|
87
99
|
}
|
|
88
100
|
|
|
101
|
+
/** The entitlements dictionary of a plist text, or a UsageError naming `source`. */
|
|
102
|
+
function parseEntitlements(text, source, plist) {
|
|
103
|
+
let parsed;
|
|
104
|
+
try {
|
|
105
|
+
parsed = plist.parse(text);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
throw new UsageError(`${source} is not a readable plist: ${error.message}`);
|
|
108
|
+
}
|
|
109
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
110
|
+
throw new UsageError(`${source} carries no entitlements dictionary`);
|
|
111
|
+
}
|
|
112
|
+
return parsed;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const SIGNED_BUNDLE = /\.(app|xcarchive|ipa)$/i;
|
|
116
|
+
|
|
117
|
+
/** `codesign -d --entitlements - --xml <bundle>`: the entitlements a signed bundle runs with (macOS). */
|
|
118
|
+
function codesignEntitlements(bundle) {
|
|
119
|
+
try {
|
|
120
|
+
return execFileSync('codesign', ['-d', '--entitlements', '-', '--xml', bundle], {
|
|
121
|
+
encoding: 'utf8',
|
|
122
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
123
|
+
});
|
|
124
|
+
} catch (error) {
|
|
125
|
+
throw new UsageError(
|
|
126
|
+
`codesign could not read the entitlements of ${bundle} (macOS only): ${error.message}`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The `.app` directories directly in `dir`. */
|
|
132
|
+
function appsIn(dir) {
|
|
133
|
+
let entries;
|
|
134
|
+
try {
|
|
135
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
136
|
+
} catch {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
return entries
|
|
140
|
+
.filter((entry) => entry.isDirectory() && entry.name.endsWith('.app'))
|
|
141
|
+
.map((entry) => join(dir, entry.name));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The app of a signed build, and every extension it embeds. */
|
|
145
|
+
function signedBundles(app) {
|
|
146
|
+
const extensions = ['PlugIns', 'Extensions'].flatMap((folder) => {
|
|
147
|
+
try {
|
|
148
|
+
return readdirSync(join(app, folder), { withFileTypes: true })
|
|
149
|
+
.filter((entry) => entry.isDirectory() && entry.name.endsWith('.appex'))
|
|
150
|
+
.map((entry) => join(app, folder, entry.name));
|
|
151
|
+
} catch {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return [app, ...extensions.sort()];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Check a SIGNED `.app`, `.xcarchive` or `.ipa` (R6-15): the entitlements
|
|
160
|
+
* codesign reports for the app and each embedded extension, each bundle judged
|
|
161
|
+
* under the id and team its own signature names.
|
|
162
|
+
*
|
|
163
|
+
* @param {{ bundleId: string, target: string, plist: { parse(text: string): unknown },
|
|
164
|
+
* codesign?: (bundle: string) => string, unzip?: (ipa: string, into: string) => void }} options
|
|
165
|
+
*/
|
|
166
|
+
function checkSignedBuild({ bundleId, target, plist, codesign = codesignEntitlements, unzip }) {
|
|
167
|
+
let scratch;
|
|
168
|
+
try {
|
|
169
|
+
let apps;
|
|
170
|
+
if (/\.ipa$/i.test(target)) {
|
|
171
|
+
scratch = mkdtempSync(join(tmpdir(), 'oxy-ipa-'));
|
|
172
|
+
(
|
|
173
|
+
unzip ??
|
|
174
|
+
((ipa, into) => execFileSync('unzip', ['-q', ipa, '-d', into], { stdio: 'ignore' }))
|
|
175
|
+
)(target, scratch);
|
|
176
|
+
apps = appsIn(join(scratch, 'Payload'));
|
|
177
|
+
} else if (/\.xcarchive$/i.test(target)) {
|
|
178
|
+
apps = appsIn(join(target, 'Products', 'Applications'));
|
|
179
|
+
} else {
|
|
180
|
+
apps = [target];
|
|
181
|
+
}
|
|
182
|
+
if (apps.length !== 1) {
|
|
183
|
+
throw new UsageError(`${target} must hold exactly one .app (found ${apps.length})`);
|
|
184
|
+
}
|
|
185
|
+
return signedBundles(apps[0]).map((bundle, index) => {
|
|
186
|
+
const source = `${basename(target)}:${bundle === apps[0] ? basename(bundle) : bundle.slice(apps[0].length + 1)}`;
|
|
187
|
+
const entitlements = parseEntitlements(codesign(bundle), source, plist);
|
|
188
|
+
const teamId = entitlements['com.apple.developer.team-identifier'];
|
|
189
|
+
const appId = entitlements['application-identifier'];
|
|
190
|
+
if (
|
|
191
|
+
typeof teamId !== 'string' ||
|
|
192
|
+
typeof appId !== 'string' ||
|
|
193
|
+
!appId.startsWith(`${teamId}.`)
|
|
194
|
+
) {
|
|
195
|
+
throw new UsageError(
|
|
196
|
+
`${source}: no signed application-identifier and team-identifier (is it signed?)`,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const signedId = appId.slice(teamId.length + 1);
|
|
200
|
+
if (index === 0 && signedId.toLowerCase() !== bundleId.toLowerCase()) {
|
|
201
|
+
throw new Error(`${source}: is signed as ${signedId}, not ${bundleId}`);
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
assertOxyKeychainGroups(signedId, entitlements[KEY], { teamId });
|
|
205
|
+
} catch (error) {
|
|
206
|
+
error.message = `${source}: ${error.message}`;
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
return { file: source, groups: entitlements[KEY] };
|
|
210
|
+
});
|
|
211
|
+
} finally {
|
|
212
|
+
if (scratch) rmSync(scratch, { recursive: true, force: true });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
89
216
|
/**
|
|
90
217
|
* Check `target` for `bundleId`. Throws the policy's Error on a violation and
|
|
91
218
|
* a UsageError when there is nothing readable to check.
|
|
@@ -93,7 +220,7 @@ function findEntitlements(dir) {
|
|
|
93
220
|
* @param {{ bundleId: string, target: string, teamId?: string, plist?: { parse(text: string): unknown } }} options
|
|
94
221
|
* @returns {{ file: string, groups: unknown }[]}
|
|
95
222
|
*/
|
|
96
|
-
function checkKeychainEntitlements({ bundleId, target, teamId, plist }) {
|
|
223
|
+
function checkKeychainEntitlements({ bundleId, target, teamId, plist, codesign, unzip }) {
|
|
97
224
|
const path = resolve(target);
|
|
98
225
|
let stats;
|
|
99
226
|
try {
|
|
@@ -101,6 +228,18 @@ function checkKeychainEntitlements({ bundleId, target, teamId, plist }) {
|
|
|
101
228
|
} catch {
|
|
102
229
|
throw new UsageError(`${target} does not exist`);
|
|
103
230
|
}
|
|
231
|
+
if (SIGNED_BUNDLE.test(path)) {
|
|
232
|
+
if (teamId !== undefined) {
|
|
233
|
+
throw new UsageError('--team-id is read from the signature of a signed build; drop it');
|
|
234
|
+
}
|
|
235
|
+
return checkSignedBuild({
|
|
236
|
+
bundleId,
|
|
237
|
+
target: path,
|
|
238
|
+
plist: plist ?? loadPlist(),
|
|
239
|
+
codesign,
|
|
240
|
+
unzip,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
104
243
|
const files = stats.isDirectory() ? findEntitlements(path) : [path];
|
|
105
244
|
if (files.length === 0) {
|
|
106
245
|
throw new UsageError(`no *.entitlements file under ${target}`);
|
|
@@ -137,7 +276,8 @@ function parseArgs(argv) {
|
|
|
137
276
|
}
|
|
138
277
|
if (positional.length !== 2) {
|
|
139
278
|
throw new UsageError(
|
|
140
|
-
'usage: oxy-check-keychain-entitlements <bundle-id> <entitlements-file-or-ios-dir> [--team-id <TEAMID>]'
|
|
279
|
+
'usage: oxy-check-keychain-entitlements <bundle-id> <entitlements-file-or-ios-dir> [--team-id <TEAMID>]\n' +
|
|
280
|
+
' oxy-check-keychain-entitlements <bundle-id> <signed .app | .xcarchive | .ipa>',
|
|
141
281
|
);
|
|
142
282
|
}
|
|
143
283
|
return { bundleId: positional[0], target: positional[1], teamId };
|
|
@@ -159,6 +299,7 @@ function main(argv = process.argv.slice(2), { log = console.log, error = console
|
|
|
159
299
|
|
|
160
300
|
module.exports = {
|
|
161
301
|
checkKeychainEntitlements,
|
|
302
|
+
checkSignedBuild,
|
|
162
303
|
findEntitlements,
|
|
163
304
|
main,
|
|
164
305
|
readKeychainGroups,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/app-preset",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.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": {
|
|
@@ -21,18 +21,35 @@
|
|
|
21
21
|
* JavaScript from a dev server, so they never get the production restricted
|
|
22
22
|
* groups: they hold the `.dev` ones, and a production id may not name those.
|
|
23
23
|
*
|
|
24
|
-
* Every entry is
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* cannot be judged
|
|
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
32
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
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.
|
|
36
53
|
*/
|
|
37
54
|
const PREFIX = '$(AppIdentifierPrefix)';
|
|
38
55
|
|
|
@@ -115,31 +132,81 @@ function keychainEntries(groups) {
|
|
|
115
132
|
return groups.map((group) => `${PREFIX}${group}`);
|
|
116
133
|
}
|
|
117
134
|
|
|
135
|
+
/**
|
|
136
|
+
* The holder id `bundleId` names, compared as Apple compares bundle ids:
|
|
137
|
+
* WITHOUT case (security review R6-15). App Store Connect and the developer
|
|
138
|
+
* portal treat `So.Oxy.Commons` and `so.oxy.commons` as the same identifier,
|
|
139
|
+
* so a case variant is never "every other app"; it is a holder spelled
|
|
140
|
+
* differently, which `assertOxyKeychainGroups` refuses.
|
|
141
|
+
* @param {string|undefined} bundleId
|
|
142
|
+
* @returns {string|undefined}
|
|
143
|
+
*/
|
|
144
|
+
function holderIdOf(bundleId) {
|
|
145
|
+
if (typeof bundleId !== 'string') return undefined;
|
|
146
|
+
const lower = bundleId.toLowerCase();
|
|
147
|
+
return Object.keys(HOLDER_LAYOUTS).find((id) => id === lower);
|
|
148
|
+
}
|
|
149
|
+
|
|
118
150
|
/**
|
|
119
151
|
* The groups this app should list: its holder layout, or the shared group.
|
|
120
152
|
* @param {string|undefined} bundleId
|
|
121
153
|
*/
|
|
122
154
|
function keychainGroupsFor(bundleId) {
|
|
123
|
-
|
|
155
|
+
const holder = holderIdOf(bundleId);
|
|
156
|
+
return holder === undefined ? [G.shared] : [...HOLDER_LAYOUTS[holder]];
|
|
124
157
|
}
|
|
125
158
|
|
|
126
159
|
function refuse(message) {
|
|
127
160
|
throw new Error(`[@oxy.so/app-preset] ${message} (docs/identity/ios-keychain-access-groups.md)`);
|
|
128
161
|
}
|
|
129
162
|
|
|
163
|
+
/** The spelling an allowed group must have: `$(AppIdentifierPrefix)<name>`, or `<teamId>.<name>`. */
|
|
164
|
+
function pinnedEntry(name, teamId) {
|
|
165
|
+
return teamId === undefined ? `${PREFIX}${name}` : `${teamId}.${name}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The lists this bundle id may ship, without its optional trailing own group:
|
|
170
|
+
* its holder layout (or the shared group alone, before its split build), or
|
|
171
|
+
* the shared group for every other app. An empty list is allowed too: it names
|
|
172
|
+
* no group, like an app without the entitlement.
|
|
173
|
+
* @param {string|undefined} bundleId
|
|
174
|
+
* @returns {readonly (readonly string[])[]}
|
|
175
|
+
*/
|
|
176
|
+
function allowedKeychainLayouts(bundleId) {
|
|
177
|
+
const layouts = [[], [G.shared]];
|
|
178
|
+
const holder = holderIdOf(bundleId);
|
|
179
|
+
if (holder !== undefined) layouts.push(HOLDER_LAYOUTS[holder]);
|
|
180
|
+
return layouts;
|
|
181
|
+
}
|
|
182
|
+
|
|
130
183
|
/**
|
|
131
184
|
* Throw unless `entries` (a `keychain-access-groups` value) is one this bundle
|
|
132
|
-
* id may ship: every entry judgeable
|
|
133
|
-
*
|
|
134
|
-
* in order
|
|
185
|
+
* id may ship: every entry judgeable and in its one spelling, each one of the
|
|
186
|
+
* Oxy groups this bundle id holds or its own application group, and the whole
|
|
187
|
+
* list exactly its layout (`allowedKeychainLayouts`), in order, optionally
|
|
188
|
+
* followed by its own application group.
|
|
135
189
|
*
|
|
136
190
|
* @param {string|undefined} bundleId
|
|
137
191
|
* @param {unknown} entries
|
|
138
192
|
* @param {{ teamId?: string }} [options] `teamId`: the entries are BUILT
|
|
139
|
-
* (codesigned) entitlements of that team, so a
|
|
193
|
+
* (codesigned) entitlements of that team, so a group is spelled
|
|
140
194
|
* `<teamId>.<group>` instead of `$(AppIdentifierPrefix)<group>`.
|
|
141
195
|
*/
|
|
142
196
|
function assertOxyKeychainGroups(bundleId, entries, options = {}) {
|
|
197
|
+
// An app's implicit own group must never alias a restricted shared group,
|
|
198
|
+
// even when its entitlements omit keychain-access-groups altogether.
|
|
199
|
+
if (typeof bundleId === 'string' && restrictedGroup(bundleId) !== undefined) {
|
|
200
|
+
refuse(`${bundleId} is reserved for an Oxy restricted keychain group, not an app bundle id`);
|
|
201
|
+
}
|
|
202
|
+
// Apple compares bundle ids without case (R6-15): a holder's id in another
|
|
203
|
+
// case is the holder misspelled, never a different app.
|
|
204
|
+
const holder = holderIdOf(bundleId);
|
|
205
|
+
if (holder !== undefined && holder !== bundleId) {
|
|
206
|
+
refuse(
|
|
207
|
+
`${bundleId} must be spelled exactly "${holder}" (bundle ids are compared without case)`,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
143
210
|
if (entries === undefined || entries === null) return;
|
|
144
211
|
const app = bundleId ?? 'This app';
|
|
145
212
|
if (!Array.isArray(entries)) {
|
|
@@ -149,12 +216,24 @@ function assertOxyKeychainGroups(bundleId, entries, options = {}) {
|
|
|
149
216
|
if (teamId !== undefined && !TEAM_ID.test(teamId)) {
|
|
150
217
|
refuse(`"${teamId}" is not an Apple team id (ten upper-case letters and digits)`);
|
|
151
218
|
}
|
|
152
|
-
const layout =
|
|
219
|
+
const layout = keychainGroupsFor(bundleId);
|
|
220
|
+
// The groups this app may name: its layout's, and its own application group.
|
|
221
|
+
const own = typeof bundleId === 'string' && bundleId !== '' ? bundleId : undefined;
|
|
222
|
+
const allowed = own === undefined ? [...layout] : [...layout, own];
|
|
223
|
+
const allowedByName = new Map(allowed.map((name) => [name.toLowerCase(), name]));
|
|
224
|
+
const ownHint =
|
|
225
|
+
own === undefined ? '' : ` and, after them, its own application group "${PREFIX}${own}"`;
|
|
153
226
|
|
|
154
|
-
|
|
227
|
+
/** The allowed group `entry` names, in its one spelling; throws for anything else. */
|
|
228
|
+
const judge = (entry) => {
|
|
155
229
|
if (typeof entry !== 'string') {
|
|
156
230
|
refuse(`${app}: every keychain-access-groups entry must be a string`);
|
|
157
231
|
}
|
|
232
|
+
// The exact spelling first: a bundle id whose first label is ten
|
|
233
|
+
// characters would otherwise be read as a team prefix below.
|
|
234
|
+
const exact = allowed.find((name) => entry === pinnedEntry(name, teamId));
|
|
235
|
+
if (exact !== undefined) return exact;
|
|
236
|
+
|
|
158
237
|
const name = normalizeGroupName(entry);
|
|
159
238
|
if (name === '' || /[$*?\s]/.test(name)) {
|
|
160
239
|
refuse(
|
|
@@ -162,9 +241,14 @@ function assertOxyKeychainGroups(bundleId, entries, options = {}) {
|
|
|
162
241
|
'whitespace past its team prefix). Name the group literally after $(AppIdentifierPrefix).',
|
|
163
242
|
);
|
|
164
243
|
}
|
|
244
|
+
const canonical = allowedByName.get(name.toLowerCase());
|
|
245
|
+
if (canonical !== undefined) {
|
|
246
|
+
refuse(
|
|
247
|
+
`${app} must spell the keychain access group "${entry}" exactly "${pinnedEntry(canonical, teamId)}"`,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
165
250
|
const restricted = restrictedGroup(name);
|
|
166
|
-
if (restricted
|
|
167
|
-
if (!layout.includes(restricted)) {
|
|
251
|
+
if (restricted !== undefined) {
|
|
168
252
|
refuse(
|
|
169
253
|
`${app} may not list the keychain access group "${entry}" (${restricted}): only Commons holds ` +
|
|
170
254
|
'the identity group and only Commons and the Peable wallet the wallet group, the production ' +
|
|
@@ -172,28 +256,34 @@ function assertOxyKeychainGroups(bundleId, entries, options = {}) {
|
|
|
172
256
|
'group.so.oxy.shared',
|
|
173
257
|
);
|
|
174
258
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
259
|
+
refuse(
|
|
260
|
+
`${app} may not list the keychain access group "${entry}": it is not one of this app's groups ` +
|
|
261
|
+
`[${layout.join(', ')}]${ownHint}. "<TEAM>.<bundle id>" is that app's own private group ` +
|
|
262
|
+
"(ADR 0062 D6), so naming another app's bundle id, or any other group, lets this app read " +
|
|
263
|
+
'items that are not its own',
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
const names = [];
|
|
267
|
+
for (const entry of entries) names.push(judge(entry));
|
|
181
268
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
269
|
+
const base = own !== undefined && names.at(-1) === own ? names.slice(0, -1) : names;
|
|
270
|
+
const fits = allowedKeychainLayouts(bundleId).some(
|
|
271
|
+
(candidate) => candidate.join(',') === base.join(','),
|
|
272
|
+
);
|
|
273
|
+
if (!fits) {
|
|
274
|
+
refuse(
|
|
275
|
+
`${app} must list its keychain access groups as exactly [${layout.join(', ')}], in that order` +
|
|
276
|
+
`${own === undefined ? '' : `, optionally followed by its own application group ${PREFIX}${own}`}` +
|
|
277
|
+
` (got [${names.join(', ')}]): the first entry is the default group, which decides where the ` +
|
|
278
|
+
'identity is written and what @oxy.so/core lets this app read',
|
|
279
|
+
);
|
|
191
280
|
}
|
|
192
281
|
}
|
|
193
282
|
|
|
194
283
|
module.exports = {
|
|
195
284
|
OXY_KEYCHAIN_GROUPS,
|
|
196
285
|
HOLDER_LAYOUTS,
|
|
286
|
+
allowedKeychainLayouts,
|
|
197
287
|
assertOxyKeychainGroups,
|
|
198
288
|
keychainEntries,
|
|
199
289
|
keychainGroupsFor,
|
|
@@ -14,8 +14,12 @@
|
|
|
14
14
|
*
|
|
15
15
|
* The Oxy groups are put FIRST, in their order; entries the app or another
|
|
16
16
|
* plugin already declared are kept after them. Then the policy is checked on
|
|
17
|
-
* the result, and on the app's own `ios.entitlements`:
|
|
18
|
-
*
|
|
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.
|
|
19
23
|
*
|
|
20
24
|
* @param {import('expo/config').ExpoConfig} config
|
|
21
25
|
* @param {string|string[]} [keychainGroups] Group name(s) without the prefix.
|