-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(config)!: replace kbpgp with gpg CLI
#37147
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
929abc8
d0dab97
dfc52eb
d489c01
7880abb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import os from 'node:os'; | ||
| import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is'; | ||
| import { mkdtemp, outputFile, rm } from 'fs-extra'; | ||
| import upath from 'upath'; | ||
| import { logger } from '../../logger'; | ||
| import { exec } from '../../util/exec'; | ||
|
|
||
| const keyImported = new Set<string>(); | ||
|
|
||
| export async function tryDecryptGnupg( | ||
| privateKey: string, | ||
| encryptedStr: string, | ||
| ): Promise<string | null> { | ||
| const tmpDir = await mkdtemp(upath.join(os.tmpdir(), 'renovate-gpg-')); | ||
|
|
||
| if (!keyImported.has(privateKey)) { | ||
| try { | ||
| const keyFilePath = upath.join(tmpDir, 'key.pem'); | ||
| await outputFile(keyFilePath, privateKey); | ||
| const { stdout, stderr } = await exec( | ||
| `gpg --batch --no-tty --yes --import ${keyFilePath}`, | ||
| ); | ||
| keyImported.add(privateKey); | ||
|
|
||
| logger.debug({ stdout, stderr }, 'Private key import result'); | ||
| } catch (err) { | ||
| logger.debug(`Private key import failed: ${err.message}`); | ||
| // cleanup temp dir | ||
| await rm(tmpDir, { recursive: true, force: true }); | ||
| return null; | ||
| } | ||
| } | ||
| try { | ||
| const startBlock = '-----BEGIN PGP MESSAGE-----\n\n'; | ||
| const endBlock = '\n-----END PGP MESSAGE-----\n'; | ||
| let armoredMessage = encryptedStr.trim(); | ||
| if (!armoredMessage.startsWith(startBlock)) { | ||
| armoredMessage = `${startBlock}${armoredMessage}`; | ||
| } | ||
| if (!armoredMessage.endsWith(endBlock)) { | ||
| armoredMessage = `${armoredMessage}${endBlock}`; | ||
| } | ||
| const encryptedFilePath = upath.join(tmpDir, 'msg.pem'); | ||
| await outputFile(encryptedFilePath, armoredMessage); | ||
|
|
||
| const { stdout, stderr } = await exec( | ||
| `gpg --batch --no-tty --yes --decrypt ${encryptedFilePath}`, | ||
viceice marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| logger.debug({ stderr }, 'Decrypted config using gnupg'); | ||
| return stdout; | ||
| } catch (err) { | ||
| if ( | ||
| 'exitCode' in err && | ||
| err.exitCode === 2 && | ||
| isNonEmptyStringAndNotWhitespace(err.stdout) | ||
| ) { | ||
| // gpg returns exit code 2 when it cannot fully decrypt the message, but stdout may contain what we need | ||
| logger.debug( | ||
| `Decryption failed, but stdout is available: ${err.message}`, | ||
| ); | ||
| return err.stdout; | ||
| } | ||
| logger.debug(`Decryption failed using gnupg: ${err.message}`); | ||
| return null; | ||
| /* v8 ignore next -- coverage bug */ | ||
| } finally { | ||
| // cleanup temp dir | ||
| await rm(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,7 +173,6 @@ | |
| "@pnpm/parse-overrides": "1001.0.0", | ||
| "@qnighy/marshal": "0.1.3", | ||
| "@renovatebot/detect-tools": "1.1.0", | ||
| "@renovatebot/kbpgp": "4.0.1", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth then deprecating this library? Looks like it's only Renovate using it: https://deps.dev/npm/%40renovatebot%2Fkbpgp/4.0.3/dependents There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, but i'm thinking of using https://github.com/renovatebot/pgp (dotnet wasm variant) instead of the cli 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've raised renovatebot/kbpgp#216 for the deprecation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sounds like a plan - is that something that needs much validation ahead of next week's major release? |
||
| "@renovatebot/osv-offline": "1.6.8", | ||
| "@renovatebot/pep440": "4.1.0", | ||
| "@renovatebot/ruby-semver": "4.0.0", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.