@libp2p/noise 1.0.0-049bfa0fa
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 +95 -0
- package/dist/index.min.js +23 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/constants.d.ts +5 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +5 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/crypto/index.browser.d.ts +2 -0
- package/dist/src/crypto/index.browser.d.ts.map +1 -0
- package/dist/src/crypto/index.browser.js +3 -0
- package/dist/src/crypto/index.browser.js.map +1 -0
- package/dist/src/crypto/index.d.ts +3 -0
- package/dist/src/crypto/index.d.ts.map +1 -0
- package/dist/src/crypto/index.js +188 -0
- package/dist/src/crypto/index.js.map +1 -0
- package/dist/src/crypto/js.d.ts +3 -0
- package/dist/src/crypto/js.d.ts.map +1 -0
- package/dist/src/crypto/js.js +43 -0
- package/dist/src/crypto/js.js.map +1 -0
- package/dist/src/crypto.d.ts +14 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/crypto.js +11 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/encoder.d.ts +10 -0
- package/dist/src/encoder.d.ts.map +1 -0
- package/dist/src/encoder.js +22 -0
- package/dist/src/encoder.js.map +1 -0
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +9 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +52 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +43 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logger.d.ts +10 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +56 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/metrics.d.ts +4 -0
- package/dist/src/metrics.d.ts.map +1 -0
- package/dist/src/metrics.js +20 -0
- package/dist/src/metrics.js.map +1 -0
- package/dist/src/noise.d.ts +58 -0
- package/dist/src/noise.d.ts.map +1 -0
- package/dist/src/noise.js +174 -0
- package/dist/src/noise.js.map +1 -0
- package/dist/src/nonce.d.ts +17 -0
- package/dist/src/nonce.d.ts.map +1 -0
- package/dist/src/nonce.js +42 -0
- package/dist/src/nonce.js.map +1 -0
- package/dist/src/performHandshake.d.ts +5 -0
- package/dist/src/performHandshake.d.ts.map +1 -0
- package/dist/src/performHandshake.js +69 -0
- package/dist/src/performHandshake.js.map +1 -0
- package/dist/src/proto/payload.d.ts +22 -0
- package/dist/src/proto/payload.d.ts.map +1 -0
- package/dist/src/proto/payload.js +133 -0
- package/dist/src/proto/payload.js.map +1 -0
- package/dist/src/protocol.d.ts +71 -0
- package/dist/src/protocol.d.ts.map +1 -0
- package/dist/src/protocol.js +257 -0
- package/dist/src/protocol.js.map +1 -0
- package/dist/src/types.d.ts +98 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +11 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +176 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +94 -0
- package/src/constants.ts +5 -0
- package/src/crypto/index.browser.ts +3 -0
- package/src/crypto/index.ts +219 -0
- package/src/crypto/js.ts +56 -0
- package/src/crypto.ts +27 -0
- package/src/encoder.ts +24 -0
- package/src/errors.ts +10 -0
- package/src/index.ts +58 -0
- package/src/logger.ts +65 -0
- package/src/metrics.ts +32 -0
- package/src/noise.ts +237 -0
- package/src/nonce.ts +49 -0
- package/src/performHandshake.ts +91 -0
- package/src/proto/payload.proto +12 -0
- package/src/proto/payload.ts +170 -0
- package/src/protocol.ts +313 -0
- package/src/types.ts +105 -0
- package/src/utils.ts +221 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA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a,gBAAiB,SAAQ,sBAAsB;IAE1D,aAAa,CAAE,OAAO,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,GAAG,cAAc;IAKjF,aAAa,CAAE,OAAO,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,GAAG,cAAc;IAUjF,aAAa,CAAE,OAAO,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,GAAG,cAAc;IAQjF,YAAY,CAAE,OAAO,EAAE,cAAc,GAAG,UAAU,GAAG,cAAc;IAWnE,YAAY,CAAE,OAAO,EAAE,cAAc,GAAG,UAAU,GAAG,cAAc;IAcnE,YAAY,CAAE,OAAO,EAAE,cAAc,GAAG,UAAU,GAAG,cAAc;CAUpE"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
2
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays';
|
|
3
|
+
import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc';
|
|
4
|
+
import { InvalidCryptoExchangeError } from './errors.js';
|
|
5
|
+
import { Nonce } from './nonce.js';
|
|
6
|
+
// Code in this file is a direct translation of a subset of the noise protocol https://noiseprotocol.org/noise.html,
|
|
7
|
+
// agnostic to libp2p's usage of noise
|
|
8
|
+
export const ZEROLEN = uint8ArrayAlloc(0);
|
|
9
|
+
export class CipherState {
|
|
10
|
+
k;
|
|
11
|
+
n;
|
|
12
|
+
crypto;
|
|
13
|
+
constructor(crypto, k = undefined, n = 0) {
|
|
14
|
+
this.crypto = crypto;
|
|
15
|
+
this.k = k;
|
|
16
|
+
this.n = new Nonce(n);
|
|
17
|
+
}
|
|
18
|
+
hasKey() {
|
|
19
|
+
return Boolean(this.k);
|
|
20
|
+
}
|
|
21
|
+
encryptWithAd(ad, plaintext) {
|
|
22
|
+
if (!this.hasKey()) {
|
|
23
|
+
return plaintext;
|
|
24
|
+
}
|
|
25
|
+
this.n.assertValue();
|
|
26
|
+
const e = this.crypto.encrypt(plaintext, this.n.getBytes(), ad, this.k);
|
|
27
|
+
this.n.increment();
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
decryptWithAd(ad, ciphertext, dst) {
|
|
31
|
+
if (!this.hasKey()) {
|
|
32
|
+
return ciphertext;
|
|
33
|
+
}
|
|
34
|
+
this.n.assertValue();
|
|
35
|
+
const plaintext = this.crypto.decrypt(ciphertext, this.n.getBytes(), ad, this.k, dst);
|
|
36
|
+
this.n.increment();
|
|
37
|
+
return plaintext;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class SymmetricState {
|
|
41
|
+
cs;
|
|
42
|
+
ck;
|
|
43
|
+
h;
|
|
44
|
+
crypto;
|
|
45
|
+
constructor(crypto, protocolName) {
|
|
46
|
+
this.crypto = crypto;
|
|
47
|
+
const protocolNameBytes = uint8ArrayFromString(protocolName, 'utf-8');
|
|
48
|
+
this.h = hashProtocolName(crypto, protocolNameBytes);
|
|
49
|
+
this.ck = this.h;
|
|
50
|
+
this.cs = new CipherState(crypto);
|
|
51
|
+
}
|
|
52
|
+
mixKey(ikm) {
|
|
53
|
+
const [ck, tempK] = this.crypto.hkdf(this.ck, ikm);
|
|
54
|
+
this.ck = ck;
|
|
55
|
+
this.cs = new CipherState(this.crypto, tempK);
|
|
56
|
+
}
|
|
57
|
+
mixHash(data) {
|
|
58
|
+
this.h = this.crypto.hash(new Uint8ArrayList(this.h, data));
|
|
59
|
+
}
|
|
60
|
+
encryptAndHash(plaintext) {
|
|
61
|
+
const ciphertext = this.cs.encryptWithAd(this.h, plaintext);
|
|
62
|
+
this.mixHash(ciphertext);
|
|
63
|
+
return ciphertext;
|
|
64
|
+
}
|
|
65
|
+
decryptAndHash(ciphertext) {
|
|
66
|
+
const plaintext = this.cs.decryptWithAd(this.h, ciphertext);
|
|
67
|
+
this.mixHash(ciphertext);
|
|
68
|
+
return plaintext;
|
|
69
|
+
}
|
|
70
|
+
split() {
|
|
71
|
+
const [tempK1, tempK2] = this.crypto.hkdf(this.ck, ZEROLEN);
|
|
72
|
+
return [new CipherState(this.crypto, tempK1), new CipherState(this.crypto, tempK2)];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export class AbstractHandshakeState {
|
|
76
|
+
ss;
|
|
77
|
+
s;
|
|
78
|
+
e;
|
|
79
|
+
rs;
|
|
80
|
+
re;
|
|
81
|
+
initiator;
|
|
82
|
+
crypto;
|
|
83
|
+
constructor(init) {
|
|
84
|
+
const { crypto, protocolName, prologue, initiator, s, e, rs, re } = init;
|
|
85
|
+
this.crypto = crypto;
|
|
86
|
+
this.ss = new SymmetricState(crypto, protocolName);
|
|
87
|
+
this.ss.mixHash(prologue);
|
|
88
|
+
this.initiator = initiator;
|
|
89
|
+
this.s = s;
|
|
90
|
+
this.e = e;
|
|
91
|
+
this.rs = rs;
|
|
92
|
+
this.re = re;
|
|
93
|
+
}
|
|
94
|
+
writeE() {
|
|
95
|
+
if (this.e) {
|
|
96
|
+
throw new Error('ephemeral keypair is already set');
|
|
97
|
+
}
|
|
98
|
+
const e = this.crypto.generateKeypair();
|
|
99
|
+
this.ss.mixHash(e.publicKey);
|
|
100
|
+
this.e = e;
|
|
101
|
+
return e.publicKey;
|
|
102
|
+
}
|
|
103
|
+
writeS() {
|
|
104
|
+
if (!this.s) {
|
|
105
|
+
throw new Error('static keypair is not set');
|
|
106
|
+
}
|
|
107
|
+
return this.ss.encryptAndHash(this.s.publicKey);
|
|
108
|
+
}
|
|
109
|
+
writeEE() {
|
|
110
|
+
if (!this.e) {
|
|
111
|
+
throw new Error('ephemeral keypair is not set');
|
|
112
|
+
}
|
|
113
|
+
if (!this.re) {
|
|
114
|
+
throw new Error('remote ephemeral public key is not set');
|
|
115
|
+
}
|
|
116
|
+
this.ss.mixKey(this.crypto.dh(this.e, this.re));
|
|
117
|
+
}
|
|
118
|
+
writeES() {
|
|
119
|
+
if (this.initiator) {
|
|
120
|
+
if (!this.e) {
|
|
121
|
+
throw new Error('ephemeral keypair is not set');
|
|
122
|
+
}
|
|
123
|
+
if (!this.rs) {
|
|
124
|
+
throw new Error('remote static public key is not set');
|
|
125
|
+
}
|
|
126
|
+
this.ss.mixKey(this.crypto.dh(this.e, this.rs));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
if (!this.s) {
|
|
130
|
+
throw new Error('static keypair is not set');
|
|
131
|
+
}
|
|
132
|
+
if (!this.re) {
|
|
133
|
+
throw new Error('remote ephemeral public key is not set');
|
|
134
|
+
}
|
|
135
|
+
this.ss.mixKey(this.crypto.dh(this.s, this.re));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
writeSE() {
|
|
139
|
+
if (this.initiator) {
|
|
140
|
+
if (!this.s) {
|
|
141
|
+
throw new Error('static keypair is not set');
|
|
142
|
+
}
|
|
143
|
+
if (!this.re) {
|
|
144
|
+
throw new Error('remote ephemeral public key is not set');
|
|
145
|
+
}
|
|
146
|
+
this.ss.mixKey(this.crypto.dh(this.s, this.re));
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
if (!this.e) {
|
|
150
|
+
throw new Error('ephemeral keypair is not set');
|
|
151
|
+
}
|
|
152
|
+
if (!this.rs) {
|
|
153
|
+
throw new Error('remote static public key is not set');
|
|
154
|
+
}
|
|
155
|
+
this.ss.mixKey(this.crypto.dh(this.e, this.rs));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
readE(message, offset = 0) {
|
|
159
|
+
if (this.re) {
|
|
160
|
+
throw new Error('remote ephemeral public key is already set');
|
|
161
|
+
}
|
|
162
|
+
if (message.byteLength < offset + 32) {
|
|
163
|
+
throw new Error('message is not long enough');
|
|
164
|
+
}
|
|
165
|
+
this.re = message.sublist(offset, offset + 32);
|
|
166
|
+
this.ss.mixHash(this.re);
|
|
167
|
+
}
|
|
168
|
+
readS(message, offset = 0) {
|
|
169
|
+
if (this.rs) {
|
|
170
|
+
throw new Error('remote static public key is already set');
|
|
171
|
+
}
|
|
172
|
+
const cipherLength = 32 + (this.ss.cs.hasKey() ? 16 : 0);
|
|
173
|
+
if (message.byteLength < offset + cipherLength) {
|
|
174
|
+
throw new Error('message is not long enough');
|
|
175
|
+
}
|
|
176
|
+
const temp = message.sublist(offset, offset + cipherLength);
|
|
177
|
+
this.rs = this.ss.decryptAndHash(temp);
|
|
178
|
+
return cipherLength;
|
|
179
|
+
}
|
|
180
|
+
readEE() {
|
|
181
|
+
this.writeEE();
|
|
182
|
+
}
|
|
183
|
+
readES() {
|
|
184
|
+
this.writeES();
|
|
185
|
+
}
|
|
186
|
+
readSE() {
|
|
187
|
+
this.writeSE();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* A IHandshakeState that's optimized for the XX pattern
|
|
192
|
+
*/
|
|
193
|
+
export class XXHandshakeState extends AbstractHandshakeState {
|
|
194
|
+
// e
|
|
195
|
+
writeMessageA(payload) {
|
|
196
|
+
return new Uint8ArrayList(this.writeE(), this.ss.encryptAndHash(payload));
|
|
197
|
+
}
|
|
198
|
+
// e, ee, s, es
|
|
199
|
+
writeMessageB(payload) {
|
|
200
|
+
const e = this.writeE();
|
|
201
|
+
this.writeEE();
|
|
202
|
+
const encS = this.writeS();
|
|
203
|
+
this.writeES();
|
|
204
|
+
return new Uint8ArrayList(e, encS, this.ss.encryptAndHash(payload));
|
|
205
|
+
}
|
|
206
|
+
// s, se
|
|
207
|
+
writeMessageC(payload) {
|
|
208
|
+
const encS = this.writeS();
|
|
209
|
+
this.writeSE();
|
|
210
|
+
return new Uint8ArrayList(encS, this.ss.encryptAndHash(payload));
|
|
211
|
+
}
|
|
212
|
+
// e
|
|
213
|
+
readMessageA(message) {
|
|
214
|
+
try {
|
|
215
|
+
this.readE(message);
|
|
216
|
+
return this.ss.decryptAndHash(message.sublist(32));
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
throw new InvalidCryptoExchangeError(`handshake stage 0 validation fail: ${e.message}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// e, ee, s, es
|
|
223
|
+
readMessageB(message) {
|
|
224
|
+
try {
|
|
225
|
+
this.readE(message);
|
|
226
|
+
this.readEE();
|
|
227
|
+
const consumed = this.readS(message, 32);
|
|
228
|
+
this.readES();
|
|
229
|
+
return this.ss.decryptAndHash(message.sublist(32 + consumed));
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
throw new InvalidCryptoExchangeError(`handshake stage 1 validation fail: ${e.message}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// s, se
|
|
236
|
+
readMessageC(message) {
|
|
237
|
+
try {
|
|
238
|
+
const consumed = this.readS(message);
|
|
239
|
+
this.readSE();
|
|
240
|
+
return this.ss.decryptAndHash(message.sublist(consumed));
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
throw new InvalidCryptoExchangeError(`handshake stage 2 validation fail: ${e.message}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function hashProtocolName(crypto, protocolName) {
|
|
248
|
+
if (protocolName.length <= 32) {
|
|
249
|
+
const h = uint8ArrayAlloc(32);
|
|
250
|
+
h.set(protocolName);
|
|
251
|
+
return h;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return crypto.hash(protocolName);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA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C;QACN,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Nonce } from './nonce.js';
|
|
2
|
+
import type { NoiseExtensions, NoiseHandshakePayload } from './proto/payload.js';
|
|
3
|
+
import type { ConnectionEncrypter, Logger, PrivateKey, PublicKey } from '@libp2p/interface';
|
|
4
|
+
import type { LengthPrefixedStream } from '@libp2p/utils';
|
|
5
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
6
|
+
/**
|
|
7
|
+
* Crypto functions defined by the noise protocol, abstracted from the
|
|
8
|
+
* underlying implementations
|
|
9
|
+
*/
|
|
10
|
+
export interface ICrypto {
|
|
11
|
+
generateKeypair(): KeyPair;
|
|
12
|
+
dh(keypair: KeyPair, publicKey: Uint8Array | Uint8ArrayList): Uint8Array;
|
|
13
|
+
encrypt(plaintext: Uint8Array | Uint8ArrayList, nonce: Uint8Array, ad: Uint8Array, k: Uint8Array): Uint8ArrayList | Uint8Array;
|
|
14
|
+
decrypt(ciphertext: Uint8Array | Uint8ArrayList, nonce: Uint8Array, ad: Uint8Array, k: Uint8Array, dst?: Uint8Array): Uint8ArrayList | Uint8Array;
|
|
15
|
+
hash(data: Uint8Array | Uint8ArrayList): Uint8Array;
|
|
16
|
+
hkdf(ck: Uint8Array, ikm: Uint8Array): [Uint8Array, Uint8Array, Uint8Array];
|
|
17
|
+
}
|
|
18
|
+
export interface HandshakeParams {
|
|
19
|
+
log: Logger;
|
|
20
|
+
connection: LengthPrefixedStream;
|
|
21
|
+
crypto: ICrypto;
|
|
22
|
+
privateKey: PrivateKey;
|
|
23
|
+
prologue: Uint8Array;
|
|
24
|
+
/** static keypair */
|
|
25
|
+
s: KeyPair;
|
|
26
|
+
remoteIdentityKey?: PublicKey;
|
|
27
|
+
extensions?: NoiseExtensions;
|
|
28
|
+
}
|
|
29
|
+
export interface HandshakeResult {
|
|
30
|
+
payload: NoiseHandshakePayload;
|
|
31
|
+
encrypt(plaintext: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
32
|
+
decrypt(ciphertext: Uint8Array | Uint8ArrayList, dst?: Uint8Array): Uint8Array | Uint8ArrayList;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A CipherState object contains k and n variables, which it uses to encrypt and
|
|
36
|
+
* decrypt ciphertext.
|
|
37
|
+
*
|
|
38
|
+
* During the handshake phase each party has a single CipherState, but during
|
|
39
|
+
* the transport phase each party has two CipherState objects: one for sending,
|
|
40
|
+
* and one for receiving.
|
|
41
|
+
*/
|
|
42
|
+
export interface ICipherState {
|
|
43
|
+
/**
|
|
44
|
+
* A cipher key of 32 bytes (which may be empty). Empty is a special value
|
|
45
|
+
* which indicates k has not yet been initialized.
|
|
46
|
+
*/
|
|
47
|
+
k?: Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* An 8-byte (64-bit) unsigned integer nonce.
|
|
50
|
+
*
|
|
51
|
+
* For performance reasons, the nonce is represented as a Nonce object
|
|
52
|
+
* The nonce is treated as a uint64, even though the underlying `number` only
|
|
53
|
+
* has 52 safely-available bits.
|
|
54
|
+
*/
|
|
55
|
+
n: Nonce;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A SymmetricState object contains a CipherState plus ck and h variables. It is
|
|
59
|
+
* so-named because it encapsulates all the "symmetric crypto" used by Noise.
|
|
60
|
+
*
|
|
61
|
+
* During the handshake phase each party has a single SymmetricState, which can
|
|
62
|
+
* be deleted once the handshake is finished.
|
|
63
|
+
*/
|
|
64
|
+
export interface ISymmetricState {
|
|
65
|
+
cs: ICipherState;
|
|
66
|
+
/** A chaining key of 32 bytes. */
|
|
67
|
+
ck: Uint8Array;
|
|
68
|
+
/** A hash output of 32 bytes. */
|
|
69
|
+
h: Uint8Array;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A HandshakeState object contains a SymmetricState plus DH variables (s, e,
|
|
73
|
+
* rs, re) and a variable representing the handshake pattern.
|
|
74
|
+
*
|
|
75
|
+
* During the handshake phase each party has a single HandshakeState, which can
|
|
76
|
+
* be deleted once the handshake is finished.
|
|
77
|
+
*/
|
|
78
|
+
export interface IHandshakeState {
|
|
79
|
+
ss: ISymmetricState;
|
|
80
|
+
/** The local static key pair */
|
|
81
|
+
s?: KeyPair;
|
|
82
|
+
/** The local ephemeral key pair */
|
|
83
|
+
e?: KeyPair;
|
|
84
|
+
/** The remote party's static public key */
|
|
85
|
+
rs?: Uint8Array | Uint8ArrayList;
|
|
86
|
+
/** The remote party's ephemeral public key */
|
|
87
|
+
re?: Uint8Array | Uint8ArrayList;
|
|
88
|
+
}
|
|
89
|
+
export interface KeyPair {
|
|
90
|
+
publicKey: Uint8Array;
|
|
91
|
+
privateKey: Uint8Array;
|
|
92
|
+
}
|
|
93
|
+
export interface INoiseExtensions {
|
|
94
|
+
webtransportCerthashes: Uint8Array[];
|
|
95
|
+
}
|
|
96
|
+
export interface INoiseConnection extends ConnectionEncrypter<INoiseExtensions> {
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,eAAe,IAAI,OAAO,CAAA;IAC1B,EAAE,CAAC,OA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AA;IACd;;;;;;OAMG;IACH,CAAC,EAAE,KAAK,CAAA;CACT;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,YAAY,CAAA;IAChB,kCAAkC;IAClC,EAAE,EAAE,UAAU,CAAA;IACd,iCAAiC;IACjC,CAAC,EAAE,UAAU,CAAA;CACd;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,eAAe,CAAA;IACnB,gCAAgC;IAChC,CAAC,CAAC,EAAE,OAAO,CAAA;IACX,mCAAmC;IACnC,CAAC,CAAC,EAAE,OAAO,CAAA;IACX,2CAA2C;IAC3C,EAAE,CAAC,EAAE,UAAU,GAAG,cAAc,CAAA;IAChC,8CAA8C;IAC9C,EAAE,CAAC,EAAE,UAAU,GAAG,cAAc,CAAA;CACjC;AAED,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,UAAU,CAAA;IACrB,UAAU,EAAE,UAAU,CAAA;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,sBAAsB,EAAE,UAAU,EAAE,CAAA;CACrC;AAED,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB,CAAC,gBAAgB,CAAC;CAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
2
|
+
import { NoiseHandshakePayload } from './proto/payload.js';
|
|
3
|
+
import type { MetricsRegistry } from './metrics.ts';
|
|
4
|
+
import type { NoiseExtensions } from './proto/payload.js';
|
|
5
|
+
import type { HandshakeResult } from './types.ts';
|
|
6
|
+
import type { MessageStream, PrivateKey, PublicKey } from '@libp2p/interface';
|
|
7
|
+
export declare function createHandshakePayload(privateKey: PrivateKey, staticPublicKey: Uint8Array | Uint8ArrayList, extensions?: NoiseExtensions): Promise<Uint8Array | Uint8ArrayList>;
|
|
8
|
+
export declare function decodeHandshakePayload(payloadBytes: Uint8Array | Uint8ArrayList, remoteStaticKey?: Uint8Array | Uint8ArrayList, remoteIdentityKey?: PublicKey): Promise<NoiseHandshakePayload>;
|
|
9
|
+
export declare function getSignaturePayload(publicKey: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
10
|
+
export declare function toMessageStream(connection: MessageStream, handshake: HandshakeResult, metrics?: MetricsRegistry): MessageStream;
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAK/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAgB,aAAa,EAAE,UAAU,EAAE,SAAS,EAAoB,MAAM,mBAAmB,CAAA;AAG7G,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,UAAU,GAAG,cAAc,EAC5C,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,UAAU,GAAG,cAAc,CAAC,CAQtC;AAED,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,UAAU,GAAG,cAAc,EACzC,eAAe,CAAC,EAAE,UAAU,GAAG,cAAc,EAC7C,iBAAiB,CAAC,EAAE,SAAS,GAC5B,OAAO,CAAC,qBAAqB,CAAC,CAuBhC;AAED,wBAAgB,mBAAmB,CAAE,SAAS,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,GAAG,cAAc,CAUxG;AAsJD,wBAAgB,eAAe,CAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,aAAa,CAEhI"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys';
|
|
2
|
+
import { StreamMessageEvent, UnexpectedPeerError } from '@libp2p/interface';
|
|
3
|
+
import { AbstractMessageStream, LengthPrefixedDecoder } from '@libp2p/utils';
|
|
4
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
5
|
+
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
6
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
7
|
+
import { CHACHA_TAG_LENGTH, NOISE_MSG_MAX_LENGTH_BYTES, NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG } from "./constants.js";
|
|
8
|
+
import { uint16BEEncode, uint16BEDecode } from "./encoder.js";
|
|
9
|
+
import { NoiseHandshakePayload } from './proto/payload.js';
|
|
10
|
+
export async function createHandshakePayload(privateKey, staticPublicKey, extensions) {
|
|
11
|
+
const identitySig = await privateKey.sign(getSignaturePayload(staticPublicKey));
|
|
12
|
+
return NoiseHandshakePayload.encode({
|
|
13
|
+
identityKey: publicKeyToProtobuf(privateKey.publicKey),
|
|
14
|
+
identitySig,
|
|
15
|
+
extensions
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export async function decodeHandshakePayload(payloadBytes, remoteStaticKey, remoteIdentityKey) {
|
|
19
|
+
try {
|
|
20
|
+
const payload = NoiseHandshakePayload.decode(payloadBytes);
|
|
21
|
+
const publicKey = publicKeyFromProtobuf(payload.identityKey);
|
|
22
|
+
if (remoteIdentityKey?.equals(publicKey) === false) {
|
|
23
|
+
throw new Error(`Payload identity key ${publicKey} does not match expected remote identity key ${remoteIdentityKey}`);
|
|
24
|
+
}
|
|
25
|
+
if (!remoteStaticKey) {
|
|
26
|
+
throw new Error('Remote static does not exist');
|
|
27
|
+
}
|
|
28
|
+
const signaturePayload = getSignaturePayload(remoteStaticKey);
|
|
29
|
+
if (!(await publicKey.verify(signaturePayload, payload.identitySig))) {
|
|
30
|
+
throw new Error('Invalid payload signature');
|
|
31
|
+
}
|
|
32
|
+
return payload;
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
throw new UnexpectedPeerError(e.message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function getSignaturePayload(publicKey) {
|
|
39
|
+
const prefix = uint8ArrayFromString('noise-libp2p-static-key:');
|
|
40
|
+
if (publicKey instanceof Uint8Array) {
|
|
41
|
+
return uint8ArrayConcat([prefix, publicKey], prefix.length + publicKey.length);
|
|
42
|
+
}
|
|
43
|
+
publicKey.prepend(prefix);
|
|
44
|
+
return publicKey;
|
|
45
|
+
}
|
|
46
|
+
class EncryptedMessageStream extends AbstractMessageStream {
|
|
47
|
+
stream;
|
|
48
|
+
handshake;
|
|
49
|
+
metrics;
|
|
50
|
+
decoder;
|
|
51
|
+
constructor(stream, handshake, metrics) {
|
|
52
|
+
super({
|
|
53
|
+
log: stream.log,
|
|
54
|
+
inactivityTimeout: stream.inactivityTimeout,
|
|
55
|
+
maxReadBufferLength: stream.maxReadBufferLength,
|
|
56
|
+
direction: stream.direction
|
|
57
|
+
});
|
|
58
|
+
this.stream = stream;
|
|
59
|
+
this.handshake = handshake;
|
|
60
|
+
this.metrics = metrics;
|
|
61
|
+
this.decoder = new LengthPrefixedDecoder({
|
|
62
|
+
lengthDecoder: uint16BEDecode,
|
|
63
|
+
maxBufferSize: 16 * 1024 * 1024,
|
|
64
|
+
encodingLength: () => 2
|
|
65
|
+
});
|
|
66
|
+
const noiseOnMessageDecrypt = (evt) => {
|
|
67
|
+
try {
|
|
68
|
+
for (const buf of this.decoder.decode(evt.data)) {
|
|
69
|
+
this.onData(this.decrypt(buf));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
this.abort(err);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
this.stream.addEventListener('message', noiseOnMessageDecrypt);
|
|
77
|
+
const noiseOnClose = (evt) => {
|
|
78
|
+
if (evt.error != null) {
|
|
79
|
+
if (evt.local === true) {
|
|
80
|
+
this.abort(evt.error);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
this.onRemoteReset();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.onTransportClosed();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.stream.addEventListener('close', noiseOnClose);
|
|
91
|
+
const noiseOnDrain = () => {
|
|
92
|
+
this.safeDispatchEvent('drain');
|
|
93
|
+
};
|
|
94
|
+
this.stream.addEventListener('drain', noiseOnDrain);
|
|
95
|
+
const noiseOnRemoteCloseWrite = () => {
|
|
96
|
+
this.onRemoteCloseWrite();
|
|
97
|
+
};
|
|
98
|
+
this.stream.addEventListener('remoteCloseWrite', noiseOnRemoteCloseWrite);
|
|
99
|
+
}
|
|
100
|
+
encrypt(chunk) {
|
|
101
|
+
const output = new Uint8ArrayList();
|
|
102
|
+
for (let i = 0; i < chunk.byteLength; i += NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG) {
|
|
103
|
+
let end = i + NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG;
|
|
104
|
+
if (end > chunk.byteLength) {
|
|
105
|
+
end = chunk.byteLength;
|
|
106
|
+
}
|
|
107
|
+
let data;
|
|
108
|
+
if (chunk instanceof Uint8Array) {
|
|
109
|
+
data = this.handshake.encrypt(chunk.subarray(i, end));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
data = this.handshake.encrypt(chunk.sublist(i, end));
|
|
113
|
+
}
|
|
114
|
+
this.metrics?.encryptedPackets.increment();
|
|
115
|
+
output.append(uint16BEEncode(data.byteLength));
|
|
116
|
+
output.append(data);
|
|
117
|
+
}
|
|
118
|
+
return output;
|
|
119
|
+
}
|
|
120
|
+
decrypt(chunk) {
|
|
121
|
+
const output = new Uint8ArrayList();
|
|
122
|
+
for (let i = 0; i < chunk.byteLength; i += NOISE_MSG_MAX_LENGTH_BYTES) {
|
|
123
|
+
let end = i + NOISE_MSG_MAX_LENGTH_BYTES;
|
|
124
|
+
if (end > chunk.byteLength) {
|
|
125
|
+
end = chunk.byteLength;
|
|
126
|
+
}
|
|
127
|
+
if (end - CHACHA_TAG_LENGTH < i) {
|
|
128
|
+
throw new Error('Invalid chunk');
|
|
129
|
+
}
|
|
130
|
+
let encrypted;
|
|
131
|
+
if (chunk instanceof Uint8Array) {
|
|
132
|
+
encrypted = chunk.subarray(i, end);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
encrypted = chunk.sublist(i, end);
|
|
136
|
+
}
|
|
137
|
+
// memory allocation is not cheap so reuse the encrypted Uint8Array
|
|
138
|
+
// see https://github.com/ChainSafe/js-libp2p-noise/pull/242#issue-1422126164
|
|
139
|
+
// this is ok because chacha20 reads bytes one by one and don't reread after that
|
|
140
|
+
// it's also tested in https://github.com/ChainSafe/as-chacha20poly1305/pull/1/files#diff-25252846b58979dcaf4e41d47b3eadd7e4f335e7fb98da6c049b1f9cd011f381R48
|
|
141
|
+
const dst = chunk.subarray(i, end - CHACHA_TAG_LENGTH);
|
|
142
|
+
try {
|
|
143
|
+
const plaintext = this.handshake.decrypt(encrypted, dst);
|
|
144
|
+
this.metrics?.decryptedPackets.increment();
|
|
145
|
+
output.append(plaintext);
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
this.metrics?.decryptErrors.increment();
|
|
149
|
+
throw e;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return output;
|
|
153
|
+
}
|
|
154
|
+
close(options) {
|
|
155
|
+
return this.stream.close(options);
|
|
156
|
+
}
|
|
157
|
+
sendPause() {
|
|
158
|
+
this.stream.pause();
|
|
159
|
+
}
|
|
160
|
+
sendResume() {
|
|
161
|
+
this.stream.resume();
|
|
162
|
+
}
|
|
163
|
+
sendReset(err) {
|
|
164
|
+
this.stream.abort(err);
|
|
165
|
+
}
|
|
166
|
+
sendData(data) {
|
|
167
|
+
return {
|
|
168
|
+
sentBytes: data.byteLength,
|
|
169
|
+
canSendMore: this.stream.send(this.encrypt(data))
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export function toMessageStream(connection, handshake, metrics) {
|
|
174
|
+
return new EncryptedMessageStream(connection, handshake, metrics);
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC3E,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,sCAAsC,EAAE,MAAM,gBAAgB,CAAA;AACtH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAO1D,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,UAAsB,EACtB,eAA4C,EAC5C,UAA4B;IAE5B,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC,CAA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