mirror of
https://github.com/crazy-max/ghaction-import-gpg.git
synced 2024-12-25 12:42:07 -05:00
Set passphrase for all key keygrips (#57)
Co-authored-by: yann degat <yann.degat@corp.ovh.com>
This commit is contained in:
parent
f4dc783f2a
commit
708e04fe6f
3 changed files with 31 additions and 23 deletions
|
@ -18,7 +18,10 @@ const userInfo = {
|
||||||
email: 'joe@foo.bar',
|
email: 'joe@foo.bar',
|
||||||
keyID: 'D523BD50DD70B0BA',
|
keyID: 'D523BD50DD70B0BA',
|
||||||
fingerprint: '27571A53B86AF0C799B38BA77D851EB72D73BDA0',
|
fingerprint: '27571A53B86AF0C799B38BA77D851EB72D73BDA0',
|
||||||
keygrip: '3E2D1142AA59E08E16B7E2C64BA6DDC773B1A627'
|
keygrips: [
|
||||||
|
'3E2D1142AA59E08E16B7E2C64BA6DDC773B1A627',
|
||||||
|
'BA83FC8947213477F28ADC019F6564A956456163',
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('gpg', () => {
|
describe('gpg', () => {
|
||||||
|
@ -58,12 +61,15 @@ describe('gpg', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getKeygrip', () => {
|
describe('getKeygrips', () => {
|
||||||
it('returns the keygrip', async () => {
|
it('returns the keygrips', async () => {
|
||||||
await gpg.importKey(userInfo.pgp);
|
await gpg.importKey(userInfo.pgp);
|
||||||
await gpg.getKeygrip(userInfo.fingerprint).then(keygrip => {
|
await gpg.getKeygrips(userInfo.fingerprint).then(keygrips => {
|
||||||
console.log(keygrip);
|
console.log(keygrips);
|
||||||
expect(keygrip).toEqual(userInfo.keygrip);
|
expect(keygrips.length).toEqual(userInfo.keygrips.length);
|
||||||
|
for (let i = 0; i < keygrips.length; i++) {
|
||||||
|
expect(keygrips[i]).toEqual(userInfo.keygrips[i]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -77,12 +83,13 @@ describe('gpg', () => {
|
||||||
describe('presetPassphrase', () => {
|
describe('presetPassphrase', () => {
|
||||||
it('presets passphrase', async () => {
|
it('presets passphrase', async () => {
|
||||||
await gpg.importKey(userInfo.pgp);
|
await gpg.importKey(userInfo.pgp);
|
||||||
const keygrip = await gpg.getKeygrip(userInfo.fingerprint);
|
|
||||||
await gpg.configureAgent(gpg.agentConfig);
|
await gpg.configureAgent(gpg.agentConfig);
|
||||||
await gpg.presetPassphrase(keygrip, userInfo.passphrase).then(output => {
|
for (let keygrip of await gpg.getKeygrips(userInfo.fingerprint)) {
|
||||||
console.log(output);
|
await gpg.presetPassphrase(keygrip, userInfo.passphrase).then(output => {
|
||||||
expect(output).not.toEqual('');
|
console.log(output);
|
||||||
});
|
expect(output).not.toEqual('');
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
10
src/gpg.ts
10
src/gpg.ts
|
@ -124,19 +124,19 @@ export const importKey = async (key: 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 => {
|
return await exec.exec('gpg', ['--batch', '--with-colons', '--with-keygrip', '--list-secret-keys', fingerprint], true).then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr != '' && !res.success) {
|
||||||
throw new Error(res.stderr);
|
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)) {
|
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
||||||
if (line.startsWith('grp')) {
|
if (line.startsWith('grp')) {
|
||||||
keygrip = line.replace(/(grp|:)/g, '').trim();
|
keygrips.push(line.replace(/(grp|:)/g, '').trim());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return keygrip;
|
return keygrips;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
15
src/main.ts
15
src/main.ts
|
@ -50,14 +50,15 @@ async function run(): Promise<void> {
|
||||||
core.info('⚙️ Configuring GnuPG agent');
|
core.info('⚙️ Configuring GnuPG agent');
|
||||||
await gpg.configureAgent(gpg.agentConfig);
|
await gpg.configureAgent(gpg.agentConfig);
|
||||||
|
|
||||||
core.info('📌 Getting keygrip');
|
core.info('📌 Getting keygrips');
|
||||||
const keygrip = await gpg.getKeygrip(privateKey.fingerprint);
|
const keygrips = await gpg.getKeygrips(privateKey.fingerprint);
|
||||||
core.debug(`${keygrip}`);
|
|
||||||
|
|
||||||
core.info('🔓 Presetting passphrase');
|
for (let keygrip of await gpg.getKeygrips(privateKey.fingerprint)) {
|
||||||
await gpg.presetPassphrase(keygrip, process.env.PASSPHRASE).then(stdout => {
|
core.info(`🔓 Presetting passphrase for ${keygrip}`);
|
||||||
core.debug(stdout);
|
await gpg.presetPassphrase(keygrip, process.env.PASSPHRASE).then(stdout => {
|
||||||
});
|
core.debug(stdout);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info('🛒 Setting outputs...');
|
core.info('🛒 Setting outputs...');
|
||||||
|
|
Loading…
Reference in a new issue