@rstreamlabs/webtty 1.9.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -9
- package/dist/{chunk-QOAMHBHC.mjs → chunk-6DA72SBW.mjs} +368 -47
- package/dist/index.d.mts +23 -9
- package/dist/index.d.ts +23 -9
- package/dist/index.js +370 -47
- package/dist/index.mjs +5 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +385 -52
- package/dist/node.mjs +20 -6
- package/package.json +5 -5
package/dist/node.js
CHANGED
|
@@ -69,6 +69,8 @@ __export(node_exports, {
|
|
|
69
69
|
verifyWebTTYServerProofTranscript: () => verifyWebTTYServerProofTranscript,
|
|
70
70
|
webTTYClientProofTranscriptBytes: () => webTTYClientProofTranscriptBytes,
|
|
71
71
|
webTTYE2EKeyID: () => webTTYE2EKeyID,
|
|
72
|
+
webTTYFIPSCompatibleKeyEnvelopeSuite: () => webTTYFIPSCompatibleKeyEnvelopeSuite,
|
|
73
|
+
webTTYFIPSCompatiblePayloadSuite: () => webTTYFIPSCompatiblePayloadSuite,
|
|
72
74
|
webTTYRecordedEventEncryptedPayload: () => webTTYRecordedEventEncryptedPayload,
|
|
73
75
|
webTTYServerProofTranscriptBytes: () => webTTYServerProofTranscriptBytes,
|
|
74
76
|
webTTYSigningKeyID: () => webTTYSigningKeyID
|
|
@@ -985,6 +987,7 @@ var rstream = $root.rstream = (() => {
|
|
|
985
987
|
values[valuesById[0] = "PAYLOAD_CIPHER_SUITE_UNSPECIFIED"] = 0;
|
|
986
988
|
values[valuesById[1] = "PAYLOAD_CIPHER_SUITE_AES_256_GCM"] = 1;
|
|
987
989
|
values[valuesById[2] = "PAYLOAD_CIPHER_SUITE_CHACHA20_POLY1305"] = 2;
|
|
990
|
+
values[valuesById[3] = "PAYLOAD_CIPHER_SUITE_AES_256_GCM_RANDOM_NONCE"] = 3;
|
|
988
991
|
return values;
|
|
989
992
|
})();
|
|
990
993
|
protobuf.KeyEnvelopeSuite = (function() {
|
|
@@ -992,6 +995,7 @@ var rstream = $root.rstream = (() => {
|
|
|
992
995
|
values[valuesById[0] = "KEY_ENVELOPE_SUITE_UNSPECIFIED"] = 0;
|
|
993
996
|
values[valuesById[1] = "KEY_ENVELOPE_SUITE_HPKE_X25519_HKDF_SHA256_AES_256_GCM"] = 1;
|
|
994
997
|
values[valuesById[2] = "KEY_ENVELOPE_SUITE_HPKE_X25519_HKDF_SHA256_CHACHA20_POLY1305"] = 2;
|
|
998
|
+
values[valuesById[3] = "KEY_ENVELOPE_SUITE_P256_HKDF_SHA256_AES_256_GCM_RANDOM_NONCE"] = 3;
|
|
995
999
|
return values;
|
|
996
1000
|
})();
|
|
997
1001
|
protobuf.ProtocolVersion = (function() {
|
|
@@ -1494,6 +1498,10 @@ var rstream = $root.rstream = (() => {
|
|
|
1494
1498
|
case 2:
|
|
1495
1499
|
message.keyEnvelopeSuite = 2;
|
|
1496
1500
|
break;
|
|
1501
|
+
case "KEY_ENVELOPE_SUITE_P256_HKDF_SHA256_AES_256_GCM_RANDOM_NONCE":
|
|
1502
|
+
case 3:
|
|
1503
|
+
message.keyEnvelopeSuite = 3;
|
|
1504
|
+
break;
|
|
1497
1505
|
default:
|
|
1498
1506
|
if (typeof object.keyEnvelopeSuite === "number" && (object.keyEnvelopeSuite | 0) === object.keyEnvelopeSuite)
|
|
1499
1507
|
message.keyEnvelopeSuite = object.keyEnvelopeSuite;
|
|
@@ -2178,6 +2186,10 @@ var rstream = $root.rstream = (() => {
|
|
|
2178
2186
|
case 2:
|
|
2179
2187
|
message.payloadSuites[message.payloadSuites.length] = 2;
|
|
2180
2188
|
break;
|
|
2189
|
+
case "PAYLOAD_CIPHER_SUITE_AES_256_GCM_RANDOM_NONCE":
|
|
2190
|
+
case 3:
|
|
2191
|
+
message.payloadSuites[message.payloadSuites.length] = 3;
|
|
2192
|
+
break;
|
|
2181
2193
|
default:
|
|
2182
2194
|
if (typeof object.payloadSuites[i] === "number" && (object.payloadSuites[i] | 0) === object.payloadSuites[i])
|
|
2183
2195
|
message.payloadSuites[message.payloadSuites.length] = object.payloadSuites[i];
|
|
@@ -2201,6 +2213,10 @@ var rstream = $root.rstream = (() => {
|
|
|
2201
2213
|
case 2:
|
|
2202
2214
|
message.keyEnvelopeSuites[message.keyEnvelopeSuites.length] = 2;
|
|
2203
2215
|
break;
|
|
2216
|
+
case "KEY_ENVELOPE_SUITE_P256_HKDF_SHA256_AES_256_GCM_RANDOM_NONCE":
|
|
2217
|
+
case 3:
|
|
2218
|
+
message.keyEnvelopeSuites[message.keyEnvelopeSuites.length] = 3;
|
|
2219
|
+
break;
|
|
2204
2220
|
default:
|
|
2205
2221
|
if (typeof object.keyEnvelopeSuites[i] === "number" && (object.keyEnvelopeSuites[i] | 0) === object.keyEnvelopeSuites[i])
|
|
2206
2222
|
message.keyEnvelopeSuites[message.keyEnvelopeSuites.length] = object.keyEnvelopeSuites[i];
|
|
@@ -2674,6 +2690,10 @@ var rstream = $root.rstream = (() => {
|
|
|
2674
2690
|
case 2:
|
|
2675
2691
|
message.payloadSuite = 2;
|
|
2676
2692
|
break;
|
|
2693
|
+
case "PAYLOAD_CIPHER_SUITE_AES_256_GCM_RANDOM_NONCE":
|
|
2694
|
+
case 3:
|
|
2695
|
+
message.payloadSuite = 3;
|
|
2696
|
+
break;
|
|
2677
2697
|
default:
|
|
2678
2698
|
if (typeof object.payloadSuite === "number" && (object.payloadSuite | 0) === object.payloadSuite)
|
|
2679
2699
|
message.payloadSuite = object.payloadSuite;
|
|
@@ -2718,6 +2738,10 @@ var rstream = $root.rstream = (() => {
|
|
|
2718
2738
|
case 2:
|
|
2719
2739
|
message.keyEnvelopeSuite = 2;
|
|
2720
2740
|
break;
|
|
2741
|
+
case "KEY_ENVELOPE_SUITE_P256_HKDF_SHA256_AES_256_GCM_RANDOM_NONCE":
|
|
2742
|
+
case 3:
|
|
2743
|
+
message.keyEnvelopeSuite = 3;
|
|
2744
|
+
break;
|
|
2721
2745
|
default:
|
|
2722
2746
|
if (typeof object.keyEnvelopeSuite === "number" && (object.keyEnvelopeSuite | 0) === object.keyEnvelopeSuite)
|
|
2723
2747
|
message.keyEnvelopeSuite = object.keyEnvelopeSuite;
|
|
@@ -2945,6 +2969,10 @@ var rstream = $root.rstream = (() => {
|
|
|
2945
2969
|
case 2:
|
|
2946
2970
|
message.payloadSuite = 2;
|
|
2947
2971
|
break;
|
|
2972
|
+
case "PAYLOAD_CIPHER_SUITE_AES_256_GCM_RANDOM_NONCE":
|
|
2973
|
+
case 3:
|
|
2974
|
+
message.payloadSuite = 3;
|
|
2975
|
+
break;
|
|
2948
2976
|
default:
|
|
2949
2977
|
if (typeof object.payloadSuite === "number" && (object.payloadSuite | 0) === object.payloadSuite)
|
|
2950
2978
|
message.payloadSuite = object.payloadSuite;
|
|
@@ -7455,6 +7483,7 @@ function authRequirementCode(value) {
|
|
|
7455
7483
|
function payloadSuiteCode(value) {
|
|
7456
7484
|
if (value === "aes-256-gcm" || value === void 0) return 1;
|
|
7457
7485
|
if (value === "chacha20-poly1305") return 2;
|
|
7486
|
+
if (value === "aes-256-gcm-random-nonce") return 3;
|
|
7458
7487
|
return 0;
|
|
7459
7488
|
}
|
|
7460
7489
|
function keyEnvelopeSuiteCode(value) {
|
|
@@ -7462,6 +7491,7 @@ function keyEnvelopeSuiteCode(value) {
|
|
|
7462
7491
|
return 1;
|
|
7463
7492
|
}
|
|
7464
7493
|
if (value === "hpke-x25519-hkdf-sha256-chacha20-poly1305") return 2;
|
|
7494
|
+
if (value === "p256-hkdf-sha256-aes-256-gcm-random-nonce") return 3;
|
|
7465
7495
|
return 0;
|
|
7466
7496
|
}
|
|
7467
7497
|
function signatureSuiteCode(value) {
|
|
@@ -7662,6 +7692,8 @@ function normalizeSessionKeyGrant(grant) {
|
|
|
7662
7692
|
// src/e2e-crypto.ts
|
|
7663
7693
|
var x25519PublicKeySize = 32;
|
|
7664
7694
|
var x25519PrivateKeySize = 32;
|
|
7695
|
+
var p256PublicKeySize = 65;
|
|
7696
|
+
var p256PrivateKeySize = 32;
|
|
7665
7697
|
var payloadKeySize = 32;
|
|
7666
7698
|
var payloadKeyIDSize = 16;
|
|
7667
7699
|
var aesGCMNonceSize = 12;
|
|
@@ -7674,21 +7706,24 @@ var keyIDDomain = "rstream-webtty-e2e-key-id/v1";
|
|
|
7674
7706
|
var hpkeVersionLabel = "HPKE-v1";
|
|
7675
7707
|
var nominalPayloadSuite = "aes-256-gcm";
|
|
7676
7708
|
var nominalKeyEnvelopeSuite = "hpke-x25519-hkdf-sha256-aes-256-gcm";
|
|
7677
|
-
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7709
|
+
var webTTYFIPSCompatiblePayloadSuite = "aes-256-gcm-random-nonce";
|
|
7710
|
+
var webTTYFIPSCompatibleKeyEnvelopeSuite = "p256-hkdf-sha256-aes-256-gcm-random-nonce";
|
|
7711
|
+
async function generateWebTTYE2EIdentity(keyEnvelopeSuite = nominalKeyEnvelopeSuite) {
|
|
7712
|
+
payloadSuiteForKeyEnvelopeSuite(keyEnvelopeSuite);
|
|
7713
|
+
const algorithm = keyEnvelopeSuite === webTTYFIPSCompatibleKeyEnvelopeSuite ? { name: "ECDH", namedCurve: "P-256" } : { name: "X25519" };
|
|
7714
|
+
const pair = await getSubtle().generateKey(algorithm, true, ["deriveBits"]);
|
|
7715
|
+
if (!isCryptoKeyPair(pair)) {
|
|
7716
|
+
throw new Error("WebCrypto returned an unexpected E2E key pair");
|
|
7683
7717
|
}
|
|
7684
7718
|
const publicKey = new Uint8Array(
|
|
7685
7719
|
await getSubtle().exportKey("raw", pair.publicKey)
|
|
7686
7720
|
);
|
|
7687
7721
|
const jwk = await getSubtle().exportKey("jwk", pair.privateKey);
|
|
7688
7722
|
if (typeof jwk.d !== "string") {
|
|
7689
|
-
throw new Error("WebCrypto
|
|
7723
|
+
throw new Error("WebCrypto E2E private JWK is missing d");
|
|
7690
7724
|
}
|
|
7691
7725
|
return {
|
|
7726
|
+
keyEnvelopeSuite,
|
|
7692
7727
|
keyId: await webTTYE2EKeyID(publicKey),
|
|
7693
7728
|
privateKey: base64URLDecode(jwk.d),
|
|
7694
7729
|
publicKey
|
|
@@ -7729,8 +7764,8 @@ function createWebTTYE2EKeyContext(config) {
|
|
|
7729
7764
|
);
|
|
7730
7765
|
}
|
|
7731
7766
|
async function createWebTTYE2EClientPayloadCrypto(config) {
|
|
7732
|
-
const
|
|
7733
|
-
const
|
|
7767
|
+
const keyEnvelopeSuite = config.keyEnvelopeSuite ?? inferRecipientSuite(config.recipients);
|
|
7768
|
+
const payloadSuite = config.payloadSuite ?? payloadSuiteForKeyEnvelopeSuite(keyEnvelopeSuite);
|
|
7734
7769
|
validateSuites(payloadSuite, keyEnvelopeSuite);
|
|
7735
7770
|
const payloadKey = config.payloadKey ? cloneKeyMaterial(config.payloadKey) : randomBytes(payloadKeySize);
|
|
7736
7771
|
if (payloadKey.byteLength !== payloadKeySize) {
|
|
@@ -7822,7 +7857,7 @@ function createPayloadCrypto(options) {
|
|
|
7822
7857
|
payloadSuite: options.payloadSuite
|
|
7823
7858
|
};
|
|
7824
7859
|
const cryptoInfo = {
|
|
7825
|
-
keyAgreement: "HPKE X25519",
|
|
7860
|
+
keyAgreement: options.keyEnvelopeSuite === webTTYFIPSCompatibleKeyEnvelopeSuite ? "ECDH P-256" : "HPKE X25519",
|
|
7826
7861
|
keyDerivation: "HKDF-SHA256",
|
|
7827
7862
|
keyEncryption: "AES-256-GCM",
|
|
7828
7863
|
keyEnvelopeSuite: options.keyEnvelopeSuite,
|
|
@@ -7837,7 +7872,7 @@ function createPayloadCrypto(options) {
|
|
|
7837
7872
|
if (chunk.byteLength > 4294967295) {
|
|
7838
7873
|
throw new Error(`E2E payload is too large: ${chunk.byteLength} bytes`);
|
|
7839
7874
|
}
|
|
7840
|
-
const nonce = randomBytes(aesGCMNonceSize);
|
|
7875
|
+
const nonce = options.payloadSuite === webTTYFIPSCompatiblePayloadSuite ? new Uint8Array() : randomBytes(aesGCMNonceSize);
|
|
7841
7876
|
const payloadCrypto = {
|
|
7842
7877
|
aadContext: cloneBytes(options.keyContext),
|
|
7843
7878
|
nonce,
|
|
@@ -7845,7 +7880,8 @@ function createPayloadCrypto(options) {
|
|
|
7845
7880
|
payloadSuite: options.payloadSuite
|
|
7846
7881
|
};
|
|
7847
7882
|
return {
|
|
7848
|
-
ciphertext: await
|
|
7883
|
+
ciphertext: await encryptPayloadForSuite(
|
|
7884
|
+
options.payloadSuite,
|
|
7849
7885
|
options.payloadKey,
|
|
7850
7886
|
nonce,
|
|
7851
7887
|
cloneBytes(chunk),
|
|
@@ -7865,19 +7901,21 @@ function createPayloadCrypto(options) {
|
|
|
7865
7901
|
const decrypt = (stream) => async (payload) => {
|
|
7866
7902
|
validatePayloadEnvelope(payload, options);
|
|
7867
7903
|
const crypto = payload.payloadCrypto;
|
|
7868
|
-
if (crypto === void 0
|
|
7869
|
-
throw new Error("missing E2E payload
|
|
7904
|
+
if (crypto === void 0) {
|
|
7905
|
+
throw new Error("missing E2E payload crypto");
|
|
7870
7906
|
}
|
|
7871
|
-
const
|
|
7907
|
+
const nonce = crypto.nonce ?? new Uint8Array();
|
|
7908
|
+
const plaintext = await decryptPayloadForSuite(
|
|
7909
|
+
options.payloadSuite,
|
|
7872
7910
|
options.payloadKey,
|
|
7873
|
-
|
|
7911
|
+
nonce,
|
|
7874
7912
|
payload.ciphertext,
|
|
7875
7913
|
payloadAAD(
|
|
7876
7914
|
stream,
|
|
7877
7915
|
options.payloadSuite,
|
|
7878
7916
|
options.payloadKeyId,
|
|
7879
7917
|
options.keyContext,
|
|
7880
|
-
|
|
7918
|
+
nonce,
|
|
7881
7919
|
payload.plaintextLength
|
|
7882
7920
|
)
|
|
7883
7921
|
);
|
|
@@ -7922,21 +7960,29 @@ async function implicitKeyContextFromRecipients(recipients) {
|
|
|
7922
7960
|
}
|
|
7923
7961
|
async function wrapPayloadKey(payloadKey, payloadSuite, payloadKeyId, keyContext, suite, recipient) {
|
|
7924
7962
|
const recipientPublicKey = cloneKeyMaterial(recipient.publicKey);
|
|
7925
|
-
|
|
7963
|
+
const recipientSuite = recipient.keyEnvelopeSuite ?? inferKeyEnvelopeSuite(recipientPublicKey);
|
|
7964
|
+
if (recipientSuite !== suite) {
|
|
7965
|
+
throw new Error("E2E recipient suite does not match key envelope suite");
|
|
7966
|
+
}
|
|
7967
|
+
const expectedPublicKeySize = publicKeySizeForSuite(suite);
|
|
7968
|
+
if (recipientPublicKey.byteLength !== expectedPublicKeySize) {
|
|
7926
7969
|
throw new Error(
|
|
7927
|
-
`E2E recipient public key must be ${
|
|
7970
|
+
`E2E recipient public key must be ${expectedPublicKeySize} bytes`
|
|
7928
7971
|
);
|
|
7929
7972
|
}
|
|
7930
7973
|
const recipientKeyId = recipient.keyId ? cloneKeyMaterial(recipient.keyId) : await webTTYE2EKeyID(recipientPublicKey);
|
|
7931
7974
|
if (recipientKeyId.byteLength !== payloadKeyIDSize) {
|
|
7932
7975
|
throw new Error(`E2E recipient key id must be ${payloadKeyIDSize} bytes`);
|
|
7933
7976
|
}
|
|
7934
|
-
const
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
|
|
7977
|
+
const info = hpkeInfo(payloadSuite, payloadKeyId, keyContext, suite);
|
|
7978
|
+
const aad = hpkeAAD(
|
|
7979
|
+
recipientKeyId,
|
|
7980
|
+
payloadSuite,
|
|
7981
|
+
payloadKeyId,
|
|
7982
|
+
keyContext,
|
|
7983
|
+
suite
|
|
7939
7984
|
);
|
|
7985
|
+
const sealed = suite === webTTYFIPSCompatibleKeyEnvelopeSuite ? await p256Seal(recipientPublicKey, info, aad, payloadKey) : await hpkeSeal(recipientPublicKey, info, aad, payloadKey);
|
|
7940
7986
|
return {
|
|
7941
7987
|
encapsulatedKey: sealed.encapsulatedKey,
|
|
7942
7988
|
recipientKeyId,
|
|
@@ -7953,17 +7999,28 @@ async function unwrapPayloadKey(envelope, payloadSuite, payloadKeyId, keyContext
|
|
|
7953
7999
|
if (envelope.wrappedKey === void 0) {
|
|
7954
8000
|
throw new Error("E2E key envelope is missing wrapped key");
|
|
7955
8001
|
}
|
|
7956
|
-
|
|
8002
|
+
if (identity.keyEnvelopeSuite !== suite) {
|
|
8003
|
+
throw new Error("E2E identity suite does not match key envelope suite");
|
|
8004
|
+
}
|
|
8005
|
+
const info = hpkeInfo(payloadSuite, payloadKeyId, keyContext, suite);
|
|
8006
|
+
const aad = hpkeAAD(
|
|
8007
|
+
envelope.recipientKeyId,
|
|
8008
|
+
payloadSuite,
|
|
8009
|
+
payloadKeyId,
|
|
8010
|
+
keyContext,
|
|
8011
|
+
suite
|
|
8012
|
+
);
|
|
8013
|
+
const payloadKey = suite === webTTYFIPSCompatibleKeyEnvelopeSuite ? await p256Open(
|
|
7957
8014
|
identity,
|
|
7958
8015
|
envelope.encapsulatedKey,
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
8016
|
+
info,
|
|
8017
|
+
aad,
|
|
8018
|
+
envelope.wrappedKey
|
|
8019
|
+
) : await hpkeOpen(
|
|
8020
|
+
identity,
|
|
8021
|
+
envelope.encapsulatedKey,
|
|
8022
|
+
info,
|
|
8023
|
+
aad,
|
|
7967
8024
|
envelope.wrappedKey
|
|
7968
8025
|
);
|
|
7969
8026
|
if (payloadKey.byteLength !== payloadKeySize) {
|
|
@@ -8045,6 +8102,95 @@ async function hpkeOpen(identity, encapsulatedKey, info, aad, ciphertext) {
|
|
|
8045
8102
|
const schedule = await hpkeKeySchedule(sharedSecret, info);
|
|
8046
8103
|
return aesGCMDecrypt(schedule.key, schedule.baseNonce, ciphertext, aad);
|
|
8047
8104
|
}
|
|
8105
|
+
async function p256Seal(publicKey, info, aad, plaintext) {
|
|
8106
|
+
const recipientPublic = await getSubtle().importKey(
|
|
8107
|
+
"raw",
|
|
8108
|
+
bufferSource(publicKey),
|
|
8109
|
+
{ name: "ECDH", namedCurve: "P-256" },
|
|
8110
|
+
false,
|
|
8111
|
+
[]
|
|
8112
|
+
);
|
|
8113
|
+
const ephemeral = await getSubtle().generateKey(
|
|
8114
|
+
{ name: "ECDH", namedCurve: "P-256" },
|
|
8115
|
+
true,
|
|
8116
|
+
["deriveBits"]
|
|
8117
|
+
);
|
|
8118
|
+
if (!isCryptoKeyPair(ephemeral)) {
|
|
8119
|
+
throw new Error("WebCrypto returned an unexpected P-256 key pair");
|
|
8120
|
+
}
|
|
8121
|
+
const encapsulatedKey = new Uint8Array(
|
|
8122
|
+
await getSubtle().exportKey("raw", ephemeral.publicKey)
|
|
8123
|
+
);
|
|
8124
|
+
const sharedSecret = new Uint8Array(
|
|
8125
|
+
await getSubtle().deriveBits(
|
|
8126
|
+
{ name: "ECDH", public: recipientPublic },
|
|
8127
|
+
ephemeral.privateKey,
|
|
8128
|
+
256
|
|
8129
|
+
)
|
|
8130
|
+
);
|
|
8131
|
+
const wrappingKey = await p256WrappingKey(sharedSecret, info);
|
|
8132
|
+
return {
|
|
8133
|
+
encapsulatedKey,
|
|
8134
|
+
wrappedKey: await aesGCMEncryptWithPrefixedRandomNonce(
|
|
8135
|
+
wrappingKey,
|
|
8136
|
+
plaintext,
|
|
8137
|
+
aad
|
|
8138
|
+
)
|
|
8139
|
+
};
|
|
8140
|
+
}
|
|
8141
|
+
async function p256Open(identity, encapsulatedKey, info, aad, ciphertext) {
|
|
8142
|
+
if (identity.privateKey.byteLength !== p256PrivateKeySize) {
|
|
8143
|
+
throw new Error(
|
|
8144
|
+
`E2E identity private key must be ${p256PrivateKeySize} bytes`
|
|
8145
|
+
);
|
|
8146
|
+
}
|
|
8147
|
+
if (identity.publicKey.byteLength !== p256PublicKeySize || identity.publicKey[0] !== 4) {
|
|
8148
|
+
throw new Error(
|
|
8149
|
+
`E2E identity public key must be an uncompressed ${p256PublicKeySize}-byte P-256 point`
|
|
8150
|
+
);
|
|
8151
|
+
}
|
|
8152
|
+
const recipientPrivate = await importP256PrivateKey(identity);
|
|
8153
|
+
const ephemeralPublic = await getSubtle().importKey(
|
|
8154
|
+
"raw",
|
|
8155
|
+
bufferSource(encapsulatedKey),
|
|
8156
|
+
{ name: "ECDH", namedCurve: "P-256" },
|
|
8157
|
+
false,
|
|
8158
|
+
[]
|
|
8159
|
+
);
|
|
8160
|
+
const sharedSecret = new Uint8Array(
|
|
8161
|
+
await getSubtle().deriveBits(
|
|
8162
|
+
{ name: "ECDH", public: ephemeralPublic },
|
|
8163
|
+
recipientPrivate,
|
|
8164
|
+
256
|
|
8165
|
+
)
|
|
8166
|
+
);
|
|
8167
|
+
return aesGCMDecryptWithPrefixedRandomNonce(
|
|
8168
|
+
await p256WrappingKey(sharedSecret, info),
|
|
8169
|
+
ciphertext,
|
|
8170
|
+
aad
|
|
8171
|
+
);
|
|
8172
|
+
}
|
|
8173
|
+
async function p256WrappingKey(sharedSecret, info) {
|
|
8174
|
+
const key = await getSubtle().importKey(
|
|
8175
|
+
"raw",
|
|
8176
|
+
bufferSource(sharedSecret),
|
|
8177
|
+
"HKDF",
|
|
8178
|
+
false,
|
|
8179
|
+
["deriveBits"]
|
|
8180
|
+
);
|
|
8181
|
+
return new Uint8Array(
|
|
8182
|
+
await getSubtle().deriveBits(
|
|
8183
|
+
{
|
|
8184
|
+
hash: "SHA-256",
|
|
8185
|
+
info: bufferSource(info),
|
|
8186
|
+
name: "HKDF",
|
|
8187
|
+
salt: new Uint8Array()
|
|
8188
|
+
},
|
|
8189
|
+
key,
|
|
8190
|
+
256
|
|
8191
|
+
)
|
|
8192
|
+
);
|
|
8193
|
+
}
|
|
8048
8194
|
async function dhkemExtractAndExpand(dh, kemContext) {
|
|
8049
8195
|
const eaePRK = await labeledExtract(
|
|
8050
8196
|
dhkemSuiteID(),
|
|
@@ -8197,6 +8343,33 @@ async function aesGCMDecrypt(key, nonce, ciphertext, aad) {
|
|
|
8197
8343
|
)
|
|
8198
8344
|
);
|
|
8199
8345
|
}
|
|
8346
|
+
async function aesGCMEncryptWithPrefixedRandomNonce(key, plaintext, aad) {
|
|
8347
|
+
const nonce = randomBytes(aesGCMNonceSize);
|
|
8348
|
+
return concat2(nonce, await aesGCMEncrypt(key, nonce, plaintext, aad));
|
|
8349
|
+
}
|
|
8350
|
+
async function aesGCMDecryptWithPrefixedRandomNonce(key, ciphertext, aad) {
|
|
8351
|
+
if (ciphertext.byteLength < aesGCMNonceSize + 16) {
|
|
8352
|
+
throw new Error("E2E random-nonce AES-GCM ciphertext is too short");
|
|
8353
|
+
}
|
|
8354
|
+
return aesGCMDecrypt(
|
|
8355
|
+
key,
|
|
8356
|
+
ciphertext.slice(0, aesGCMNonceSize),
|
|
8357
|
+
ciphertext.slice(aesGCMNonceSize),
|
|
8358
|
+
aad
|
|
8359
|
+
);
|
|
8360
|
+
}
|
|
8361
|
+
async function encryptPayloadForSuite(suite, key, nonce, plaintext, aad) {
|
|
8362
|
+
if (suite === webTTYFIPSCompatiblePayloadSuite) {
|
|
8363
|
+
return aesGCMEncryptWithPrefixedRandomNonce(key, plaintext, aad);
|
|
8364
|
+
}
|
|
8365
|
+
return aesGCMEncrypt(key, nonce, plaintext, aad);
|
|
8366
|
+
}
|
|
8367
|
+
async function decryptPayloadForSuite(suite, key, nonce, ciphertext, aad) {
|
|
8368
|
+
if (suite === webTTYFIPSCompatiblePayloadSuite) {
|
|
8369
|
+
return aesGCMDecryptWithPrefixedRandomNonce(key, ciphertext, aad);
|
|
8370
|
+
}
|
|
8371
|
+
return aesGCMDecrypt(key, nonce, ciphertext, aad);
|
|
8372
|
+
}
|
|
8200
8373
|
async function importX25519PrivateKey(identity) {
|
|
8201
8374
|
return getSubtle().importKey(
|
|
8202
8375
|
"jwk",
|
|
@@ -8213,6 +8386,23 @@ async function importX25519PrivateKey(identity) {
|
|
|
8213
8386
|
["deriveBits"]
|
|
8214
8387
|
);
|
|
8215
8388
|
}
|
|
8389
|
+
async function importP256PrivateKey(identity) {
|
|
8390
|
+
return getSubtle().importKey(
|
|
8391
|
+
"jwk",
|
|
8392
|
+
{
|
|
8393
|
+
crv: "P-256",
|
|
8394
|
+
d: base64URLEncode(identity.privateKey),
|
|
8395
|
+
ext: true,
|
|
8396
|
+
key_ops: ["deriveBits"],
|
|
8397
|
+
kty: "EC",
|
|
8398
|
+
x: base64URLEncode(identity.publicKey.slice(1, 33)),
|
|
8399
|
+
y: base64URLEncode(identity.publicKey.slice(33, 65))
|
|
8400
|
+
},
|
|
8401
|
+
{ name: "ECDH", namedCurve: "P-256" },
|
|
8402
|
+
false,
|
|
8403
|
+
["deriveBits"]
|
|
8404
|
+
);
|
|
8405
|
+
}
|
|
8216
8406
|
function validatePayloadEnvelope(payload, options) {
|
|
8217
8407
|
const crypto = payload.payloadCrypto;
|
|
8218
8408
|
if (crypto === void 0) throw new Error("missing E2E payload crypto");
|
|
@@ -8225,18 +8415,64 @@ function validatePayloadEnvelope(payload, options) {
|
|
|
8225
8415
|
if (!bytesEqual(crypto.aadContext, options.keyContext)) {
|
|
8226
8416
|
throw new Error("unexpected E2E key context");
|
|
8227
8417
|
}
|
|
8228
|
-
|
|
8229
|
-
|
|
8418
|
+
const expectedNonceSize = options.payloadSuite === webTTYFIPSCompatiblePayloadSuite ? 0 : aesGCMNonceSize;
|
|
8419
|
+
if (crypto.nonce === void 0 || crypto.nonce.byteLength !== expectedNonceSize) {
|
|
8420
|
+
throw new Error(`E2E AES-GCM nonce must be ${expectedNonceSize} bytes`);
|
|
8230
8421
|
}
|
|
8231
8422
|
}
|
|
8232
|
-
function
|
|
8233
|
-
if (
|
|
8234
|
-
throw new Error(
|
|
8423
|
+
function inferRecipientSuite(recipients) {
|
|
8424
|
+
if (recipients.length === 0) {
|
|
8425
|
+
throw new Error(
|
|
8426
|
+
"E2E client payload crypto requires at least one recipient"
|
|
8427
|
+
);
|
|
8428
|
+
}
|
|
8429
|
+
const suites = recipients.map(
|
|
8430
|
+
(recipient) => recipient.keyEnvelopeSuite ?? inferKeyEnvelopeSuite(cloneKeyMaterial(recipient.publicKey))
|
|
8431
|
+
);
|
|
8432
|
+
const suite = suites[0];
|
|
8433
|
+
if (suite === void 0 || suites.some((candidate) => candidate !== suite)) {
|
|
8434
|
+
throw new Error("E2E recipients must use the same key envelope suite");
|
|
8435
|
+
}
|
|
8436
|
+
return suite;
|
|
8437
|
+
}
|
|
8438
|
+
function inferKeyEnvelopeSuite(publicKey) {
|
|
8439
|
+
if (publicKey.byteLength === x25519PublicKeySize) {
|
|
8440
|
+
return nominalKeyEnvelopeSuite;
|
|
8441
|
+
}
|
|
8442
|
+
if (publicKey.byteLength === p256PublicKeySize && publicKey[0] === 4) {
|
|
8443
|
+
return webTTYFIPSCompatibleKeyEnvelopeSuite;
|
|
8444
|
+
}
|
|
8445
|
+
throw new Error(
|
|
8446
|
+
`unsupported E2E recipient public key length ${publicKey.byteLength}`
|
|
8447
|
+
);
|
|
8448
|
+
}
|
|
8449
|
+
function payloadSuiteForKeyEnvelopeSuite(suite) {
|
|
8450
|
+
switch (suite) {
|
|
8451
|
+
case nominalKeyEnvelopeSuite:
|
|
8452
|
+
return nominalPayloadSuite;
|
|
8453
|
+
case webTTYFIPSCompatibleKeyEnvelopeSuite:
|
|
8454
|
+
return webTTYFIPSCompatiblePayloadSuite;
|
|
8455
|
+
default:
|
|
8456
|
+
throw new Error(`unsupported E2E key envelope suite ${suite}`);
|
|
8235
8457
|
}
|
|
8236
|
-
|
|
8237
|
-
|
|
8458
|
+
}
|
|
8459
|
+
function publicKeySizeForSuite(suite) {
|
|
8460
|
+
switch (suite) {
|
|
8461
|
+
case nominalKeyEnvelopeSuite:
|
|
8462
|
+
return x25519PublicKeySize;
|
|
8463
|
+
case webTTYFIPSCompatibleKeyEnvelopeSuite:
|
|
8464
|
+
return p256PublicKeySize;
|
|
8465
|
+
default:
|
|
8466
|
+
throw new Error(`unsupported E2E key envelope suite ${suite}`);
|
|
8238
8467
|
}
|
|
8239
|
-
|
|
8468
|
+
}
|
|
8469
|
+
function validateSuites(payloadSuite, keyEnvelopeSuite) {
|
|
8470
|
+
if (payloadSuite === nominalPayloadSuite && keyEnvelopeSuite === nominalKeyEnvelopeSuite || payloadSuite === webTTYFIPSCompatiblePayloadSuite && keyEnvelopeSuite === webTTYFIPSCompatibleKeyEnvelopeSuite) {
|
|
8471
|
+
return { keyEnvelopeSuite, payloadSuite };
|
|
8472
|
+
}
|
|
8473
|
+
throw new Error(
|
|
8474
|
+
`unsupported E2E suite pair ${payloadSuite}/${keyEnvelopeSuite}`
|
|
8475
|
+
);
|
|
8240
8476
|
}
|
|
8241
8477
|
function hpkeInfo(payloadSuite, payloadKeyId, keyContext, suite) {
|
|
8242
8478
|
return concat2(
|
|
@@ -8271,11 +8507,13 @@ function payloadAAD(stream, suite, payloadKeyId, keyContext, nonce, plaintextLen
|
|
|
8271
8507
|
function payloadSuiteCode2(suite) {
|
|
8272
8508
|
if (suite === "aes-256-gcm") return 1;
|
|
8273
8509
|
if (suite === "chacha20-poly1305") return 2;
|
|
8510
|
+
if (suite === "aes-256-gcm-random-nonce") return 3;
|
|
8274
8511
|
return unsupportedPayloadSuite(suite);
|
|
8275
8512
|
}
|
|
8276
8513
|
function keyEnvelopeSuiteCode2(suite) {
|
|
8277
8514
|
if (suite === "hpke-x25519-hkdf-sha256-aes-256-gcm") return 1;
|
|
8278
8515
|
if (suite === "hpke-x25519-hkdf-sha256-chacha20-poly1305") return 2;
|
|
8516
|
+
if (suite === "p256-hkdf-sha256-aes-256-gcm-random-nonce") return 3;
|
|
8279
8517
|
return unsupportedKeyEnvelopeSuite(suite);
|
|
8280
8518
|
}
|
|
8281
8519
|
function unsupportedPayloadSuite(suite) {
|
|
@@ -8351,10 +8589,12 @@ function nonEmptyString(value, label) {
|
|
|
8351
8589
|
return void 0;
|
|
8352
8590
|
}
|
|
8353
8591
|
function normalizeIdentity(identity) {
|
|
8592
|
+
const publicKey = cloneKeyMaterial(identity.publicKey);
|
|
8354
8593
|
return {
|
|
8594
|
+
keyEnvelopeSuite: identity.keyEnvelopeSuite ?? inferKeyEnvelopeSuite(publicKey),
|
|
8355
8595
|
keyId: cloneKeyMaterial(identity.keyId),
|
|
8356
8596
|
privateKey: cloneKeyMaterial(identity.privateKey),
|
|
8357
|
-
publicKey
|
|
8597
|
+
publicKey
|
|
8358
8598
|
};
|
|
8359
8599
|
}
|
|
8360
8600
|
function bufferSource(value) {
|
|
@@ -8408,9 +8648,10 @@ function getSubtle() {
|
|
|
8408
8648
|
}
|
|
8409
8649
|
return subtle;
|
|
8410
8650
|
}
|
|
8411
|
-
function
|
|
8651
|
+
function isCryptoKeyPair(value) {
|
|
8412
8652
|
return "privateKey" in value && "publicKey" in value;
|
|
8413
8653
|
}
|
|
8654
|
+
var isX25519KeyPair = isCryptoKeyPair;
|
|
8414
8655
|
function base64URLEncode(value) {
|
|
8415
8656
|
const binary = String.fromCharCode(...value);
|
|
8416
8657
|
return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
@@ -8475,6 +8716,8 @@ function payloadCipherSuiteToProto(suite) {
|
|
|
8475
8716
|
return rstream.webtty.protobuf.PayloadCipherSuite.PAYLOAD_CIPHER_SUITE_AES_256_GCM;
|
|
8476
8717
|
case "chacha20-poly1305":
|
|
8477
8718
|
return rstream.webtty.protobuf.PayloadCipherSuite.PAYLOAD_CIPHER_SUITE_CHACHA20_POLY1305;
|
|
8719
|
+
case "aes-256-gcm-random-nonce":
|
|
8720
|
+
return rstream.webtty.protobuf.PayloadCipherSuite.PAYLOAD_CIPHER_SUITE_AES_256_GCM_RANDOM_NONCE;
|
|
8478
8721
|
default:
|
|
8479
8722
|
return rstream.webtty.protobuf.PayloadCipherSuite.PAYLOAD_CIPHER_SUITE_UNSPECIFIED;
|
|
8480
8723
|
}
|
|
@@ -8485,6 +8728,8 @@ function payloadCipherSuiteFromProto(suite) {
|
|
|
8485
8728
|
return "aes-256-gcm";
|
|
8486
8729
|
case rstream.webtty.protobuf.PayloadCipherSuite.PAYLOAD_CIPHER_SUITE_CHACHA20_POLY1305:
|
|
8487
8730
|
return "chacha20-poly1305";
|
|
8731
|
+
case rstream.webtty.protobuf.PayloadCipherSuite.PAYLOAD_CIPHER_SUITE_AES_256_GCM_RANDOM_NONCE:
|
|
8732
|
+
return "aes-256-gcm-random-nonce";
|
|
8488
8733
|
default:
|
|
8489
8734
|
return void 0;
|
|
8490
8735
|
}
|
|
@@ -8495,6 +8740,8 @@ function keyEnvelopeSuiteToProto(suite) {
|
|
|
8495
8740
|
return rstream.webtty.protobuf.KeyEnvelopeSuite.KEY_ENVELOPE_SUITE_HPKE_X25519_HKDF_SHA256_AES_256_GCM;
|
|
8496
8741
|
case "hpke-x25519-hkdf-sha256-chacha20-poly1305":
|
|
8497
8742
|
return rstream.webtty.protobuf.KeyEnvelopeSuite.KEY_ENVELOPE_SUITE_HPKE_X25519_HKDF_SHA256_CHACHA20_POLY1305;
|
|
8743
|
+
case "p256-hkdf-sha256-aes-256-gcm-random-nonce":
|
|
8744
|
+
return rstream.webtty.protobuf.KeyEnvelopeSuite.KEY_ENVELOPE_SUITE_P256_HKDF_SHA256_AES_256_GCM_RANDOM_NONCE;
|
|
8498
8745
|
default:
|
|
8499
8746
|
return rstream.webtty.protobuf.KeyEnvelopeSuite.KEY_ENVELOPE_SUITE_UNSPECIFIED;
|
|
8500
8747
|
}
|
|
@@ -8505,10 +8752,72 @@ function keyEnvelopeSuiteFromProto(suite) {
|
|
|
8505
8752
|
return "hpke-x25519-hkdf-sha256-aes-256-gcm";
|
|
8506
8753
|
case rstream.webtty.protobuf.KeyEnvelopeSuite.KEY_ENVELOPE_SUITE_HPKE_X25519_HKDF_SHA256_CHACHA20_POLY1305:
|
|
8507
8754
|
return "hpke-x25519-hkdf-sha256-chacha20-poly1305";
|
|
8755
|
+
case rstream.webtty.protobuf.KeyEnvelopeSuite.KEY_ENVELOPE_SUITE_P256_HKDF_SHA256_AES_256_GCM_RANDOM_NONCE:
|
|
8756
|
+
return "p256-hkdf-sha256-aes-256-gcm-random-nonce";
|
|
8508
8757
|
default:
|
|
8509
8758
|
return void 0;
|
|
8510
8759
|
}
|
|
8511
8760
|
}
|
|
8761
|
+
var defaultE2EPayloadSuite = "aes-256-gcm";
|
|
8762
|
+
var defaultE2EKeyEnvelopeSuite = "hpke-x25519-hkdf-sha256-aes-256-gcm";
|
|
8763
|
+
var fipsCompatibleE2EPayloadSuite = "aes-256-gcm-random-nonce";
|
|
8764
|
+
var fipsCompatibleE2EKeyEnvelopeSuite = "p256-hkdf-sha256-aes-256-gcm-random-nonce";
|
|
8765
|
+
function payloadSuiteForKeyEnvelopeSuite2(suite) {
|
|
8766
|
+
switch (suite) {
|
|
8767
|
+
case defaultE2EKeyEnvelopeSuite:
|
|
8768
|
+
return defaultE2EPayloadSuite;
|
|
8769
|
+
case fipsCompatibleE2EKeyEnvelopeSuite:
|
|
8770
|
+
return fipsCompatibleE2EPayloadSuite;
|
|
8771
|
+
default:
|
|
8772
|
+
throw new Error(`Unsupported WebTTY E2E key envelope suite ${suite}.`);
|
|
8773
|
+
}
|
|
8774
|
+
}
|
|
8775
|
+
function asE2EKeyEnvelopeSuite(suite) {
|
|
8776
|
+
if (suite === defaultE2EKeyEnvelopeSuite || suite === fipsCompatibleE2EKeyEnvelopeSuite) {
|
|
8777
|
+
return suite;
|
|
8778
|
+
}
|
|
8779
|
+
throw new Error(`Unsupported WebTTY E2E key envelope suite ${suite}.`);
|
|
8780
|
+
}
|
|
8781
|
+
function inferE2EKeyEnvelopeSuite(publicKey) {
|
|
8782
|
+
if (publicKey?.byteLength === 32) return defaultE2EKeyEnvelopeSuite;
|
|
8783
|
+
if (publicKey?.byteLength === 65 && publicKey[0] === 4) {
|
|
8784
|
+
return fipsCompatibleE2EKeyEnvelopeSuite;
|
|
8785
|
+
}
|
|
8786
|
+
return void 0;
|
|
8787
|
+
}
|
|
8788
|
+
function proofSuitesFromGrant(grant) {
|
|
8789
|
+
const rawKeyEnvelopeSuite = keyEnvelopeSuiteFromProto(
|
|
8790
|
+
grant?.keyEnvelopeSuite
|
|
8791
|
+
);
|
|
8792
|
+
const payloadSuite = payloadCipherSuiteFromProto(grant?.payloadSuite);
|
|
8793
|
+
if (rawKeyEnvelopeSuite === void 0 && payloadSuite === void 0) {
|
|
8794
|
+
return {
|
|
8795
|
+
keyEnvelopeSuite: defaultE2EKeyEnvelopeSuite,
|
|
8796
|
+
payloadSuite: defaultE2EPayloadSuite
|
|
8797
|
+
};
|
|
8798
|
+
}
|
|
8799
|
+
if (rawKeyEnvelopeSuite === void 0 || payloadSuite === void 0) {
|
|
8800
|
+
throw new Error("WebTTY session key grant uses an unsupported suite pair.");
|
|
8801
|
+
}
|
|
8802
|
+
const keyEnvelopeSuite = asE2EKeyEnvelopeSuite(rawKeyEnvelopeSuite);
|
|
8803
|
+
const expectedPayloadSuite = payloadSuiteForKeyEnvelopeSuite2(keyEnvelopeSuite);
|
|
8804
|
+
if (expectedPayloadSuite !== payloadSuite) {
|
|
8805
|
+
throw new Error("WebTTY session key grant uses an unsupported suite pair.");
|
|
8806
|
+
}
|
|
8807
|
+
return { keyEnvelopeSuite, payloadSuite: expectedPayloadSuite };
|
|
8808
|
+
}
|
|
8809
|
+
function proofSuitesFromClientConfig(config) {
|
|
8810
|
+
const configured = config.endpointIdentity?.keyEnvelopeSuite;
|
|
8811
|
+
const expected = config.expectedServerIdentity;
|
|
8812
|
+
const expectedSuite = expected?.keyEnvelopeSuite ?? inferE2EKeyEnvelopeSuite(expected?.encryptionPublicKey);
|
|
8813
|
+
const keyEnvelopeSuite = asE2EKeyEnvelopeSuite(
|
|
8814
|
+
configured ?? expectedSuite ?? defaultE2EKeyEnvelopeSuite
|
|
8815
|
+
);
|
|
8816
|
+
return {
|
|
8817
|
+
keyEnvelopeSuite,
|
|
8818
|
+
payloadSuite: payloadSuiteForKeyEnvelopeSuite2(keyEnvelopeSuite)
|
|
8819
|
+
};
|
|
8820
|
+
}
|
|
8512
8821
|
function signatureSuiteFromProto(suite) {
|
|
8513
8822
|
switch (suite) {
|
|
8514
8823
|
case rstream.webtty.protobuf.SignatureSuite.SIGNATURE_SUITE_ECDSA_P256_SHA256:
|
|
@@ -9189,6 +9498,16 @@ var WebTTY = class {
|
|
|
9189
9498
|
if (!bytesEqual2(actual.signingKeyId, expected.signingKeyId) || !bytesEqual2(actual.signingPublicKey, expected.signingPublicKey) || !bytesEqual2(actual.encryptionKeyId, expected.encryptionKeyId) || !bytesEqual2(actual.encryptionPublicKey, expected.encryptionPublicKey)) {
|
|
9190
9499
|
return false;
|
|
9191
9500
|
}
|
|
9501
|
+
const expectedKeyEnvelopeSuite = expected.keyEnvelopeSuite ?? inferE2EKeyEnvelopeSuite(expected.encryptionPublicKey) ?? defaultE2EKeyEnvelopeSuite;
|
|
9502
|
+
const advertisedKeyEnvelopeSuites = (serverHello.keyEnvelopeSuites ?? []).map(keyEnvelopeSuiteFromProto).filter((value) => value !== void 0);
|
|
9503
|
+
const advertisedPayloadSuites = (serverHello.payloadSuites ?? []).map(payloadCipherSuiteFromProto).filter(
|
|
9504
|
+
(value) => value !== void 0
|
|
9505
|
+
);
|
|
9506
|
+
if (!advertisedKeyEnvelopeSuites.includes(expectedKeyEnvelopeSuite) || !advertisedPayloadSuites.includes(
|
|
9507
|
+
payloadSuiteForKeyEnvelopeSuite2(expectedKeyEnvelopeSuite)
|
|
9508
|
+
)) {
|
|
9509
|
+
return false;
|
|
9510
|
+
}
|
|
9192
9511
|
const transcript = {
|
|
9193
9512
|
authRequirement: authRequirementFromProto(serverHello.authRequirement),
|
|
9194
9513
|
keyEnvelopeSuites: (serverHello.keyEnvelopeSuites ?? []).map(keyEnvelopeSuiteFromProto).filter(
|
|
@@ -9243,6 +9562,7 @@ var WebTTY = class {
|
|
|
9243
9562
|
}
|
|
9244
9563
|
const clientPrincipalId = trimOptional(this.clientConfig.clientPrincipalId);
|
|
9245
9564
|
const clientCredential = this.clientConfig.clientCredential;
|
|
9565
|
+
const proofSuites = proofSuitesFromGrant(open.sessionKeyGrant);
|
|
9246
9566
|
const transcript = {
|
|
9247
9567
|
authRequirement: "client-proof",
|
|
9248
9568
|
clientCredentialHash: await hashWebTTYClientCredential(clientCredential),
|
|
@@ -9251,8 +9571,8 @@ var WebTTY = class {
|
|
|
9251
9571
|
commandConfigHash,
|
|
9252
9572
|
expiresAt: expiresAt.toISOString().replace(".000Z", "Z"),
|
|
9253
9573
|
issuedAt: issuedAt.toISOString().replace(".000Z", "Z"),
|
|
9254
|
-
keyEnvelopeSuite:
|
|
9255
|
-
payloadSuite:
|
|
9574
|
+
keyEnvelopeSuite: proofSuites.keyEnvelopeSuite,
|
|
9575
|
+
payloadSuite: proofSuites.payloadSuite,
|
|
9256
9576
|
projectId: optionalString(serverHello.projectId),
|
|
9257
9577
|
protocolVersion: "webtty-1",
|
|
9258
9578
|
serverEncryptionKeyId: optionalBytes(serverIdentity.encryptionKeyId),
|
|
@@ -9301,6 +9621,7 @@ var WebTTY = class {
|
|
|
9301
9621
|
issuedAt.setMilliseconds(0);
|
|
9302
9622
|
const expiresAt = new Date(issuedAt.getTime() + 3e4);
|
|
9303
9623
|
const clientPrincipalId = trimOptional(this.clientConfig.clientPrincipalId);
|
|
9624
|
+
const proofSuites = proofSuitesFromClientConfig(this.clientConfig);
|
|
9304
9625
|
const transcript = {
|
|
9305
9626
|
attachGrantHash: await hashWebTTYAttachGrant(attach.attachGrant),
|
|
9306
9627
|
authRequirement: "client-proof",
|
|
@@ -9309,8 +9630,8 @@ var WebTTY = class {
|
|
|
9309
9630
|
clientSigningKeyId: signing.keyId,
|
|
9310
9631
|
expiresAt: expiresAt.toISOString().replace(".000Z", "Z"),
|
|
9311
9632
|
issuedAt: issuedAt.toISOString().replace(".000Z", "Z"),
|
|
9312
|
-
keyEnvelopeSuite:
|
|
9313
|
-
payloadSuite:
|
|
9633
|
+
keyEnvelopeSuite: proofSuites.keyEnvelopeSuite,
|
|
9634
|
+
payloadSuite: proofSuites.payloadSuite,
|
|
9314
9635
|
projectId: attachConfig.projectId,
|
|
9315
9636
|
protocolVersion: "webtty-1",
|
|
9316
9637
|
requestedRole: attachRoleTranscriptValue(attach.requestedRole),
|
|
@@ -10947,7 +11268,9 @@ function numberValue(value) {
|
|
|
10947
11268
|
// src/local-e2e.ts
|
|
10948
11269
|
var localKeyFileVersion = 1;
|
|
10949
11270
|
var localKeyFileCryptoSuite = "webtty-e2e-x25519-hpke-aes-256-gcm-v1";
|
|
11271
|
+
var localKeyFileFIPSCompatibleCryptoSuite = "webtty-e2e-p256-hkdf-sha256-aes-256-gcm-random-nonce-v1";
|
|
10950
11272
|
var x25519PublicKeySize2 = 32;
|
|
11273
|
+
var p256PublicKeySize2 = 65;
|
|
10951
11274
|
var payloadKeyIDSize2 = 16;
|
|
10952
11275
|
var knownServerKeyEnv = "RSTREAM_WEBTTY_KNOWN_SERVER_KEY";
|
|
10953
11276
|
var knownServersFileEnv = "RSTREAM_WEBTTY_KNOWN_SERVERS_FILE";
|
|
@@ -10975,9 +11298,8 @@ async function parseWebTTYKnownServerKey(value) {
|
|
|
10975
11298
|
validateSigningKeyMaterial(parts[2] ?? "", parts[3] ?? "");
|
|
10976
11299
|
}
|
|
10977
11300
|
if (parts.length === 1) {
|
|
10978
|
-
const publicKey2 =
|
|
11301
|
+
const publicKey2 = decodeEncryptionPublicKey(
|
|
10979
11302
|
parts[0] ?? "",
|
|
10980
|
-
x25519PublicKeySize2,
|
|
10981
11303
|
"known WebTTY server public key"
|
|
10982
11304
|
);
|
|
10983
11305
|
return { keyId: await webTTYE2EKeyID(publicKey2), publicKey: publicKey2 };
|
|
@@ -10987,9 +11309,8 @@ async function parseWebTTYKnownServerKey(value) {
|
|
|
10987
11309
|
payloadKeyIDSize2,
|
|
10988
11310
|
"known WebTTY server key id"
|
|
10989
11311
|
);
|
|
10990
|
-
const publicKey =
|
|
11312
|
+
const publicKey = decodeEncryptionPublicKey(
|
|
10991
11313
|
parts[1] ?? "",
|
|
10992
|
-
x25519PublicKeySize2,
|
|
10993
11314
|
"known WebTTY server public key"
|
|
10994
11315
|
);
|
|
10995
11316
|
const expectedKeyId = await webTTYE2EKeyID(publicKey);
|
|
@@ -11084,7 +11405,7 @@ function decodeWebTTYKnownServerKeysFile(data, filePath) {
|
|
|
11084
11405
|
);
|
|
11085
11406
|
}
|
|
11086
11407
|
const cryptoSuite = parsed.crypto_suite;
|
|
11087
|
-
if (cryptoSuite !== localKeyFileCryptoSuite) {
|
|
11408
|
+
if (cryptoSuite !== localKeyFileCryptoSuite && cryptoSuite !== localKeyFileFIPSCompatibleCryptoSuite) {
|
|
11088
11409
|
throw new Error(
|
|
11089
11410
|
`unsupported known WebTTY server keys crypto suite ${String(cryptoSuite)}`
|
|
11090
11411
|
);
|
|
@@ -11194,6 +11515,16 @@ function decodeFixedKeyMaterial(value, size, label) {
|
|
|
11194
11515
|
}
|
|
11195
11516
|
return decoded;
|
|
11196
11517
|
}
|
|
11518
|
+
function decodeEncryptionPublicKey(value, label) {
|
|
11519
|
+
const decoded = decodeWebTTYE2EKeyMaterial(value.trim());
|
|
11520
|
+
if (decoded.byteLength === x25519PublicKeySize2) return decoded;
|
|
11521
|
+
if (decoded.byteLength === p256PublicKeySize2 && decoded[0] === 4) {
|
|
11522
|
+
return decoded;
|
|
11523
|
+
}
|
|
11524
|
+
throw new Error(
|
|
11525
|
+
`${label} must decode to a ${x25519PublicKeySize2}-byte X25519 key or an uncompressed ${p256PublicKeySize2}-byte P-256 point`
|
|
11526
|
+
);
|
|
11527
|
+
}
|
|
11197
11528
|
function validateSigningKeyMaterial(keyID, publicKey) {
|
|
11198
11529
|
decodeFixedKeyMaterial(keyID, 32, "known WebTTY server signing key id");
|
|
11199
11530
|
decodeWebTTYE2EKeyMaterial(publicKey.trim());
|
|
@@ -11352,6 +11683,8 @@ function errorMessage(error) {
|
|
|
11352
11683
|
verifyWebTTYServerProofTranscript,
|
|
11353
11684
|
webTTYClientProofTranscriptBytes,
|
|
11354
11685
|
webTTYE2EKeyID,
|
|
11686
|
+
webTTYFIPSCompatibleKeyEnvelopeSuite,
|
|
11687
|
+
webTTYFIPSCompatiblePayloadSuite,
|
|
11355
11688
|
webTTYRecordedEventEncryptedPayload,
|
|
11356
11689
|
webTTYServerProofTranscriptBytes,
|
|
11357
11690
|
webTTYSigningKeyID
|