Skip to content
Snippets Groups Projects
Unverified Commit 0cfb1827 authored by Sigurd Spieckermann's avatar Sigurd Spieckermann Committed by GitHub
Browse files

fix(git): keep trailing newline in private SSH key (#31005)

parent 4ec7eae1
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,8 @@ describe('util/git/private-key', () => { ...@@ -89,7 +89,8 @@ describe('util/git/private-key', () => {
-----BEGIN OPENSSH PRIVATE KEY----- -----BEGIN OPENSSH PRIVATE KEY-----
some-private-key with-passphrase some-private-key with-passphrase
some-private-key with-passphrase some-private-key with-passphrase
-----END OPENSSH PRIVATE KEY-----`); -----END OPENSSH PRIVATE KEY-----
`);
await expect(writePrivateKey()).rejects.toThrow(); await expect(writePrivateKey()).rejects.toThrow();
}); });
...@@ -98,7 +99,8 @@ some-private-key with-passphrase ...@@ -98,7 +99,8 @@ some-private-key with-passphrase
-----BEGIN OPENSSH PRIVATE KEY----- -----BEGIN OPENSSH PRIVATE KEY-----
some-private-key some-private-key
some-private-key some-private-key
-----END OPENSSH PRIVATE KEY-----`; -----END OPENSSH PRIVATE KEY-----
`;
const privateKeyFile = upath.join(os.tmpdir() + '/git-private-ssh.key'); const privateKeyFile = upath.join(os.tmpdir() + '/git-private-ssh.key');
const publicKeyFile = `${privateKeyFile}.pub`; const publicKeyFile = `${privateKeyFile}.pub`;
const publicKey = 'some-public-key'; const publicKey = 'some-public-key';
......
...@@ -24,7 +24,7 @@ abstract class PrivateKey { ...@@ -24,7 +24,7 @@ abstract class PrivateKey {
protected abstract readonly gpgFormat: string; protected abstract readonly gpgFormat: string;
constructor(key: string) { constructor(key: string) {
this.key = key.trim(); this.key = key;
addSecretForSanitizing(this.key, 'global'); addSecretForSanitizing(this.key, 'global');
logger.debug( logger.debug(
'gitPrivateKey: successfully set (but not yet written/configured)', 'gitPrivateKey: successfully set (but not yet written/configured)',
...@@ -57,6 +57,10 @@ abstract class PrivateKey { ...@@ -57,6 +57,10 @@ abstract class PrivateKey {
class GPGKey extends PrivateKey { class GPGKey extends PrivateKey {
protected readonly gpgFormat = 'openpgp'; protected readonly gpgFormat = 'openpgp';
constructor(key: string) {
super(key.trim());
}
protected async importKey(): Promise<string | undefined> { protected async importKey(): Promise<string | undefined> {
const keyFileName = upath.join(os.tmpdir() + '/git-private-gpg.key'); const keyFileName = upath.join(os.tmpdir() + '/git-private-gpg.key');
await fs.outputFile(keyFileName, this.key); await fs.outputFile(keyFileName, this.key);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment