Skip to content

Commit 77fff67

Browse files
committed
Initial support for rcodesign
1 parent 2226eb3 commit 77fff67

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,9 @@ class Applesign {
647647
res = await tools.pseudoSign(entitlements, file);
648648
} else {
649649
const keychain = getKeychain();
650-
res = await tools.codesign(identity, entitlements, keychain, file);
650+
res = await tools.codesign(identity, entitlements, keychain, file, this.config.codeSign);
651651
if (res.code !== 0 && codesignHasFailed(config, res.code, res.stderr)) {
652-
return this.emit("end", res.stderr);
652+
return this.emit('end', res.stderr);
653653
}
654654
}
655655
this.emit("message", "Signed " + file);

lib/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const helpMessage = `Usage:
6161
-k, --keychain [KEYCHAIN] Specify custom keychain file
6262
-K, --add-access-group [NAME] Add $(TeamIdentifier).NAME to keychain-access-groups
6363
-L, --identities List local codesign identities
64+
--codesign-tool=rcodesign Use rcodesign instead of codesign (EXPERIMENTAL)
6465
-m, --mobileprovision [FILE] Specify the mobileprovision file to use
6566
-s, --single Sign a single file instead of an IPA
6667
-S, --self-sign-provision Self-sign mobile provisioning (EXPERIMENTAL)
@@ -127,6 +128,7 @@ export interface ConfigOptions {
127128
bundleIdKeychainGroup: string | false;
128129
bundleid: string | undefined;
129130
cloneEntitlements: boolean;
131+
codeSign: string | undefined;
130132
customKeychainGroup: string | undefined;
131133
debug: any; // opt.d || opt.debug || ""
132134
deviceProvision: any; // opt.D || opt.deviceProvision || false
@@ -206,6 +208,7 @@ const fromOptions = function (opt: any): ConfigOptions {
206208
bundleIdKeychainGroup: opt.bundleIdKeychainGroup || false,
207209
bundleid: opt.bundleid || undefined,
208210
cloneEntitlements: opt.cloneEntitlements || false,
211+
codeSign: opt.codeSign || undefined,
209212
customKeychainGroup: opt.customKeychainGroup || undefined,
210213
debug: opt.d || opt.debug || "",
211214
deviceProvision: opt.D || opt.deviceProvision || false,
@@ -338,6 +341,7 @@ function compile(conf: any) {
338341
bundleIdKeychainGroup: conf.B || conf["bundleid-access-group"],
339342
bundleid: conf.bundleid || conf.b,
340343
cloneEntitlements: conf.c || conf["clone-entitlements"],
344+
codeSign: conf["codesign-tool"],
341345
customKeychainGroup: conf.K || conf["add-access-group"],
342346
debug: conf.debug || conf.d || "",
343347
deviceProvision: conf.D || conf.deviceProvision || false,

lib/tools.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,62 @@ async function codesign(
141141
entitlement: string | undefined,
142142
keychain: string | undefined,
143143
file: string,
144+
tool?: string,
144145
) {
145146
if (identity === undefined) {
146147
// XXX: typescript can ensure this at compile time
147148
throw new Error("--identity is required to sign");
148149
}
150+
if (tool === 'rcodesign') {
151+
console.error('WARNING: Signing with the experimental rcodesign tool');
152+
const args = [];
153+
args.push('sign'); // action
154+
155+
args.push('-v');
156+
args.push('--pem-source'); // action
157+
const pemFile = '/Users/pancake/iphone.pem';
158+
args.push(pemFile);
159+
160+
args.push('--code-resources-path');
161+
args.push('/tmp/csreq.bin');
162+
// rcodesign bug makes this flag to not sign the binary at all
163+
args.push('--extra-digest');
164+
args.push('sha256');
165+
args.push('--extra-digest');
166+
args.push('sha384');
167+
// args.push('--binary-identifier');
168+
// args.push('com.tacobellspain.app');
169+
/*
170+
args.push('--code-signature-flags');
171+
args.push('runtime');
172+
*/
173+
// --p12-file developer-id.p12
174+
// --p12-password-file ~/.certificate-password
175+
// --code-signature-flags runtime
176+
// path/to/executable
177+
/*
178+
if (typeof entitlement === 'string' && entitlement !== '') {
179+
args.push('-e');
180+
args.push(entitlement);
181+
}
182+
args.push('--binary-identifier');
183+
args.push(identity);
184+
*/
185+
if (typeof keychain === 'string') {
186+
args.push('--keychain-fingerprint');
187+
args.push(keychain);
188+
}
189+
args.push(file); // input
190+
args.push(file + '.signed'); // output
191+
console.error('rcodesign ' + args.join(' '));
192+
const a = await execProgram('rcodesign', args, undefined);
193+
if (a.code === 0) {
194+
await execProgram('rm', ['-rf', file], undefined);
195+
await execProgram('mv', [file + '.signed', file], undefined);
196+
}
197+
console.log(a.stderr);
198+
return execProgram('cp', [file, '/tmp/newsigned'], undefined);
199+
}
149200
/* use the --no-strict to avoid the "resource envelope is obsolete" error */
150201
const args = ["--no-strict"]; // http://stackoverflow.com/a/26204757
151202
args.push("-fs", identity);
@@ -181,6 +232,12 @@ async function verifyCodesign(
181232
file: string,
182233
keychain?: string,
183234
): Promise<ExecResult> {
235+
/*
236+
if (tool === 'rcodesign') {
237+
const args = ['verify', file];
238+
return execProgram(getTool('rcodesign'), args, null, cb);
239+
}
240+
*/
184241
const args = ["-v", "--no-strict"];
185242
if (typeof keychain === "string") {
186243
args.push("--keychain=" + keychain);

0 commit comments

Comments
 (0)