Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add codesign verification and assessment prior to notarizing #152

Merged
merged 8 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/check-signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as path from 'path';

import { spawn } from './spawn';
import type { NotarizeStapleOptions } from './types';
dsanders11 marked this conversation as resolved.
Show resolved Hide resolved
import debug from 'debug';
const d = debug('electron-notarize');

const codesignDisplay = async (opts: NotarizeStapleOptions) => {
const result = await spawn('codesign', ['-dv', '-vvvv', '--deep', 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;
};
dsanders11 marked this conversation as resolved.
Show resolved Hide resolved
export async function checkSignatures(opts: NotarizeStapleOptions): Promise<void> {
const codesignResult = await codesign(opts);
const codesignInfo = await codesignDisplay(opts);
dsanders11 marked this conversation as resolved.
Show resolved Hide resolved

let error = '';

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

if (error) {
throw new Error(error);
}
d('codesign assess succeeded');
}
4 changes: 4 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';
dsanders11 marked this conversation as resolved.
Show resolved Hide resolved

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

Expand All @@ -14,6 +15,9 @@ export { NotarizeOptions };
export { validateLegacyAuthorizationArgs as validateAuthorizationArgs } from './validate-args';

export async function notarize({ appPath, ...otherOptions }: NotarizeOptions) {

await checkSignatures({ appPath });

if (otherOptions.tool === 'legacy') {
console.warn(
'Notarizing using the legacy altool system. The altool system will be disabled on November 1 2023. Please switch to the notarytool system before then.',
Expand Down
6 changes: 3 additions & 3 deletions src/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const spawn = (
'spawning cmd:',
cmd,
'args:',
args.map(arg => (isSecret(arg) ? '*********' : arg)),
args.map((arg) => (isSecret(arg) ? '*********' : arg)),
'opts:',
opts,
);
Expand All @@ -28,10 +28,10 @@ export const spawn = (
child.stdout!.on('data', dataHandler);
child.stderr!.on('data', dataHandler);
return new Promise<SpawnResult>((resolve, reject) => {
child.on('error', err => {
child.on('error', (err) => {
reject(err);
});
child.on('exit', code => {
child.on('exit', (code) => {
d(`cmd ${cmd} terminated with code: ${code}`);
resolve({
code,
Expand Down