Skip to content

Commit 217432c

Browse files
committed
enable use of ed25519 keys
1 parent 421d90e commit 217432c

5 files changed

Lines changed: 27 additions & 34 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A seed is used to generate the secret, it's recommended you don't use the same s
3030

3131
## ⚠️ Limitations
3232

33-
- Can't use ecdsa/ed25519 keys, they always give different signatures
33+
- Can't use ECDSA keys, they always give different signatures
3434

3535
## 💻 CLI usage
3636

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ssh-agent-secrets",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "Encrypt and decrypt secrets using an SSH agent",
55
"keywords": [
66
"ssh",

src/lib/ssh_agent_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class SSHAgentClient {
256256
key: SSHKey,
257257
seed: string,
258258
): Promise<{ cipherKey: crypto.KeyObject; ivLength: number }> {
259-
if (key.type !== 'ssh-rsa') {
259+
if (key.type !== 'ssh-rsa' && key.type !== 'ssh-ed25519') {
260260
throw new Error(`${key.type} key is forbidden, it always gives different signatures!`)
261261
}
262262
// Use SSH signature as decryption key

test/ssh_agent_cli.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('ssh-crypt cli tests', () => {
3030
})
3131
it('should encrypt', () => {
3232
const output = execSync(
33-
`echo 'Lorem ipsum dolor' | npm exec -- tsx src/cli.ts -k key_rsa -s not_a_secret --encryptEncoding hex encrypt`,
33+
`echo 'Lorem ipsum dolor' | npm exec -- tsx src/cli.ts -k key_ed25519 -s not_a_secret --encryptEncoding hex encrypt`,
3434
{
3535
encoding: 'ascii',
3636
},
Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,39 @@ import { SSHAgentClient } from '../src/lib/ssh_agent_client.ts'
55

66
chai.use(chaiAsPromised)
77

8-
describe('RSA key mandatory tests', () => {
9-
it("doesn't give the same signature twice with an ECDSA key", async () => {
8+
describe('SSH key type tests', () => {
9+
it('does give the same signature twice with RSA key', async () => {
1010
const agent = new SSHAgentClient()
11-
const identity = await agent.getIdentity('key_ecdsa')
11+
const identity = await agent.getIdentity('key_rsa')
1212
if (!identity) {
1313
throw new Error()
1414
}
15-
const signature1 = await agent.sign(identity, Buffer.from('hello', 'utf8'))
16-
const signature2 = await agent.sign(identity, Buffer.from('hello', 'utf8'))
17-
chai.assert.notEqual(signature1, signature2)
15+
const buffer = Buffer.from('not_a_secret', 'utf8')
16+
const signature1 = await agent.sign(identity, buffer)
17+
const signature2 = await agent.sign(identity, buffer)
18+
chai.assert.equal(signature1.signature, signature2.signature)
1819
})
19-
it("doesn't give the same signature twice with an ED25519 key", async () => {
20+
it('does give the same signature twice with ED25519 key', async () => {
2021
const agent = new SSHAgentClient()
2122
const identity = await agent.getIdentity('key_ed25519')
2223
if (!identity) {
2324
throw new Error()
2425
}
25-
const signature1 = await agent.sign(identity, Buffer.from('hello', 'utf8'))
26-
const signature2 = await agent.sign(identity, Buffer.from('hello', 'utf8'))
27-
chai.assert.notEqual(signature1, signature2)
26+
const buffer = Buffer.from('not_a_secret', 'utf8')
27+
const signature1 = await agent.sign(identity, buffer)
28+
const signature2 = await agent.sign(identity, buffer)
29+
chai.assert.equal(signature1.signature, signature2.signature)
30+
})
31+
it("doesn't give the same signature twice with an ECDSA key", async () => {
32+
const agent = new SSHAgentClient()
33+
const identity = await agent.getIdentity('key_ecdsa')
34+
if (!identity) {
35+
throw new Error()
36+
}
37+
const buffer = Buffer.from('not_a_secret', 'utf8')
38+
const signature1 = await agent.sign(identity, buffer)
39+
const signature2 = await agent.sign(identity, buffer)
40+
chai.assert.notEqual(signature1.signature, signature2.signature)
2841
})
2942
it('should throw if using ECDSA key for encrypting', async () => {
3043
const agent = new SSHAgentClient()
@@ -52,24 +65,4 @@ describe('RSA key mandatory tests', () => {
5265
'ecdsa-sha2-nistp256 key is forbidden, it always gives different signatures!',
5366
)
5467
})
55-
it('should throw if using ED25519 key for encrypting', async () => {
56-
const agent = new SSHAgentClient()
57-
const identity = await agent.getIdentity('key_ed25519')
58-
if (!identity) {
59-
throw new Error()
60-
}
61-
return chai
62-
.expect(agent.encrypt(identity, 'not_a_secret', Buffer.from('', 'utf8')))
63-
.to.be.rejectedWith(Error, 'ssh-ed25519 key is forbidden, it always gives different signatures!')
64-
})
65-
it('should throw if using ED25519 key for decrypting', async () => {
66-
const agent = new SSHAgentClient()
67-
const identity = await agent.getIdentity('key_ed25519')
68-
if (!identity) {
69-
throw new Error()
70-
}
71-
return chai
72-
.expect(agent.decrypt(identity, 'not_a_secret', ''))
73-
.to.be.rejectedWith(Error, 'ssh-ed25519 key is forbidden, it always gives different signatures!')
74-
})
7568
})

0 commit comments

Comments
 (0)