Skip to content

Commit 4c3e64c

Browse files
feat(ec2): switch to using ed25519 to generate key pair (#5637)
## Problem currently use RSA. ## Solution switch to ed25519 --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Justin M. Keyes <[email protected]>
1 parent 86ed46d commit 4c3e64c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

packages/core/src/awsService/ec2/sshKeyPair.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class SshKeyPair {
2121
}
2222

2323
public static async generateSshKeyPair(keyPath: string): Promise<void> {
24-
const process = new ChildProcess(`ssh-keygen`, ['-t', 'rsa', '-N', '', '-q', '-f', keyPath])
24+
const process = new ChildProcess(`ssh-keygen`, ['-t', 'ed25519', '-N', '', '-q', '-f', keyPath])
2525
const result = await process.run()
2626
if (result.exitCode !== 0) {
2727
throw new ToolkitError('ec2: Failed to generate ssh key', { details: { stdout: result.stdout } })

packages/core/src/test/awsService/ec2/sshKeyPair.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as fs from 'fs-extra'
88
import * as sinon from 'sinon'
99
import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../../../shared/filesystemUtilities'
1010
import { SshKeyPair } from '../../../awsService/ec2/sshKeyPair'
11+
import { ChildProcess } from '../../../shared/utilities/childProcess'
1112

1213
describe('SshKeyUtility', async function () {
1314
let temporaryDirectory: string
@@ -29,6 +30,13 @@ describe('SshKeyUtility', async function () {
2930
const contents = await fs.readFile(keyPath, 'utf-8')
3031
assert.notStrictEqual(contents.length, 0)
3132
})
33+
34+
it('uses ed25519 algorithm to generate the keys', async function () {
35+
const process = new ChildProcess(`ssh-keygen`, ['-vvv', '-l', '-f', keyPath])
36+
const result = await process.run()
37+
// Check private key header for algorithm name
38+
assert.strictEqual(result.stdout.includes('[ED25519 256]'), true)
39+
})
3240
})
3341

3442
it('properly names the public key', function () {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "EC2 connect: use ed25519 to generate ec2 ssh key pair"
4+
}

0 commit comments

Comments
 (0)