luci-mod-network: Correctly encode/decode ech field in HTTPS record

Signed-off-by: Anya Lin <hukk1996@gmail.com>
This commit is contained in:
Anya Lin
2025-09-26 00:59:01 +08:00
committed by Paul Donald
parent d42dce3ea2
commit 39637490ae

View File

@@ -163,6 +163,7 @@ return baseclass.extend({
return keys.map(n => [(n >> 8) & 0xff, n & 0xff]).flat();
case 'ech': // Assume ech is in base64
return Array.prototype.map.call(atob(value), c => c.charCodeAt(0)); // OR Uint8Array.fromBase64(value)
case 'alpn':
/* (RFC 9460 §7.1.1 The wire-format value for "alpn" consists of
at least one alpn-id prefixed by its length as a single octet */
@@ -320,6 +321,7 @@ return baseclass.extend({
return keys.join(',');
case 'ech':
return btoa(String.fromCharCode(...buf)); // OR buf.toBase64()
case 'alpn': {
let pos = 0, result = [];
while (pos < buf.length) {