Skip to content
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

feat(ec2): switch to using ed25519 to generate key pair #5637

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/awsService/ec2/sshKeyPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SshKeyPair {
}

public static async generateSshKeyPair(keyPath: string): Promise<void> {
const process = new ChildProcess(`ssh-keygen`, ['-t', 'rsa', '-N', '', '-q', '-f', keyPath])
const process = new ChildProcess(`ssh-keygen`, ['-t', 'ed25519', '-N', '', '-q', '-f', keyPath])
const result = await process.run()
if (result.exitCode !== 0) {
throw new ToolkitError('ec2: Failed to generate ssh key', { details: { stdout: result.stdout } })
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/test/awsService/ec2/sshKeyPair.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as fs from 'fs-extra'
import * as sinon from 'sinon'
import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../../../shared/filesystemUtilities'
import { SshKeyPair } from '../../../awsService/ec2/sshKeyPair'
import { ChildProcess } from '../../../shared/utilities/childProcess'

describe('SshKeyUtility', async function () {
let temporaryDirectory: string
Expand All @@ -29,6 +30,13 @@ describe('SshKeyUtility', async function () {
const contents = await fs.readFile(keyPath, 'utf-8')
assert.notStrictEqual(contents.length, 0)
})

it('uses ed25519 algorithm to generate the keys', async function () {
const process = new ChildProcess(`ssh-keygen`, ['-vvv', '-l', '-f', keyPath])
const result = await process.run()
// Check private key header for algorithm name
assert.strictEqual(result.stdout.includes('[ED25519 256]'), true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always great to see tests exercising actual reality instead of setting up mocks!

})
})

it('properly names the public key', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "use ed25519 to generate ec2 ssh key pair"
Hweinstock marked this conversation as resolved.
Show resolved Hide resolved
}
Loading