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

Preset passphrase for all keygrips of priv key #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
24 changes: 12 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/gpg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,18 @@ export const importKey = async (armoredText: string): Promise<string> => {
});
};

export const getKeygrip = async (fingerprint: string): Promise<string> => {
export const getKeygrips = async (fingerprint: string): Promise<Array<string>> => {
return await exec.exec('gpg', ['--batch', '--with-colons', '--with-keygrip', '--list-secret-keys', fingerprint], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
let keygrip: string = '';
let keygrips: Array<string> = [];
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
if (line.startsWith('grp')) {
keygrip = line.replace(/(grp|:)/g, '').trim();
break;
keygrips.push(line.replace(/(grp|:)/g, '').trim());
}
}
return keygrip;
return keygrips;
});
};

Expand Down
13 changes: 7 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ async function run(): Promise<void> {
await gpg.configureAgent(gpg.agentConfig);

core.info('📌 Getting keygrip');
const keygrip = await gpg.getKeygrip(privateKey.fingerprint);
core.debug(`${keygrip}`);
const keygrips = await gpg.getKeygrips(privateKey.fingerprint);

core.info('🔓 Presetting passphrase');
await gpg.presetPassphrase(keygrip, process.env.PASSPHRASE).then(stdout => {
core.debug(stdout);
});
for (var i = 0; i < keygrips.length; i++) {
core.info(`🔓 Presetting passphrase for ${keygrips[i]}`);
await gpg.presetPassphrase(keygrips[i], process.env.PASSPHRASE).then(stdout => {
core.debug(stdout);
});
}
}

core.info('🛒 Setting outputs...');
Expand Down