Skip to content

Commit

Permalink
feat: add spctl and codesign verificatin prior to stapling
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Aug 8, 2023
1 parent d0eabf3 commit b4b6d48
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
lib
*.log
src/example.ts
.idea
48 changes: 48 additions & 0 deletions src/check-signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as path from 'path';

import { spawn } from './spawn';
import type { NotarizeStapleOptions } from './types';
import debug from 'debug';
const d = debug('electron-notarize');

const spctl = async (opts: NotarizeStapleOptions) => {
d('attempting to spctl asses app:', opts.appPath);
const result = await spawn('spctl', ['-vvv', '--assess', path.basename(opts.appPath)], {
cwd: path.dirname(opts.appPath),
});

return result;
};

const codesign = async (opts: NotarizeStapleOptions) => {
d('attempting to check codesign of app:', opts.appPath);
const result = await spawn(
'codesign',
['-vvv', '--deep', '--strict', path.basename(opts.appPath)],
{
cwd: path.dirname(opts.appPath),
},
);

return result;
};
export async function checkSignatures(opts: NotarizeStapleOptions): Promise<void> {
const codesignResult = await codesign(opts);
const spctlResult = await spctl(opts);

let error = '';

if (spctlResult.code !== 0) {
d('spctl asses failed');
error = `Failed to spctl asses your application with code: ${spctlResult.code}\n\n${spctlResult.output}\n`;
}
if (codesignResult.code !== 0) {
d('codesign check failed');
error += `Failed to codesign your application with code: ${spctlResult.code}\n\n${spctlResult.output}`;
}

if (error) {
throw new Error(error);
}
d('codesign and spctl asses succeeded');
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { startLegacyNotarize, waitForLegacyNotarize } from './legacy';
import { isNotaryToolAvailable, notarizeAndWaitForNotaryTool } from './notarytool';
import { stapleApp } from './staple';
import { NotarizeOptions, NotaryToolStartOptions } from './types';
import { checkSignatures } from './check-signature';

const d = debug('electron-notarize');

Expand Down Expand Up @@ -50,6 +51,8 @@ export async function notarize({ appPath, ...otherOptions }: NotarizeOptions) {
} as NotaryToolStartOptions);
}

await checkSignatures({ appPath });

await retry(() => stapleApp({ appPath }), {
retries: 3,
});
Expand Down

0 comments on commit b4b6d48

Please sign in to comment.