@oxy.so/app-preset 6.1.1 → 6.3.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 +6 -2
- package/bin/oxy-check-keychain-entitlements.js +170 -0
- package/package.json +7 -1
- package/plugin/oxyKeychainGroups.js +202 -0
- package/plugin/withOxyAppPreset.js +11 -12
- package/plugin/withOxyBuildProperties.js +1 -0
- package/plugin/withOxyKeychain.js +63 -20
- package/plugin/withOxyUpdates.js +4 -1
package/README.md
CHANGED
|
@@ -81,7 +81,11 @@ plugins: [
|
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
This adds the iOS `keychain-access-groups` entitlement
|
|
84
|
-
(`$(AppIdentifierPrefix)group.so.oxy.shared
|
|
84
|
+
(`$(AppIdentifierPrefix)group.so.oxy.shared`; only Commons and the Peable wallet get
|
|
85
|
+
more, their `.dev` builds the `.dev` groups, and any other app naming `so.oxy.identity` or
|
|
86
|
+
`so.oxy.wallet` in any spelling fails prebuild — ADR 0062 of the oxy repo;
|
|
87
|
+
`oxy-check-keychain-entitlements <bundle-id> ios` runs the same policy over what prebuild
|
|
88
|
+
wrote), the Oxy `expo-build-properties`
|
|
85
89
|
defaults (iOS `deploymentTarget 16.4`; Android ProGuard + resource shrinking — the
|
|
86
90
|
Android compile/target SDK and build tools are the Expo SDK's own, never pinned here), and `@oxy.so/services/plugins/withOxySharedPermissions`:
|
|
87
91
|
the app declares and requests the signature-level `so.oxy.permission.IDENTITY` and
|
|
@@ -94,7 +98,7 @@ The iOS and build-property pieces are overridable:
|
|
|
94
98
|
|
|
95
99
|
```js
|
|
96
100
|
['@oxy.so/app-preset', {
|
|
97
|
-
keychainGroup: 'group.so.oxy.shared', // false → skip
|
|
101
|
+
keychainGroup: 'group.so.oxy.shared', // default: the bundle id's groups; false → skip (the policy still checks)
|
|
98
102
|
ios: { deploymentTarget: '17.0' }, // deep-merges over defaults; false → skip iOS build props
|
|
99
103
|
android: { targetSdkVersion: 34 }, // deep-merges over defaults; false → skip Android build props
|
|
100
104
|
}]
|
|
@@ -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.3.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",
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may name which Oxy iOS keychain access group
|
|
3
|
+
* (docs/identity/ios-keychain-access-groups.md, ADR 0062 in the oxy repo).
|
|
4
|
+
*
|
|
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 |
|
|
12
|
+
*
|
|
13
|
+
* The first entry of `keychain-access-groups` is the app's DEFAULT group, and
|
|
14
|
+
* `@oxy.so/core` reads its role from it at runtime: identity first is Commons,
|
|
15
|
+
* wallet first is the Peable wallet, anything else holds no private key. So the
|
|
16
|
+
* ORDER is part of the policy, not only the membership: Commons lists
|
|
17
|
+
* `[identity, wallet, shared]`, the Peable wallet `[wallet, shared]`.
|
|
18
|
+
*
|
|
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 NORMALISED before it is judged (`normalizeGroupName`): leading
|
|
25
|
+
* build variables (`$(AppIdentifierPrefix)`, `$(TeamIdentifierPrefix)`,
|
|
26
|
+
* `${…}`, nested), a leading ten-character team id and surrounding whitespace
|
|
27
|
+
* are stripped, and the name is compared without case. An entry that names a
|
|
28
|
+
* restricted group must then be spelled EXACTLY `$(AppIdentifierPrefix)<group>`
|
|
29
|
+
* (or `<TEAMID>.<group>` when checking built entitlements for that team), and
|
|
30
|
+
* an entry still carrying a build variable or a wildcard after normalisation
|
|
31
|
+
* cannot be judged and is refused.
|
|
32
|
+
*
|
|
33
|
+
* Every other app keeps the shared group only. An app config that names a
|
|
34
|
+
* restricted group without being its holder fails prebuild; the entitlement is
|
|
35
|
+
* native, so this is the one place it can be stopped before it ships.
|
|
36
|
+
*/
|
|
37
|
+
const PREFIX = '$(AppIdentifierPrefix)';
|
|
38
|
+
|
|
39
|
+
const OXY_KEYCHAIN_GROUPS = Object.freeze({
|
|
40
|
+
identity: 'so.oxy.identity',
|
|
41
|
+
wallet: 'so.oxy.wallet',
|
|
42
|
+
identityDev: 'so.oxy.identity.dev',
|
|
43
|
+
walletDev: 'so.oxy.wallet.dev',
|
|
44
|
+
shared: 'group.so.oxy.shared',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const G = OXY_KEYCHAIN_GROUPS;
|
|
48
|
+
|
|
49
|
+
/** The exact leading entries each holder lists, by bundle id. */
|
|
50
|
+
const HOLDER_LAYOUTS = Object.freeze({
|
|
51
|
+
'so.oxy.commons': Object.freeze([G.identity, G.wallet, G.shared]),
|
|
52
|
+
'so.oxy.commons.dev': Object.freeze([G.identityDev, G.walletDev, G.shared]),
|
|
53
|
+
'to.peable.app': Object.freeze([G.wallet, G.shared]),
|
|
54
|
+
'to.peable.app.dev': Object.freeze([G.walletDev, G.shared]),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/** Lower-cased restricted name → its canonical spelling. */
|
|
58
|
+
const RESTRICTED = new Map(
|
|
59
|
+
[G.identity, G.wallet, G.identityDev, G.walletDev].map((name) => [name.toLowerCase(), name]),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const TEAM_ID = /^[A-Z0-9]{10}$/;
|
|
63
|
+
const LEADING_TEAM_ID = /^[A-Z0-9]{10}\./i;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Length of the build variable (`$(…)` or `${…}`, nesting allowed) at the start
|
|
67
|
+
* of `text`, or 0 when it does not start with a complete one.
|
|
68
|
+
*/
|
|
69
|
+
function leadingVariableLength(text) {
|
|
70
|
+
if (text[0] !== '$' || (text[1] !== '(' && text[1] !== '{')) return 0;
|
|
71
|
+
const stack = [];
|
|
72
|
+
for (let i = 1; i < text.length; i += 1) {
|
|
73
|
+
const ch = text[i];
|
|
74
|
+
if (ch === '(' || ch === '{') stack.push(ch === '(' ? ')' : '}');
|
|
75
|
+
else if (ch === ')' || ch === '}') {
|
|
76
|
+
if (stack.pop() !== ch) return 0;
|
|
77
|
+
if (stack.length === 0) return i + 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The group an entry names, with every way of spelling its team prefix
|
|
85
|
+
* removed: `$(AppIdentifierPrefix)so.oxy.wallet`, `$(TeamIdentifierPrefix)
|
|
86
|
+
* so.oxy.wallet`, `ABCDE12345.so.oxy.wallet` → `so.oxy.wallet`. Case is kept;
|
|
87
|
+
* compare with `restrictedGroup`, which ignores it.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} entry
|
|
90
|
+
*/
|
|
91
|
+
function normalizeGroupName(entry) {
|
|
92
|
+
let rest = entry.trim();
|
|
93
|
+
for (;;) {
|
|
94
|
+
const variable = leadingVariableLength(rest);
|
|
95
|
+
if (variable > 0) {
|
|
96
|
+
rest = rest.slice(variable).trim();
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const team = LEADING_TEAM_ID.exec(rest);
|
|
100
|
+
if (team) {
|
|
101
|
+
rest = rest.slice(team[0].length).trim();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
return rest;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The canonical restricted group a normalised name is, in any case, or undefined. */
|
|
109
|
+
function restrictedGroup(name) {
|
|
110
|
+
return RESTRICTED.get(name.toLowerCase());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The entitlement entries for these group names, in order. */
|
|
114
|
+
function keychainEntries(groups) {
|
|
115
|
+
return groups.map((group) => `${PREFIX}${group}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The groups this app should list: its holder layout, or the shared group.
|
|
120
|
+
* @param {string|undefined} bundleId
|
|
121
|
+
*/
|
|
122
|
+
function keychainGroupsFor(bundleId) {
|
|
123
|
+
return Object.hasOwn(HOLDER_LAYOUTS, bundleId ?? '') ? [...HOLDER_LAYOUTS[bundleId]] : [G.shared];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function refuse(message) {
|
|
127
|
+
throw new Error(`[@oxy.so/app-preset] ${message} (docs/identity/ios-keychain-access-groups.md)`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Throw unless `entries` (a `keychain-access-groups` value) is one this bundle
|
|
132
|
+
* id may ship: every entry judgeable, a restricted group only for its holders
|
|
133
|
+
* and only in its one spelling, and a holder's layout as the leading entries,
|
|
134
|
+
* in order.
|
|
135
|
+
*
|
|
136
|
+
* @param {string|undefined} bundleId
|
|
137
|
+
* @param {unknown} entries
|
|
138
|
+
* @param {{ teamId?: string }} [options] `teamId`: the entries are BUILT
|
|
139
|
+
* (codesigned) entitlements of that team, so a restricted group is spelled
|
|
140
|
+
* `<teamId>.<group>` instead of `$(AppIdentifierPrefix)<group>`.
|
|
141
|
+
*/
|
|
142
|
+
function assertOxyKeychainGroups(bundleId, entries, options = {}) {
|
|
143
|
+
if (entries === undefined || entries === null) return;
|
|
144
|
+
const app = bundleId ?? 'This app';
|
|
145
|
+
if (!Array.isArray(entries)) {
|
|
146
|
+
refuse(`${app}: keychain-access-groups must be an array of strings`);
|
|
147
|
+
}
|
|
148
|
+
const { teamId } = options;
|
|
149
|
+
if (teamId !== undefined && !TEAM_ID.test(teamId)) {
|
|
150
|
+
refuse(`"${teamId}" is not an Apple team id (ten upper-case letters and digits)`);
|
|
151
|
+
}
|
|
152
|
+
const layout = Object.hasOwn(HOLDER_LAYOUTS, bundleId ?? '') ? HOLDER_LAYOUTS[bundleId] : [];
|
|
153
|
+
|
|
154
|
+
const names = entries.map((entry) => {
|
|
155
|
+
if (typeof entry !== 'string') {
|
|
156
|
+
refuse(`${app}: every keychain-access-groups entry must be a string`);
|
|
157
|
+
}
|
|
158
|
+
const name = normalizeGroupName(entry);
|
|
159
|
+
if (name === '' || /[$*?\s]/.test(name)) {
|
|
160
|
+
refuse(
|
|
161
|
+
`${app}: the keychain access group "${entry}" cannot be checked (a build variable, wildcard or ` +
|
|
162
|
+
'whitespace past its team prefix). Name the group literally after $(AppIdentifierPrefix).',
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const restricted = restrictedGroup(name);
|
|
166
|
+
if (restricted === undefined) return name;
|
|
167
|
+
if (!layout.includes(restricted)) {
|
|
168
|
+
refuse(
|
|
169
|
+
`${app} may not list the keychain access group "${entry}" (${restricted}): only Commons holds ` +
|
|
170
|
+
'the identity group and only Commons and the Peable wallet the wallet group, the production ' +
|
|
171
|
+
'apps the production groups and their dev builds the .dev groups. Every other Oxy app lists ' +
|
|
172
|
+
'group.so.oxy.shared',
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
const pinned = teamId === undefined ? `${PREFIX}${restricted}` : `${teamId}.${restricted}`;
|
|
176
|
+
if (entry !== pinned) {
|
|
177
|
+
refuse(`${app} must spell the keychain access group "${entry}" exactly "${pinned}"`);
|
|
178
|
+
}
|
|
179
|
+
return restricted;
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if (layout.length > 0 && names.some((name) => restrictedGroup(name) !== undefined)) {
|
|
183
|
+
const leading = names.slice(0, layout.length);
|
|
184
|
+
if (leading.join(',') !== layout.join(',')) {
|
|
185
|
+
refuse(
|
|
186
|
+
`${bundleId} must list its keychain access groups as [${layout.join(', ')}] first, in that ` +
|
|
187
|
+
`order (got [${names.join(', ')}]): the first entry is the default group, which decides ` +
|
|
188
|
+
'where the identity is written and what @oxy.so/core lets this app read',
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
module.exports = {
|
|
195
|
+
OXY_KEYCHAIN_GROUPS,
|
|
196
|
+
HOLDER_LAYOUTS,
|
|
197
|
+
assertOxyKeychainGroups,
|
|
198
|
+
keychainEntries,
|
|
199
|
+
keychainGroupsFor,
|
|
200
|
+
normalizeGroupName,
|
|
201
|
+
restrictedGroup,
|
|
202
|
+
};
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* Options:
|
|
16
16
|
*
|
|
17
17
|
* ['@oxy.so/app-preset', {
|
|
18
|
-
* keychainGroup:
|
|
18
|
+
* keychainGroup: undefined, // default: the app's groups (shared; Commons and the Peable wallet more); false → skip
|
|
19
19
|
* ios: { deploymentTarget: '17.0' }, // false → skip iOS build properties
|
|
20
20
|
* android: { targetSdkVersion: 34 }, // false → skip Android build properties
|
|
21
21
|
* webgpu: true, // opt-in: react-native-webgpu's config plugin
|
|
@@ -42,7 +42,11 @@
|
|
|
42
42
|
*
|
|
43
43
|
* @param {import('expo/config').ExpoConfig} config
|
|
44
44
|
* @param {object} [options]
|
|
45
|
-
* @param {string|false} [options.keychainGroup
|
|
45
|
+
* @param {string|string[]|false} [options.keychainGroup] The iOS keychain
|
|
46
|
+
* access group name(s), without `$(AppIdentifierPrefix)`. Default: the
|
|
47
|
+
* policy's groups for the bundle id (`./oxyKeychainGroups`): the shared group,
|
|
48
|
+
* or a holder's layout. `false` skips the entitlement (the policy still checks
|
|
49
|
+
* whatever the app declares itself).
|
|
46
50
|
* @param {object|false} [options.ios]
|
|
47
51
|
* @param {object|false} [options.android]
|
|
48
52
|
* @param {boolean} [options.webgpu=false] Apply `react-native-webgpu`'s
|
|
@@ -80,13 +84,7 @@ module.exports = function withOxyAppPreset(config, options = {}) {
|
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
const {
|
|
84
|
-
keychainGroup = 'group.so.oxy.shared',
|
|
85
|
-
ios = {},
|
|
86
|
-
android = {},
|
|
87
|
-
webgpu = false,
|
|
88
|
-
noxcturnal = true,
|
|
89
|
-
} = options;
|
|
87
|
+
const { keychainGroup, ios = {}, android = {}, webgpu = false, noxcturnal = true } = options;
|
|
90
88
|
|
|
91
89
|
let next = config;
|
|
92
90
|
|
|
@@ -100,9 +98,10 @@ module.exports = function withOxyAppPreset(config, options = {}) {
|
|
|
100
98
|
};
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
next =
|
|
102
|
+
keychainGroup === false
|
|
103
|
+
? withOxyKeychain.withOxyKeychainPolicy(next)
|
|
104
|
+
: withOxyKeychain(next, keychainGroup);
|
|
106
105
|
|
|
107
106
|
if (ios !== false || android !== false) {
|
|
108
107
|
next = withOxyBuildProperties(next, { ios, android });
|
|
@@ -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;
|
|
@@ -1,35 +1,78 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Expo Config Plugin: withOxyKeychain
|
|
3
3
|
*
|
|
4
|
-
* Adds
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Adds the iOS `keychain-access-groups` entitlement an Oxy app needs, prefixed
|
|
5
|
+
* with `$(AppIdentifierPrefix)` so Xcode expands it to the Team ID at build
|
|
6
|
+
* time. Which groups, and in which order, is `./oxyKeychainGroups`: every app
|
|
7
|
+
* the shared group (`group.so.oxy.shared`: public keys and the device-session
|
|
8
|
+
* credential), Commons `[so.oxy.identity, so.oxy.wallet, group.so.oxy.shared]`
|
|
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. 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).
|
|
9
14
|
*
|
|
10
|
-
*
|
|
11
|
-
* already declared
|
|
12
|
-
*
|
|
15
|
+
* The Oxy groups are put FIRST, in their order; entries the app or another
|
|
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`: an app that is not a
|
|
18
|
+
* holder and names the identity or wallet group fails prebuild.
|
|
13
19
|
*
|
|
14
20
|
* @param {import('expo/config').ExpoConfig} config
|
|
15
|
-
* @param {string} [
|
|
16
|
-
*
|
|
21
|
+
* @param {string|string[]} [keychainGroups] Group name(s) without the prefix.
|
|
22
|
+
* Default: what `keychainGroupsFor(ios.bundleIdentifier)` gives.
|
|
17
23
|
*/
|
|
18
24
|
const { withEntitlementsPlist } = require('expo/config-plugins');
|
|
25
|
+
const {
|
|
26
|
+
assertOxyKeychainGroups,
|
|
27
|
+
keychainEntries,
|
|
28
|
+
keychainGroupsFor,
|
|
29
|
+
normalizeGroupName,
|
|
30
|
+
restrictedGroup,
|
|
31
|
+
} = require('./oxyKeychainGroups');
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
const entry = `$(AppIdentifierPrefix)${keychainGroup}`;
|
|
33
|
+
const KEY = 'keychain-access-groups';
|
|
22
34
|
|
|
35
|
+
/** Check the groups an app config declares itself (`ios.entitlements`). */
|
|
36
|
+
function withOxyKeychainPolicy(config) {
|
|
37
|
+
const bundleId = config.ios?.bundleIdentifier;
|
|
38
|
+
assertOxyKeychainGroups(bundleId, config.ios?.entitlements?.[KEY]);
|
|
23
39
|
return withEntitlementsPlist(config, (config) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
assertOxyKeychainGroups(bundleId, config.modResults[KEY]);
|
|
41
|
+
return config;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
27
44
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
function withOxyKeychain(config, keychainGroups) {
|
|
46
|
+
const bundleId = config.ios?.bundleIdentifier;
|
|
47
|
+
const wanted = keychainEntries(
|
|
48
|
+
keychainGroups === undefined
|
|
49
|
+
? keychainGroupsFor(bundleId)
|
|
50
|
+
: Array.isArray(keychainGroups)
|
|
51
|
+
? keychainGroups
|
|
52
|
+
: [keychainGroups],
|
|
53
|
+
);
|
|
54
|
+
// At config time, not only in the mod: a refused group fails `expo config` too.
|
|
55
|
+
assertOxyKeychainGroups(bundleId, wanted);
|
|
56
|
+
assertOxyKeychainGroups(bundleId, config.ios?.entitlements?.[KEY]);
|
|
31
57
|
|
|
32
|
-
|
|
58
|
+
const next = withEntitlementsPlist(config, (config) => {
|
|
59
|
+
const existing = Array.isArray(config.modResults[KEY]) ? config.modResults[KEY] : [];
|
|
60
|
+
// Drop what `wanted` already lists. Another spelling of a restricted group
|
|
61
|
+
// is KEPT, so the check below refuses it instead of quietly repairing it.
|
|
62
|
+
const wantedNames = new Set(wanted.map((entry) => normalizeGroupName(entry).toLowerCase()));
|
|
63
|
+
const rest = existing.filter((entry) => {
|
|
64
|
+
if (wanted.includes(entry)) return false;
|
|
65
|
+
if (typeof entry !== 'string') return true;
|
|
66
|
+
const name = normalizeGroupName(entry);
|
|
67
|
+
return restrictedGroup(name) !== undefined || !wantedNames.has(name.toLowerCase());
|
|
68
|
+
});
|
|
69
|
+
const groups = [...wanted, ...rest];
|
|
70
|
+
assertOxyKeychainGroups(bundleId, groups);
|
|
71
|
+
config.modResults[KEY] = groups;
|
|
33
72
|
return config;
|
|
34
73
|
});
|
|
35
|
-
|
|
74
|
+
return next;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = withOxyKeychain;
|
|
78
|
+
module.exports.withOxyKeychainPolicy = withOxyKeychainPolicy;
|
package/plugin/withOxyUpdates.js
CHANGED
|
@@ -70,6 +70,7 @@ const path = require('path');
|
|
|
70
70
|
const { WarningAggregator } = require('expo/config-plugins');
|
|
71
71
|
const withOxyReleaseVersion = require('./withOxyReleaseVersion');
|
|
72
72
|
const withOxyAbiSplits = require('./withOxyAbiSplits');
|
|
73
|
+
const { withOxyKeychainPolicy } = require('./withOxyKeychain');
|
|
73
74
|
|
|
74
75
|
/** Origin of the Oxy Updates server. `updates.oxy.so` does not exist; oxy-api serves it. */
|
|
75
76
|
const DEFAULT_API_ORIGIN = 'https://api.oxy.so';
|
|
@@ -185,5 +186,7 @@ module.exports = function withOxyUpdates(config, options = {}) {
|
|
|
185
186
|
// `version` is the OTA boundary, so it also numbers the store build: an
|
|
186
187
|
// OTA-enabled app that skips the preset's main plugin gets the same rule,
|
|
187
188
|
// and the same per-ABI APKs (every app on the release pipeline lists this).
|
|
188
|
-
|
|
189
|
+
// Every Oxy app applies this plugin, Commons and the Peable wallet included
|
|
190
|
+
// (neither uses the preset), so the keychain access-group policy is checked here too.
|
|
191
|
+
return withOxyKeychainPolicy(withOxyAbiSplits(withOxyReleaseVersion(next)));
|
|
189
192
|
};
|