Fix importing of base64 armored string (#18)

This commit is contained in:
Alejandro Hernández 2020-05-18 17:15:05 +02:00 committed by GitHub
parent 151c2def6c
commit fe2d0d79b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 6 deletions

1
.github/test-key-base64.pgp vendored Normal file
View file

@ -0,0 +1 @@
LS0tLS1CRUdJTiBQR1AgUFJJVkFURSBLRVkgQkxPQ0stLS0tLQoKbFFQR0JGN0NmMU1CQ0FEYXdGRDVrK05kRm40YzNrMlNRQlV2UXA5R21kYmZjeFlwMjEvSEl1amtSVVhDVFB6YgoyaVdtclJmMUx1RFdnNlFmd0MzMFpHdWpQZmsxVWYrVlEvLzlXK1FFU0JMcHJnUm8vaXNvSUVBbEZYVFpyVGNvCkRocUxIaW04UkliVFVhNkJZNmJtdkRxeEpUN0RSR3Q0bExkdVZEK1UvaG5saXdVRTAxcW9TTHJYaUlLeTVJbjUKM29NRkMyWXNTSkN2cmVNT09oQzlYakRaQ1lrTFVaanZoY3JMQ0x4ZGJPUFZGSjgrZm9JK1hHK0IxeEREOVVMYQp5bGZTeHBJcEFRaTFEQ2R0Y3RLZnJsOGhUUDdieXp2NWM1ZUFoY1B0ek82VVBCdGgwNk5lUW5ORmZCeGVNZ1grCk9tRVNuUU5WRlkwdytmeEY0aGFDQ1pFTjZOTGV4NjZKWE9DaEFCRUJBQUgrQndNQ3k1NTZKUG1kZ2tydERxZnMKdzFIcXRaelBRVnYxT0oyL2VMbUYvYnlkblFJL3lsNEsrZUNvWXMvU0w1SVdpT0grcFFVcDQ3QWV5bkdtZjFxSgo2alVSZURsejlWa1d0VTNQNVhJc0NBVFQyYmdqbmJmOTZDdk05NUdBWDNqSlg5aC9laGVXTDRrY2Jzc2lWZnNkCjd2SUR5SGVvWXMrMG8wQXRqbmkrYmRZbnJjZ09tVVRuNSsxeUdTWXErK3Q4cXQ1QUR0elpoMitSN0JyTXN5TkUKdUJwd00yS25pbUo3YXh5ay9jNFpkMXJrSEREdk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2tuNHpac09OdnZsQ01RL3pBWgowQVNxdE1LYndUQ2NYeGVhbWRhQUZ4MkdnTmJ6NWs4Q1BvNlRhQll3dXkyaXFsSUZ2S1MyUWkwM2pOK1BBV1J6CkhSeFBXYUwyMFJ0VG05WjlmaXg3R044ZGQ3VVlYUDY0Q3Jyd1BiL0VIOW1MaDVUSVJmd2N5aUtaaTBGWmRNVGUKMUFoaWlRRThCQmdCQ0FBbUZpRUVHbkhSUHdrNFRtZFpvdjE2ejVidHdPdEJ2anNGQWw3Q2YxTUNHd3dGQ1FQQwpad0FBQ2drUXo1YnR3T3RCdmp2WFZBZ0FxNE1iK2NjaGhaT1N2dHBuMVdVR2RIWEZ0TERmMXlWR2xCTUdQQ2UzCnM3TDk1LzVpVkdKUWdJVmdKRzZnNDQ3ZDFjSUNNWTlHLzRYa3VkaE1aWDVQZ2FMQ3dPWnhadTVVYkl2cFYxaW8KV1YxYzIyNXZuY3FYbVgxZ3NsT2RHTzdrbHRta0tOTmQzVDBzc0lndjZBY3p3ZWdUM2svYzRzdE1wcSs0d0VPZwp4QjBtTjUvZXNFSjVSWGtMWDUxVFUzdGovNVZXTFEwMUdPRUhDQVZhUFpLRGpiYU5yNGRPbHBDZE04TWsxQmJuCkVNUUtML3J5UmJZU0xYK0ViOHN5Rll4NUVkWkxqc215Q1o4em1QZG01NURsVnh1Tm5CMjRNb0tGSExhYXdLL2MKaTA3VkVOR3k0OWw3dG1lTmRhK1QyNG04bkNlTzkveitqS1MxdUxQbjRZdkp6QT09Cj1DQ3F0Ci0tLS0tRU5EIFBHUCBQUklWQVRFIEtFWSBCTE9DSy0tLS0tCg==

View file

@ -32,6 +32,7 @@ jobs:
script: |
const fs = require('fs');
core.setOutput('pgp', fs.readFileSync('.github/test-key.pgp', {encoding: 'utf8'}));
core.setOutput('pgp-base64', fs.readFileSync('.github/test-key-base64.pgp', {encoding: 'utf8'}));
core.setOutput('passphrase', fs.readFileSync('.github/test-key.pass', {encoding: 'utf8'}));
-
name: Import GPG private key
@ -52,3 +53,22 @@ jobs:
echo "keyid: ${{ steps.import_gpg.outputs.keyid }}"
echo "name: ${{ steps.import_gpg.outputs.name }}"
echo "email: ${{ steps.import_gpg.outputs.email }}"
-
name: Import GPG private key in base64 format
id: import_gpg_base64
uses: ./
with:
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
git_push_gpgsign: true
env:
GPG_PRIVATE_KEY: ${{ steps.test.outputs.pgp-base64 }}
PASSPHRASE: ${{ steps.test.outputs.passphrase }}
-
name: GPG user IDs
run: |
echo "fingerprint: ${{ steps.import_gpg_base64.outputs.fingerprint }}"
echo "keyid: ${{ steps.import_gpg_base64.outputs.keyid }}"
echo "name: ${{ steps.import_gpg_base64.outputs.name }}"
echo "email: ${{ steps.import_gpg_base64.outputs.email }}"

View file

@ -40,12 +40,18 @@ describe('gpg', () => {
});
describe('importKey', () => {
it('imports key to GnuPG', async () => {
it('imports key (as armored string) to GnuPG', async () => {
await gpg.importKey(userInfo.pgp).then(output => {
console.log(output);
expect(output).not.toEqual('');
});
});
it('imports key (as base64 string) to GnuPG', async () => {
await gpg.importKey(Buffer.from(userInfo.pgp).toString('base64')).then(output => {
console.log(output);
expect(output).not.toEqual('');
});
});
});
describe('getKeygrip', () => {

5
dist/index.js generated vendored
View file

@ -1270,10 +1270,11 @@ exports.getDirs = () => __awaiter(void 0, void 0, void 0, function* () {
};
});
});
exports.importKey = (armoredText) => __awaiter(void 0, void 0, void 0, function* () {
exports.importKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
const keyFolder = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-import-gpg-'));
const keyPath = `${keyFolder}/key.pgp`;
fs.writeFileSync(keyPath, armoredText, { mode: 0o600 });
const armored = key.trimLeft().startsWith('---') ? key : Buffer.from(key, 'base64').toString();
fs.writeFileSync(keyPath, armored, { mode: 0o600 });
return yield exec
.exec('gpg', ['--import', '--batch', '--yes', keyPath], true)
.then(res => {

View file

@ -102,10 +102,13 @@ export const getDirs = async (): Promise<Dirs> => {
});
};
export const importKey = async (armoredText: string): Promise<string> => {
export const importKey = async (key: string): Promise<string> => {
const keyFolder: string = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-import-gpg-'));
const keyPath: string = `${keyFolder}/key.pgp`;
fs.writeFileSync(keyPath, armoredText, {mode: 0o600});
const armored: string = key.trimLeft().startsWith('---') ? key : Buffer.from(key, 'base64').toString();
fs.writeFileSync(keyPath, armored, {mode: 0o600});
return await exec
.exec('gpg', ['--import', '--batch', '--yes', keyPath], true)