Skip to content

Commit

Permalink
chore(x509): remove key prefix for buggy compression algo
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <sliedrecht@berend.io>
  • Loading branch information
berendsliedrecht committed Oct 14, 2024
1 parent 6282482 commit c3e186c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/modules/x509/X509Certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export class X509Certificate {
if (keyBytes[0] !== 0x04) {
throw new X509Error('Received P256 key with 65 bytes, but key did not start with 0x04. Invalid key')
}
keyBytes = compress(keyBytes)
// TODO(crypto): the compress method is bugged because it does not expect the required `0x04` prefix. Here we strip that and receive the expected result
keyBytes = compress(keyBytes.slice(1))
}

const key = new Key(keyBytes, keyType)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/modules/x509/__tests__/X509Service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ describe('X509Service', () => {
const x509Certificate = X509Service.parseCertificate(agentContext, { encodedCertificate })

expect(x509Certificate.publicKey.publicKey.length).toStrictEqual(33)
expect(x509Certificate.publicKey.publicKeyBase58).toStrictEqual('tzf7ci2SqwnesE1Ppb8NPhWfMJpuWpRETfLegmsaooBY')
expect(x509Certificate.publicKey.publicKeyBase58).toStrictEqual('23vfBuUJkWXTC3zZWMh1TR57CTubFjFfhm4CGfgszRMHU')

const jwk = getJwkFromKey(x509Certificate.publicKey)

expect(jwk).toBeInstanceOf(P256Jwk)
expect(jwk).toMatchObject({
x: 'BIk8LYNHkG3GzWm39javS_1TP5YYTwqtrNEIMNpEcds',
y: '2UODj-scC_6OYXAeLtWqbo6SP4tU1coNPU0qLjxCBCE',
x: 'iTwtg0eQbcbNabf2Nq9L_VM_lhhPCq2s0Qgw2kRx29s',
y: 'YKwXDRz8U0-uLZ3NSI93R_35eNkl6jHp6Qg8OCup7VM',
})
})

Expand Down

0 comments on commit c3e186c

Please sign in to comment.