Skip to content

Commit

Permalink
revise addBinders
Browse files Browse the repository at this point in the history
  • Loading branch information
Srabutdotcom committed Jan 2, 2025
1 parent 6784eb1 commit 2c5151d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tls/keyexchange",
"version": "0.0.9",
"version": "0.1.0",
"exports": "./src/mod.ts",
"publish": {
"exclude": ["dist/"]
Expand Down
20 changes: 14 additions & 6 deletions src/clienthello.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ClientHello extends Struct {
cipher_suites; // offset = 33;
legacy_compression_methods; // offset = 33 + cipher_suites.length
extensions;
ext = {};
ext = new Map;
static fromHandShake(handshake) {
const copy = Uint8Array.from(handshake);
let offset = 0;
Expand Down Expand Up @@ -65,9 +65,12 @@ export class ClientHello extends Struct {
this.legacy_session = legacy_session;
this.cipher_suites = cipher_suites;
this.legacy_compression_methods = legacy_compression_methods
let offset = legacy_version.length + random.length + legacy_session.length
+ cipher_suites.length + legacy_compression_methods.length;
this.extensions = extensions;
for (const ex of extensions) {
this.ext[ex.extension_type?.name] = ex.extension_data
this.ext.set(ex.extension_type?.name, {pos: offset + 2, data: ex.extension_data});
offset += ex.length;
}
}
static fromServerName(serverName) {
Expand All @@ -85,12 +88,17 @@ export class ClientHello extends Struct {
))
)
}
toRecord() {
toRecord() {
return ContentType.HANDSHAKE.tlsPlainText(
HandshakeType.CLIENT_HELLO.handshake(this)
) }
add(data){
const array = safeuint8array(this, data);
)
}
addBinders(binders) {
const psk = this.ext.get('PRE_SHARED_KEY');
const lengthOf = psk.data.length + binders.length;
const uint16 = Uint16.fromValue(lengthOf)
const array = safeuint8array(this, binders);
array.set(uint16, psk.pos + 2);
return ClientHello.from(array)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/serverhello.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ function parseExtension(extension) {
function fromClient_hello(clientHello) {
const { legacy_session, cipher_suites, ext } = clientHello;
const { ciphers } = cipher_suites;
const { KEY_SHARE } = ext;
const { keyShareEntries } = KEY_SHARE
const KEY_SHARE = ext.get('KEY_SHARE');
const { keyShareEntries } = KEY_SHARE.data;
const cipherPreferences = new Set([Cipher.AES_128_GCM_SHA256, Cipher.AES_256_GCM_SHA384, Cipher.CHACHA20_POLY1305_SHA256]);
const namedGroupPreferences = new Set([NamedGroup.X25519, NamedGroup.SECP256R1, NamedGroup.SECP384R1])
const cipher = cipherPreferences.intersection(ciphers).values().next().value//selectFirstMatch(ciphers, cipherPreferences);
Expand Down
4 changes: 4 additions & 0 deletions test/clienthello_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,9 @@ const clientHelloPSKBinder = HexaDecimal.fromString(
).byte

const clientHelloPSKBinderBack = ClientHello.fromHandShake(clientHelloPSKBinder);
const binders = HexaDecimal.fromString(`00 21 20 3a dd 4f b2 d8 fd f8 22 a0 ca
3c f7 67 8e f5 e8 8d ae 99 01 41 c5 92 4d 57 bb 6f a3 1b 9e 5f
9d`).byte;
const clientHelloPsk_0 = clientHelloPSKBinderBack.addBinders(binders)

debugger;
4 changes: 2 additions & 2 deletions type/clienthello.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export class ClientHello extends Struct {
/**
* Appends the given data to the current instance and creates a new `ClientHello` object.
*
* @param {Uint8Array} data - The data to be appended. Must be a valid `Uint8Array`.
* @param {Uint8Array} binders - The data to be appended. Must be a valid `Uint8Array`.
* @returns {ClientHello} A new `ClientHello` instance with the combined data.
*/
add(data: Uint8Array): ClientHello;
addBinders(binders: Uint8Array): ClientHello;
}

/**
Expand Down

0 comments on commit 2c5151d

Please sign in to comment.