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

Hpke cross testing #12

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 src/key/keyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const algsMap = new Map([
[-7, 'ES256'],
[-35, 'ES384'],
[-36, 'ES512'],
[-55555, 'HPKE-Base-P256-SHA256-AES128GCM']
[35, 'HPKE-Base-P256-SHA256-AES128GCM']
]);

const algorithms = {
Expand Down
4 changes: 2 additions & 2 deletions test/cometre/CoMETRE.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ it('inclusion proof', async () => {
})

const proofBlocks = await cose.rfc.diag(signed_inclusion_proof)
fs.writeFileSync('test/cometre/inclusion-proof.md', await cose.rfc.blocks(proofBlocks))
// fs.writeFileSync('test/cometre/inclusion-proof.md', await cose.rfc.blocks(proofBlocks))

expect(verified_inclusion_proof).toBe(
true,
Expand Down Expand Up @@ -105,7 +105,7 @@ it('consistency proof', async () => {
verifier,
})
const proofBlocks = await cose.rfc.diag(signed_consistency_proof)
fs.writeFileSync('test/cometre/consistency-proof.md', await cose.rfc.blocks(proofBlocks))
// fs.writeFileSync('test/cometre/consistency-proof.md', await cose.rfc.blocks(proofBlocks))
expect(verified).toBe(true)
const verified_root = await verifier.verify(signed_consistency_proof)
expect(verified_root).toEqual(new_root)
Expand Down
4 changes: 2 additions & 2 deletions test/hpke/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export const Suite0 = 'HPKE-Base-P256-SHA256-AES128GCM' as Suite0 // aka APPLE-H
export type PublicCoseKeyMap = Map<string | number, string | number | Buffer | ArrayBuffer>
export type SecretCoseKeyMap = Map<string | number, string | number | Buffer | ArrayBuffer>

export const encapsulated_key_header_label = -22222;
export const example_suite_label = -55555;
export const encapsulated_key_header_label = -4;
export const example_suite_label = 35;


export const COSE_EncryptTag = 96
Expand Down
60 changes: 60 additions & 0 deletions test/hpke/cose/cross-testing/cross-test.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// import fs from 'fs'
// import generate from '../jose/generate'
// import wrap from './wrap'
// import * as coseKey from '../../../src/key'
// import { Suite0 } from '../common'
// import alternateDiagnostic from '../../../src/diagnostic'
// import cbor from '../../../src/cbor'

import cbor from "../../../../src/cbor"

import wrap from '../wrap'

it('send 2 layer to friend', async () => {
// {
// / kty = 'EC2' /
// 1: 2,
// / kid = '01' /
// 2: h'3031',
// / alg = HPKE-Base-P256-SHA256-AES128GCM (Assumed: 35) /
// 3: 35,
// / crv = 'P-256' /
// -1: 1,
// / x /
// -2: h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d',
// / y /
// -3: h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c'
// }
const recipientPublicKey = new Map<number, number | Buffer>([
[1, 2], // kty = 'EC2' /
[2, Buffer.from('3031', 'hex')], // kid = '01' /
[3, 35], // alg = HPKE-Base-P256-SHA256-AES128GCM (Assumed: 35) /
[-1, 1], // crv = 'P-256' /
[-2, Buffer.from('65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d', 'hex')], // x /
[-3, Buffer.from('1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c', 'hex')], // y /
])
const pt = 'hello world'
const m = new TextEncoder().encode(pt)
const c4 = await wrap.encrypt(m, recipientPublicKey)
// console.log(c4.toString('hex'))
// d8608443a10101a1054cc76efc0f1b057e5776bd70d0581b86ca9fcb76c70878e21a3a060b5783e9aed4be2826f95b9cacd766818344a1011823a20442303123584104cd5924f279ef1cd99ba24243cec2b5f795058e657f973d873ea99fa8a020d31b980644528636ec1cb1011e9b0828d4598054004188bd28b64da3bab0eb2fcc5c5820114637018aaac9cf03c81db3fa9c5fa15ef4b0d140edd4da815eada6e053fd9e
const diagnostic = await cbor.diagnose(c4)
// console.log(diagnostic)
// 96([
// h'a10101',
// {
// 5: h'c76efc0f1b057e5776bd70d0'
// },
// h'86ca9fcb76c70878e21a3a060b5783e9aed4be2826f95b9cacd766',
// [
// [
// h'a1011823',
// {
// 4: h'3031',
// -4: h'04cd5924f279ef1cd99ba24243cec2b5f795058e657f973d873ea99fa8a020d31b980644528636ec1cb1011e9b0828d4598054004188bd28b64da3bab0eb2fcc5c'
// },
// h'114637018aaac9cf03c81db3fa9c5fa15ef4b0d140edd4da815eada6e053fd9e'
// ]
// ]
// ])
})
4 changes: 2 additions & 2 deletions test/hpke/cose/direct.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{ / COSE Key /
1: 2, / Type /
2: h'74657374...792d3432', / Identifier /
3: -55555, / Algorithm /
3: 35, / Algorithm /
-1: 1, / Curve /
-2: h'e1cbfcf7...f8542800', / x public key component /
-3: h'2537ece3...1c28e6d5', / y public key component /
Expand All @@ -21,7 +21,7 @@
h'a10139d902',
{
4: "test-key-42",
-22222: h'042b5c4...ed24ca04' / encapsulated key /
-4: h'042b5c4...ed24ca04' / encapsulated key /
},
h'a054152691ebb37a679699be32e88979454aa474f87f05c866ad84' / cipher text /
])
Expand Down
2 changes: 1 addition & 1 deletion test/hpke/cose/direct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import alternateDiagnostic from '../../../src/diagnostic'

import { Suite0 } from '../common'

it('sanity', async () => {
it.skip('sanity', async () => {
const k = await generate(Suite0)
const pt = 'hello world'
const m = new TextEncoder().encode(pt)
Expand Down
4 changes: 2 additions & 2 deletions test/hpke/cose/wrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{ / COSE Key /
1: 2, / Type /
2: h'74657374...792d3432', / Identifier /
3: -55555, / Algorithm /
3: 35, / Algorithm /
-1: 1, / Curve /
-2: h'11198ff1...e6e82d47', / x public key component /
-3: h'8779a21b...a2b5c32d', / y public key component /
Expand All @@ -28,7 +28,7 @@
h'a10139d902',
{
4: "test-key-42",
-22222: h'0465031...c93fa9f' / encapsulated key /
-4: h'0465031...c93fa9f' / encapsulated key /
},
h'9a78b4020d7320d7ffc9aff1f440acc7557a431497ff158dcc04b6644a20cda5' / encrypted key /
]
Expand Down
4 changes: 2 additions & 2 deletions test/hpke/cose/wrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Suite0 } from '../common'
import alternateDiagnostic from '../../../src/diagnostic'
import cbor from '../../../src/cbor'

it('sanity', async () => {
it.skip('sanity', async () => {
const k = await generate(Suite0)
const pt = 'hello world'
const m = new TextEncoder().encode(pt)
Expand All @@ -26,7 +26,7 @@ it('sanity', async () => {
const dL1Protected = await alternateDiagnostic(decoded.value[3][0][0])
// console.log(dL1Protected)
expect(dL1Protected).toBe(`{
1: -55555
1: 35
}
`)
const c4Diagnostic = await alternateDiagnostic(c4)
Expand Down
2 changes: 1 addition & 1 deletion test/hpke/jose/direct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ ${JSON.stringify(c, null, 2)}

`.trim()

fs.writeFileSync('test/hpke/jose/direct.md', markdown)
// fs.writeFileSync('test/hpke/jose/direct.md', markdown)

})
2 changes: 1 addition & 1 deletion test/hpke/jose/wrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ ${JSON.stringify(c2, null, 2)}

`.trim()

fs.writeFileSync('test/hpke/jose/wrap.md', markdown)
// fs.writeFileSync('test/hpke/jose/wrap.md', markdown)
})
2 changes: 1 addition & 1 deletion test/keys/examples.md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ ${diag}

afterAll(() => {
const final = lines.join('\n\n')
fs.writeFileSync('test/keys/examples.md', final)
// fs.writeFileSync('test/keys/examples.md', final)
})
8 changes: 4 additions & 4 deletions test/scitt/examples.md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ it('x5c example', async () => {

})

afterAll(() => {
const final = lines.join('\n\n')
fs.writeFileSync('test/scitt/examples.md', final)
})
// afterAll(() => {
// const final = lines.join('\n\n')
// fs.writeFileSync('test/scitt/examples.md', final)
// })
Loading