@libp2p/tls 2.2.7-6059227cb → 2.2.7-87bc8d4fb
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/dist/src/tls.browser.d.ts +5 -3
- package/dist/src/tls.browser.d.ts.map +1 -1
- package/dist/src/tls.browser.js.map +1 -1
- package/dist/src/tls.d.ts +4 -4
- package/dist/src/tls.d.ts.map +1 -1
- package/dist/src/tls.js +27 -21
- package/dist/src/tls.js.map +1 -1
- package/dist/src/utils.d.ts +6 -5
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +91 -121
- package/dist/src/utils.js.map +1 -1
- package/package.json +15 -14
- package/src/tls.browser.ts +5 -3
- package/src/tls.ts +35 -25
- package/src/utils.ts +94 -135
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { serviceCapabilities } from '@libp2p/interface';
|
|
2
|
-
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions
|
|
2
|
+
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions } from '@libp2p/interface';
|
|
3
|
+
import type { Duplex } from 'it-stream-types';
|
|
4
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
3
5
|
export declare class TLS implements ConnectionEncrypter {
|
|
4
6
|
protocol: string;
|
|
5
7
|
constructor();
|
|
6
8
|
readonly [Symbol.toStringTag] = "@libp2p/tls";
|
|
7
9
|
readonly [serviceCapabilities]: string[];
|
|
8
|
-
secureInbound<Stream extends
|
|
9
|
-
secureOutbound<Stream extends
|
|
10
|
+
secureInbound<Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>>;
|
|
11
|
+
secureOutbound<Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>>;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=tls.browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tls.browser.d.ts","sourceRoot":"","sources":["../../src/tls.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,
|
|
1
|
+
{"version":3,"file":"tls.browser.d.ts","sourceRoot":"","sources":["../../src/tls.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAC7H,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,qBAAa,GAAI,YAAW,mBAAmB;IACtC,QAAQ,EAAE,MAAM,CAAW;;IAMlC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,iBAAgB;IAE7C,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAEvC;IAEK,aAAa,CAAE,MAAM,SAAS,MAAM,CAAC,cAAc,CAAC,UAAU,GAAG,cAAc,CAAC,CAAC,GAAG,mBAAmB,EAAG,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAI9L,cAAc,CAAE,MAAM,SAAS,MAAM,CAAC,cAAc,CAAC,UAAU,GAAG,cAAc,CAAC,CAAC,GAAG,mBAAmB,EAAG,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAGtM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tls.browser.js","sourceRoot":"","sources":["../../src/tls.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"tls.browser.js","sourceRoot":"","sources":["../../src/tls.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAKrC,MAAM,OAAO,GAAG;IACP,QAAQ,GAAW,QAAQ,CAAA;IAElC;QACE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;IAEQ,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,aAAa,CAAA;IAEpC,CAAC,mBAAmB,CAAC,GAAa;QACzC,+BAA+B;KAChC,CAAA;IAED,KAAK,CAAC,aAAa,CAA6F,IAAY,EAAE,OAAiC;QAC7J,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;IAED,KAAK,CAAC,cAAc,CAA6F,IAAY,EAAE,OAAiC;QAC9J,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;CACF"}
|
package/dist/src/tls.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { serviceCapabilities } from '@libp2p/interface';
|
|
21
21
|
import type { TLSComponents } from './index.js';
|
|
22
|
-
import type { ConnectionEncrypter, SecuredConnection, SecureConnectionOptions,
|
|
22
|
+
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions, SecurableStream } from '@libp2p/interface';
|
|
23
23
|
export declare class TLS implements ConnectionEncrypter {
|
|
24
24
|
protocol: string;
|
|
25
25
|
private readonly log;
|
|
@@ -28,11 +28,11 @@ export declare class TLS implements ConnectionEncrypter {
|
|
|
28
28
|
constructor(components: TLSComponents);
|
|
29
29
|
readonly [Symbol.toStringTag] = "@libp2p/tls";
|
|
30
30
|
readonly [serviceCapabilities]: string[];
|
|
31
|
-
secureInbound(
|
|
32
|
-
secureOutbound(
|
|
31
|
+
secureInbound<Stream extends SecurableStream = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>>;
|
|
32
|
+
secureOutbound<Stream extends SecurableStream = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>>;
|
|
33
33
|
/**
|
|
34
34
|
* Encrypt connection
|
|
35
35
|
*/
|
|
36
|
-
_encrypt(
|
|
36
|
+
_encrypt<Stream extends SecurableStream = MultiaddrConnection>(conn: Stream, isServer: boolean, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>>;
|
|
37
37
|
}
|
|
38
38
|
//# sourceMappingURL=tls.d.ts.map
|
package/dist/src/tls.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tls.d.ts","sourceRoot":"","sources":["../../src/tls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAA8B,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAInF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAU,uBAAuB,EAAoC,
|
|
1
|
+
{"version":3,"file":"tls.d.ts","sourceRoot":"","sources":["../../src/tls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAA8B,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAInF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAU,uBAAuB,EAAoC,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGxL,qBAAa,GAAI,YAAW,mBAAmB;IACtC,QAAQ,EAAE,MAAM,CAAW;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CASvB;gBAEY,UAAU,EAAE,aAAa;IA2BtC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,iBAAgB;IAE7C,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAEvC;IAEK,aAAa,CAAE,MAAM,SAAS,eAAe,GAAG,mBAAmB,EAAG,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAI1J,cAAc,CAAE,MAAM,SAAS,eAAe,GAAG,mBAAmB,EAAG,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAIjK;;OAEG;IACG,QAAQ,CAAE,MAAM,SAAS,eAAe,GAAG,mBAAmB,EAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAyJ/K"}
|
package/dist/src/tls.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { TLSSocket, connect } from 'node:tls';
|
|
21
21
|
import { InvalidCryptoExchangeError, serviceCapabilities } from '@libp2p/interface';
|
|
22
22
|
import { HandshakeTimeoutError } from './errors.js';
|
|
23
|
-
import { generateCertificate, verifyPeerCertificate,
|
|
23
|
+
import { generateCertificate, verifyPeerCertificate, itToStream, streamToIt } from './utils.js';
|
|
24
24
|
import { PROTOCOL } from './index.js';
|
|
25
25
|
export class TLS {
|
|
26
26
|
protocol = PROTOCOL;
|
|
@@ -57,17 +57,17 @@ export class TLS {
|
|
|
57
57
|
[serviceCapabilities] = [
|
|
58
58
|
'@libp2p/connection-encryption'
|
|
59
59
|
];
|
|
60
|
-
async secureInbound(
|
|
61
|
-
return this._encrypt(
|
|
60
|
+
async secureInbound(conn, options) {
|
|
61
|
+
return this._encrypt(conn, true, options);
|
|
62
62
|
}
|
|
63
|
-
async secureOutbound(
|
|
64
|
-
return this._encrypt(
|
|
63
|
+
async secureOutbound(conn, options) {
|
|
64
|
+
return this._encrypt(conn, false, options);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Encrypt connection
|
|
68
68
|
*/
|
|
69
|
-
async _encrypt(
|
|
70
|
-
const log =
|
|
69
|
+
async _encrypt(conn, isServer, options) {
|
|
70
|
+
const log = conn.log?.newScope('tls') ?? this.log;
|
|
71
71
|
let streamMuxer;
|
|
72
72
|
let streamMuxers = [];
|
|
73
73
|
if (options?.skipStreamMuxerNegotiation !== true) {
|
|
@@ -102,10 +102,9 @@ export class TLS {
|
|
|
102
102
|
return chosenProtocol;
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
-
const duplex = toNodeDuplex(connection);
|
|
106
105
|
let socket;
|
|
107
106
|
if (isServer) {
|
|
108
|
-
socket = new TLSSocket(
|
|
107
|
+
socket = new TLSSocket(itToStream(conn), {
|
|
109
108
|
...opts,
|
|
110
109
|
// require clients to send certificates
|
|
111
110
|
requestCert: true
|
|
@@ -113,13 +112,10 @@ export class TLS {
|
|
|
113
112
|
}
|
|
114
113
|
else {
|
|
115
114
|
socket = connect({
|
|
116
|
-
socket:
|
|
115
|
+
socket: itToStream(conn),
|
|
117
116
|
...opts
|
|
118
117
|
});
|
|
119
118
|
}
|
|
120
|
-
duplex.on('error', (err) => {
|
|
121
|
-
socket.emit('error', err);
|
|
122
|
-
});
|
|
123
119
|
const onAbort = () => {
|
|
124
120
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
125
121
|
abort: true
|
|
@@ -133,7 +129,7 @@ export class TLS {
|
|
|
133
129
|
return new Promise((resolve, reject) => {
|
|
134
130
|
const verifyRemote = () => {
|
|
135
131
|
const remote = socket.getPeerCertificate();
|
|
136
|
-
verifyPeerCertificate(remote.raw, options?.remotePeer, log)
|
|
132
|
+
verifyPeerCertificate(remote.raw, options?.remotePeer, this.log)
|
|
137
133
|
.then(remotePeer => {
|
|
138
134
|
log('remote certificate ok, remote peer %p', remotePeer);
|
|
139
135
|
// 'libp2p' is a special protocol - if it's sent the remote does not
|
|
@@ -144,13 +140,18 @@ export class TLS {
|
|
|
144
140
|
if (streamMuxer == null) {
|
|
145
141
|
const err = new InvalidCryptoExchangeError(`Selected muxer ${socket.alpnProtocol} did not exist`);
|
|
146
142
|
log.error(`Selected muxer ${socket.alpnProtocol} did not exist - %e`, err);
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
if (isAbortable(conn)) {
|
|
144
|
+
conn.abort(err);
|
|
145
|
+
reject(err);
|
|
146
|
+
}
|
|
149
147
|
}
|
|
150
148
|
}
|
|
151
149
|
resolve({
|
|
152
150
|
remotePeer,
|
|
153
|
-
|
|
151
|
+
conn: {
|
|
152
|
+
...conn,
|
|
153
|
+
...streamToIt(socket)
|
|
154
|
+
},
|
|
154
155
|
streamMuxer
|
|
155
156
|
});
|
|
156
157
|
})
|
|
@@ -162,18 +163,20 @@ export class TLS {
|
|
|
162
163
|
});
|
|
163
164
|
};
|
|
164
165
|
socket.on('error', (err) => {
|
|
165
|
-
log.error('error encrypting %s connection - %e',
|
|
166
|
+
this.log.error('error encrypting %s connection - %e', isServer ? 'server' : 'client', err);
|
|
166
167
|
if (err.name !== 'HandshakeTimeoutError') {
|
|
167
168
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
168
169
|
error: true
|
|
169
170
|
});
|
|
170
171
|
}
|
|
171
|
-
socket.destroy();
|
|
172
|
-
|
|
172
|
+
socket.destroy(err);
|
|
173
|
+
if (isAbortable(conn)) {
|
|
174
|
+
conn.abort(err);
|
|
175
|
+
}
|
|
173
176
|
reject(err);
|
|
174
177
|
});
|
|
175
178
|
socket.once('secure', () => {
|
|
176
|
-
log('verifying remote certificate
|
|
179
|
+
this.log('verifying remote certificate');
|
|
177
180
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
178
181
|
secure: true
|
|
179
182
|
});
|
|
@@ -195,4 +198,7 @@ export class TLS {
|
|
|
195
198
|
});
|
|
196
199
|
}
|
|
197
200
|
}
|
|
201
|
+
function isAbortable(obj) {
|
|
202
|
+
return typeof obj?.abort === 'function';
|
|
203
|
+
}
|
|
198
204
|
//# sourceMappingURL=tls.js.map
|
package/dist/src/tls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tls.js","sourceRoot":"","sources":["../../src/tls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"tls.js","sourceRoot":"","sources":["../../src/tls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,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,GAAG,EAAE;gBACxB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC;oBAC7D,OAAO,EAAE,IAAI;iBACd,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;YACF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACtB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC;oBAC7D,KAAK,EAAE,IAAI;iBACZ,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC;aACC,OAAO,CAAC,GAAG,EAAE;YACZ,OAAO,EAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AAMD,SAAS,WAAW,CAAM,GAA2B;IACnD,OAAO,OAAO,GAAG,EAAE,KAAK,KAAK,UAAU,CAAA;AACzC,CAAC"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Duplex } from 'node:stream';
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
1
|
+
import { Duplex as DuplexStream } from 'node:stream';
|
|
2
|
+
import type { PeerId, Logger, PrivateKey, AbortOptions } from '@libp2p/interface';
|
|
3
|
+
import type { Duplex } from 'it-stream-types';
|
|
4
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
4
5
|
export declare function verifyPeerCertificate(rawCertificate: Uint8Array, expectedPeerId?: PeerId, log?: Logger): Promise<PeerId>;
|
|
5
6
|
export declare function generateCertificate(privateKey: PrivateKey, options?: AbortOptions): Promise<{
|
|
6
7
|
cert: string;
|
|
@@ -10,6 +11,6 @@ export declare function generateCertificate(privateKey: PrivateKey, options?: Ab
|
|
|
10
11
|
* @see https://github.com/libp2p/specs/blob/master/tls/tls.md#libp2p-public-key-extension
|
|
11
12
|
*/
|
|
12
13
|
export declare function encodeSignatureData(certPublicKey: ArrayBuffer): Uint8Array;
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function itToStream(conn: Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>>): DuplexStream;
|
|
15
|
+
export declare function streamToIt(stream: DuplexStream): Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>>;
|
|
15
16
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAA;AAepD,OAAO,KAAK,EAAE,MAAM,EAAgC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAE/G,OAAO,KAAK,EAAE,MAAM,EAAU,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAapD,wBAAsB,qBAAqB,CAAE,cAAc,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4D/H;AAED,wBAAsB,mBAAmB,CAAE,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAuDjI;AAeD;;GAEG;AACH,wBAAgB,mBAAmB,CAAE,aAAa,EAAE,WAAW,GAAG,UAAU,CAQ3E;AAmBD,wBAAgB,UAAU,CAAE,IAAI,EAAE,MAAM,CAAC,cAAc,CAAC,UAAU,GAAG,cAAc,CAAC,CAAC,GAAG,YAAY,CAoCnG;AA0DD,wBAAgB,UAAU,CAAE,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,UAAU,GAAG,cAAc,CAAC,CAAC,CAErG"}
|
package/dist/src/utils.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Duplex } from 'node:stream';
|
|
3
|
-
import tls from 'node:tls';
|
|
1
|
+
import { Duplex as DuplexStream } from 'node:stream';
|
|
4
2
|
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys';
|
|
5
|
-
import { InvalidCryptoExchangeError, UnexpectedPeerError
|
|
3
|
+
import { InvalidCryptoExchangeError, UnexpectedPeerError } from '@libp2p/interface';
|
|
6
4
|
import { peerIdFromCID } from '@libp2p/peer-id';
|
|
7
|
-
import { AbstractMessageStream } from '@libp2p/utils';
|
|
8
5
|
import { AsnConvert } from '@peculiar/asn1-schema';
|
|
9
6
|
import * as asn1X509 from '@peculiar/asn1-x509';
|
|
10
7
|
import { Crypto } from '@peculiar/webcrypto';
|
|
11
8
|
import * as x509 from '@peculiar/x509';
|
|
12
9
|
import * as asn1js from 'asn1js';
|
|
13
|
-
import {
|
|
14
|
-
import { Uint8ArrayList } from 'uint8arraylist';
|
|
10
|
+
import { queuelessPushable } from 'it-queueless-pushable';
|
|
15
11
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
16
12
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
17
13
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
@@ -66,7 +62,7 @@ export async function verifyPeerCertificate(rawCertificate, expectedPeerId, log)
|
|
|
66
62
|
}
|
|
67
63
|
const remotePeerId = peerIdFromCID(remoteLibp2pPublicKey.toCID());
|
|
68
64
|
if (expectedPeerId?.equals(remotePeerId) === false) {
|
|
69
|
-
log?.error('invalid peer id
|
|
65
|
+
log?.error('invalid peer id');
|
|
70
66
|
throw new UnexpectedPeerError();
|
|
71
67
|
}
|
|
72
68
|
return remotePeerId;
|
|
@@ -154,138 +150,112 @@ function formatAsPem(str) {
|
|
|
154
150
|
finalString = finalString + '-----END PRIVATE KEY-----';
|
|
155
151
|
return finalString;
|
|
156
152
|
}
|
|
157
|
-
export function
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
socket.pause();
|
|
166
|
-
pEvent(stream, 'drain', {
|
|
167
|
-
rejectionEvents: ['close']
|
|
168
|
-
})
|
|
153
|
+
export function itToStream(conn) {
|
|
154
|
+
const output = queuelessPushable();
|
|
155
|
+
const iterator = conn.source[Symbol.asyncIterator]();
|
|
156
|
+
const stream = new DuplexStream({
|
|
157
|
+
autoDestroy: false,
|
|
158
|
+
allowHalfOpen: true,
|
|
159
|
+
write(chunk, encoding, callback) {
|
|
160
|
+
output.push(chunk)
|
|
169
161
|
.then(() => {
|
|
170
|
-
socket.resume();
|
|
171
162
|
callback();
|
|
172
|
-
},
|
|
163
|
+
}, err => {
|
|
173
164
|
callback(err);
|
|
174
165
|
});
|
|
175
|
-
}
|
|
176
|
-
catch (err) {
|
|
177
|
-
callback(err);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
// pause incoming messages until pulled from duplex
|
|
181
|
-
stream.pause();
|
|
182
|
-
const socket = new Duplex({
|
|
183
|
-
write(chunk, encoding, callback) {
|
|
184
|
-
sendAndCallback(chunk, callback);
|
|
185
|
-
},
|
|
186
|
-
writev(chunks, callback) {
|
|
187
|
-
sendAndCallback(new Uint8ArrayList(...chunks.map(({ chunk }) => chunk)), callback);
|
|
188
166
|
},
|
|
189
167
|
read() {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
168
|
+
iterator.next()
|
|
169
|
+
.then(result => {
|
|
170
|
+
if (result.done === true) {
|
|
171
|
+
this.push(null);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
this.push(result.value);
|
|
175
|
+
}
|
|
176
|
+
}, (err) => {
|
|
177
|
+
this.destroy(err);
|
|
178
|
+
});
|
|
195
179
|
}
|
|
196
180
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
else {
|
|
204
|
-
for (const chunk of buf) {
|
|
205
|
-
sendMore = socket.push(chunk);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (!sendMore) {
|
|
209
|
-
stream.pause();
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
stream.addEventListener('message', onMessage);
|
|
213
|
-
const onClose = (evt) => {
|
|
214
|
-
socket.destroy(evt.error);
|
|
215
|
-
};
|
|
216
|
-
stream.addEventListener('close', onClose);
|
|
217
|
-
return socket;
|
|
181
|
+
// @ts-expect-error return type of sink is unknown
|
|
182
|
+
conn.sink(output)
|
|
183
|
+
.catch((err) => {
|
|
184
|
+
stream.destroy(err);
|
|
185
|
+
});
|
|
186
|
+
return stream;
|
|
218
187
|
}
|
|
219
|
-
class
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
// accept decrypted data
|
|
234
|
-
this.socket.on('data', (buf) => {
|
|
235
|
-
this.onData(buf);
|
|
236
|
-
});
|
|
237
|
-
this.socket.on('error', err => {
|
|
238
|
-
stream.abort(err);
|
|
188
|
+
class DuplexIterable {
|
|
189
|
+
source;
|
|
190
|
+
stream;
|
|
191
|
+
constructor(stream) {
|
|
192
|
+
this.stream = stream;
|
|
193
|
+
this.source = queuelessPushable();
|
|
194
|
+
stream.addListener('data', (buf) => {
|
|
195
|
+
stream.pause();
|
|
196
|
+
this.source.push(buf.subarray())
|
|
197
|
+
.then(() => {
|
|
198
|
+
stream.resume();
|
|
199
|
+
}, (err) => {
|
|
200
|
+
stream.emit('error', err);
|
|
201
|
+
});
|
|
239
202
|
});
|
|
240
|
-
|
|
241
|
-
|
|
203
|
+
// both ends closed
|
|
204
|
+
stream.addListener('close', () => {
|
|
205
|
+
this.source.end()
|
|
242
206
|
.catch(err => {
|
|
243
|
-
stream.
|
|
207
|
+
stream.emit('error', err);
|
|
244
208
|
});
|
|
245
209
|
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
210
|
+
stream.addListener('error', (err) => {
|
|
211
|
+
this.source.end(err)
|
|
212
|
+
.catch(() => { });
|
|
249
213
|
});
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.
|
|
214
|
+
// just writable end closed
|
|
215
|
+
stream.addListener('finish', () => {
|
|
216
|
+
this.source.end()
|
|
217
|
+
.catch(() => { });
|
|
253
218
|
});
|
|
219
|
+
this.sink = this.sink.bind(this);
|
|
254
220
|
}
|
|
255
|
-
async
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
sendResume() {
|
|
263
|
-
this.socket.resume();
|
|
264
|
-
}
|
|
265
|
-
async sendClose(options) {
|
|
266
|
-
this.socket.destroySoon();
|
|
267
|
-
options?.signal?.throwIfAborted();
|
|
268
|
-
}
|
|
269
|
-
sendReset() {
|
|
270
|
-
this.socket.resetAndDestroy();
|
|
271
|
-
}
|
|
272
|
-
sendData(data) {
|
|
273
|
-
let sentBytes = 0;
|
|
274
|
-
let canSendMore = true;
|
|
275
|
-
for (const buf of data) {
|
|
276
|
-
sentBytes += buf.byteLength;
|
|
277
|
-
canSendMore = this.socket.write(buf);
|
|
278
|
-
if (!canSendMore) {
|
|
279
|
-
break;
|
|
221
|
+
async sink(source) {
|
|
222
|
+
try {
|
|
223
|
+
for await (const buf of source) {
|
|
224
|
+
const sendMore = this.stream.write(buf.subarray());
|
|
225
|
+
if (!sendMore) {
|
|
226
|
+
await waitForBackpressure(this.stream);
|
|
227
|
+
}
|
|
280
228
|
}
|
|
229
|
+
// close writable end
|
|
230
|
+
this.stream.end();
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
this.stream.destroy(err);
|
|
234
|
+
throw err;
|
|
281
235
|
}
|
|
282
|
-
return {
|
|
283
|
-
sentBytes,
|
|
284
|
-
canSendMore
|
|
285
|
-
};
|
|
286
236
|
}
|
|
287
237
|
}
|
|
288
|
-
export function
|
|
289
|
-
return new
|
|
238
|
+
export function streamToIt(stream) {
|
|
239
|
+
return new DuplexIterable(stream);
|
|
240
|
+
}
|
|
241
|
+
async function waitForBackpressure(stream) {
|
|
242
|
+
await new Promise((resolve, reject) => {
|
|
243
|
+
const continueListener = () => {
|
|
244
|
+
cleanUp();
|
|
245
|
+
resolve();
|
|
246
|
+
};
|
|
247
|
+
const stopListener = (err) => {
|
|
248
|
+
cleanUp();
|
|
249
|
+
reject(err ?? new Error('Stream ended'));
|
|
250
|
+
};
|
|
251
|
+
const cleanUp = () => {
|
|
252
|
+
stream.removeListener('drain', continueListener);
|
|
253
|
+
stream.removeListener('end', stopListener);
|
|
254
|
+
stream.removeListener('error', stopListener);
|
|
255
|
+
};
|
|
256
|
+
stream.addListener('drain', continueListener);
|
|
257
|
+
stream.addListener('end', stopListener);
|
|
258
|
+
stream.addListener('error', stopListener);
|
|
259
|
+
});
|
|
290
260
|
}
|
|
291
261
|
//# sourceMappingURL=utils.js.map
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,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B;IAC9C,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAA;AACnC,CAAC;AAED,KAAK,UAAU,mBAAmB,CAAE,MAAoB;IACtD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,MAAM,gBAAgB,GAAG,GAAS,EAAE;YAClC,OAAO,EAAE,CAAA;YACT,OAAO,EAAE,CAAA;QACX,CAAC,CAAA;QACD,MAAM,YAAY,GAAG,CAAC,GAAW,EAAQ,EAAE;YACzC,OAAO,EAAE,CAAA;YACT,MAAM,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAA;QAC1C,CAAC,CAAA;QAED,MAAM,OAAO,GAAG,GAAS,EAAE;YACzB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;YAChD,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;YAC1C,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;QAC9C,CAAC,CAAA;QAED,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;QAC7C,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;QACvC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tls",
|
|
3
|
-
"version": "2.2.7-
|
|
3
|
+
"version": "2.2.7-87bc8d4fb",
|
|
4
4
|
"description": "A connection encrypter that uses TLS 1.3",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-tls#readme",
|
|
@@ -41,25 +41,26 @@
|
|
|
41
41
|
"doc-check": "aegir doc-check"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@libp2p/crypto": "5.1.8-
|
|
45
|
-
"@libp2p/interface": "2.11.0-
|
|
46
|
-
"@libp2p/peer-id": "5.1.9-
|
|
47
|
-
"@
|
|
48
|
-
"@peculiar/asn1-
|
|
49
|
-
"@peculiar/asn1-x509": "^2.4.0",
|
|
44
|
+
"@libp2p/crypto": "5.1.8-87bc8d4fb",
|
|
45
|
+
"@libp2p/interface": "2.11.0-87bc8d4fb",
|
|
46
|
+
"@libp2p/peer-id": "5.1.9-87bc8d4fb",
|
|
47
|
+
"@peculiar/asn1-schema": "^2.3.15",
|
|
48
|
+
"@peculiar/asn1-x509": "^2.3.15",
|
|
50
49
|
"@peculiar/webcrypto": "^1.5.0",
|
|
51
|
-
"@peculiar/x509": "^1.
|
|
50
|
+
"@peculiar/x509": "^1.12.3",
|
|
52
51
|
"asn1js": "^3.0.6",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
52
|
+
"it-queueless-pushable": "^2.0.1",
|
|
53
|
+
"it-stream-types": "^2.0.2",
|
|
54
|
+
"protons-runtime": "^5.5.0",
|
|
55
55
|
"uint8arraylist": "^2.4.8",
|
|
56
56
|
"uint8arrays": "^5.1.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@libp2p/logger": "5.2.0-
|
|
60
|
-
"aegir": "^47.0.
|
|
61
|
-
"
|
|
62
|
-
"
|
|
59
|
+
"@libp2p/logger": "5.2.0-87bc8d4fb",
|
|
60
|
+
"aegir": "^47.0.14",
|
|
61
|
+
"it-pair": "^2.0.6",
|
|
62
|
+
"protons": "^7.6.1",
|
|
63
|
+
"sinon": "^20.0.0",
|
|
63
64
|
"sinon-ts": "^2.0.0"
|
|
64
65
|
},
|
|
65
66
|
"browser": {
|
package/src/tls.browser.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { serviceCapabilities } from '@libp2p/interface'
|
|
2
2
|
import { PROTOCOL } from './index.js'
|
|
3
|
-
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions
|
|
3
|
+
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions } from '@libp2p/interface'
|
|
4
|
+
import type { Duplex } from 'it-stream-types'
|
|
5
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
4
6
|
|
|
5
7
|
export class TLS implements ConnectionEncrypter {
|
|
6
8
|
public protocol: string = PROTOCOL
|
|
@@ -15,11 +17,11 @@ export class TLS implements ConnectionEncrypter {
|
|
|
15
17
|
'@libp2p/connection-encryption'
|
|
16
18
|
]
|
|
17
19
|
|
|
18
|
-
async secureInbound <Stream extends
|
|
20
|
+
async secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
19
21
|
throw new Error('TLS encryption is not possible in browsers')
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
async secureOutbound <Stream extends
|
|
24
|
+
async secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
23
25
|
throw new Error('TLS encryption is not possible in browsers')
|
|
24
26
|
}
|
|
25
27
|
}
|
package/src/tls.ts
CHANGED
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
import { TLSSocket, connect } from 'node:tls'
|
|
22
22
|
import { InvalidCryptoExchangeError, serviceCapabilities } from '@libp2p/interface'
|
|
23
23
|
import { HandshakeTimeoutError } from './errors.js'
|
|
24
|
-
import { generateCertificate, verifyPeerCertificate,
|
|
24
|
+
import { generateCertificate, verifyPeerCertificate, itToStream, streamToIt } from './utils.js'
|
|
25
25
|
import { PROTOCOL } from './index.js'
|
|
26
26
|
import type { TLSComponents } from './index.js'
|
|
27
|
-
import type { ConnectionEncrypter, SecuredConnection, Logger, SecureConnectionOptions, CounterGroup, StreamMuxerFactory,
|
|
27
|
+
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, Logger, SecureConnectionOptions, CounterGroup, StreamMuxerFactory, SecurableStream } from '@libp2p/interface'
|
|
28
28
|
import type { TLSSocketOptions } from 'node:tls'
|
|
29
29
|
|
|
30
30
|
export class TLS implements ConnectionEncrypter {
|
|
@@ -75,19 +75,19 @@ export class TLS implements ConnectionEncrypter {
|
|
|
75
75
|
'@libp2p/connection-encryption'
|
|
76
76
|
]
|
|
77
77
|
|
|
78
|
-
async secureInbound (
|
|
79
|
-
return this._encrypt(
|
|
78
|
+
async secureInbound <Stream extends SecurableStream = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
79
|
+
return this._encrypt(conn, true, options)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
async secureOutbound (
|
|
83
|
-
return this._encrypt(
|
|
82
|
+
async secureOutbound <Stream extends SecurableStream = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
83
|
+
return this._encrypt(conn, false, options)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* Encrypt connection
|
|
88
88
|
*/
|
|
89
|
-
async _encrypt (
|
|
90
|
-
const log =
|
|
89
|
+
async _encrypt <Stream extends SecurableStream = MultiaddrConnection> (conn: Stream, isServer: boolean, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
90
|
+
const log = conn.log?.newScope('tls') ?? this.log
|
|
91
91
|
let streamMuxer: StreamMuxerFactory | undefined
|
|
92
92
|
|
|
93
93
|
let streamMuxers: string[] = []
|
|
@@ -131,26 +131,21 @@ export class TLS implements ConnectionEncrypter {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
const duplex = toNodeDuplex(connection)
|
|
135
134
|
let socket: TLSSocket
|
|
136
135
|
|
|
137
136
|
if (isServer) {
|
|
138
|
-
socket = new TLSSocket(
|
|
137
|
+
socket = new TLSSocket(itToStream(conn), {
|
|
139
138
|
...opts,
|
|
140
139
|
// require clients to send certificates
|
|
141
140
|
requestCert: true
|
|
142
141
|
})
|
|
143
142
|
} else {
|
|
144
143
|
socket = connect({
|
|
145
|
-
socket:
|
|
144
|
+
socket: itToStream(conn),
|
|
146
145
|
...opts
|
|
147
146
|
})
|
|
148
147
|
}
|
|
149
148
|
|
|
150
|
-
duplex.on('error', (err) => {
|
|
151
|
-
socket.emit('error', err)
|
|
152
|
-
})
|
|
153
|
-
|
|
154
149
|
const onAbort = (): void => {
|
|
155
150
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
156
151
|
abort: true
|
|
@@ -163,11 +158,11 @@ export class TLS implements ConnectionEncrypter {
|
|
|
163
158
|
|
|
164
159
|
options?.signal?.addEventListener('abort', onAbort)
|
|
165
160
|
|
|
166
|
-
return new Promise<SecuredConnection<
|
|
161
|
+
return new Promise<SecuredConnection<Stream>>((resolve, reject) => {
|
|
167
162
|
const verifyRemote = (): void => {
|
|
168
163
|
const remote = socket.getPeerCertificate()
|
|
169
164
|
|
|
170
|
-
verifyPeerCertificate(remote.raw, options?.remotePeer, log)
|
|
165
|
+
verifyPeerCertificate(remote.raw, options?.remotePeer, this.log)
|
|
171
166
|
.then(remotePeer => {
|
|
172
167
|
log('remote certificate ok, remote peer %p', remotePeer)
|
|
173
168
|
|
|
@@ -181,14 +176,19 @@ export class TLS implements ConnectionEncrypter {
|
|
|
181
176
|
const err = new InvalidCryptoExchangeError(`Selected muxer ${socket.alpnProtocol} did not exist`)
|
|
182
177
|
log.error(`Selected muxer ${socket.alpnProtocol} did not exist - %e`, err)
|
|
183
178
|
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
if (isAbortable(conn)) {
|
|
180
|
+
conn.abort(err)
|
|
181
|
+
reject(err)
|
|
182
|
+
}
|
|
186
183
|
}
|
|
187
184
|
}
|
|
188
185
|
|
|
189
186
|
resolve({
|
|
190
187
|
remotePeer,
|
|
191
|
-
|
|
188
|
+
conn: {
|
|
189
|
+
...conn,
|
|
190
|
+
...streamToIt(socket)
|
|
191
|
+
},
|
|
192
192
|
streamMuxer
|
|
193
193
|
})
|
|
194
194
|
})
|
|
@@ -196,13 +196,12 @@ export class TLS implements ConnectionEncrypter {
|
|
|
196
196
|
this.metrics[isServer ? 'server' : 'client'].errors?.increment({
|
|
197
197
|
verify_peer_certificate: true
|
|
198
198
|
})
|
|
199
|
-
|
|
200
199
|
socket.emit('error', err)
|
|
201
200
|
})
|
|
202
201
|
}
|
|
203
202
|
|
|
204
203
|
socket.on('error', (err: Error) => {
|
|
205
|
-
log.error('error encrypting %s connection - %e',
|
|
204
|
+
this.log.error('error encrypting %s connection - %e', isServer ? 'server' : 'client', err)
|
|
206
205
|
|
|
207
206
|
if (err.name !== 'HandshakeTimeoutError') {
|
|
208
207
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
@@ -210,13 +209,16 @@ export class TLS implements ConnectionEncrypter {
|
|
|
210
209
|
})
|
|
211
210
|
}
|
|
212
211
|
|
|
213
|
-
socket.destroy()
|
|
214
|
-
|
|
212
|
+
socket.destroy(err)
|
|
213
|
+
|
|
214
|
+
if (isAbortable(conn)) {
|
|
215
|
+
conn.abort(err)
|
|
216
|
+
}
|
|
215
217
|
|
|
216
218
|
reject(err)
|
|
217
219
|
})
|
|
218
220
|
socket.once('secure', () => {
|
|
219
|
-
log('verifying remote certificate
|
|
221
|
+
this.log('verifying remote certificate')
|
|
220
222
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
221
223
|
secure: true
|
|
222
224
|
})
|
|
@@ -238,3 +240,11 @@ export class TLS implements ConnectionEncrypter {
|
|
|
238
240
|
})
|
|
239
241
|
}
|
|
240
242
|
}
|
|
243
|
+
|
|
244
|
+
interface Abortable {
|
|
245
|
+
abort (err: Error): void
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isAbortable <T> (obj: T & Partial<Abortable>): obj is T & Abortable {
|
|
249
|
+
return typeof obj?.abort === 'function'
|
|
250
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Duplex } from 'node:stream'
|
|
3
|
-
import tls from 'node:tls'
|
|
1
|
+
import { Duplex as DuplexStream } from 'node:stream'
|
|
4
2
|
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'
|
|
5
|
-
import { InvalidCryptoExchangeError, UnexpectedPeerError
|
|
3
|
+
import { InvalidCryptoExchangeError, UnexpectedPeerError } from '@libp2p/interface'
|
|
6
4
|
import { peerIdFromCID } from '@libp2p/peer-id'
|
|
7
|
-
import { AbstractMessageStream } from '@libp2p/utils'
|
|
8
5
|
import { AsnConvert } from '@peculiar/asn1-schema'
|
|
9
6
|
import * as asn1X509 from '@peculiar/asn1-x509'
|
|
10
7
|
import { Crypto } from '@peculiar/webcrypto'
|
|
11
8
|
import * as x509 from '@peculiar/x509'
|
|
12
9
|
import * as asn1js from 'asn1js'
|
|
13
|
-
import {
|
|
14
|
-
import { Uint8ArrayList } from 'uint8arraylist'
|
|
10
|
+
import { queuelessPushable } from 'it-queueless-pushable'
|
|
15
11
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
16
12
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
17
13
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
18
14
|
import { InvalidCertificateError } from './errors.js'
|
|
19
15
|
import { KeyType, PublicKey } from './pb/index.js'
|
|
20
|
-
import type { PeerId, PublicKey as Libp2pPublicKey, Logger, PrivateKey, AbortOptions
|
|
21
|
-
import type {
|
|
16
|
+
import type { PeerId, PublicKey as Libp2pPublicKey, Logger, PrivateKey, AbortOptions } from '@libp2p/interface'
|
|
17
|
+
import type { Pushable } from 'it-queueless-pushable'
|
|
18
|
+
import type { Duplex, Source } from 'it-stream-types'
|
|
19
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
22
20
|
|
|
23
21
|
const crypto = new Crypto()
|
|
24
22
|
x509.cryptoProvider.set(crypto)
|
|
@@ -86,7 +84,7 @@ export async function verifyPeerCertificate (rawCertificate: Uint8Array, expecte
|
|
|
86
84
|
const remotePeerId = peerIdFromCID(remoteLibp2pPublicKey.toCID())
|
|
87
85
|
|
|
88
86
|
if (expectedPeerId?.equals(remotePeerId) === false) {
|
|
89
|
-
log?.error('invalid peer id
|
|
87
|
+
log?.error('invalid peer id')
|
|
90
88
|
throw new UnexpectedPeerError()
|
|
91
89
|
}
|
|
92
90
|
|
|
@@ -193,162 +191,123 @@ function formatAsPem (str: string): string {
|
|
|
193
191
|
return finalString
|
|
194
192
|
}
|
|
195
193
|
|
|
196
|
-
export function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const sendMore = stream.send(chunk)
|
|
200
|
-
|
|
201
|
-
if (sendMore) {
|
|
202
|
-
callback()
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
socket.pause()
|
|
194
|
+
export function itToStream (conn: Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>>): DuplexStream {
|
|
195
|
+
const output = queuelessPushable<Uint8Array>()
|
|
196
|
+
const iterator = conn.source[Symbol.asyncIterator]() as AsyncGenerator<Uint8Array>
|
|
207
197
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
198
|
+
const stream = new DuplexStream({
|
|
199
|
+
autoDestroy: false,
|
|
200
|
+
allowHalfOpen: true,
|
|
201
|
+
write (chunk, encoding, callback) {
|
|
202
|
+
output.push(chunk)
|
|
211
203
|
.then(() => {
|
|
212
|
-
socket.resume()
|
|
213
204
|
callback()
|
|
214
|
-
},
|
|
205
|
+
}, err => {
|
|
215
206
|
callback(err)
|
|
216
207
|
})
|
|
217
|
-
} catch (err: any) {
|
|
218
|
-
callback(err)
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// pause incoming messages until pulled from duplex
|
|
223
|
-
stream.pause()
|
|
224
|
-
|
|
225
|
-
const socket = new Duplex({
|
|
226
|
-
write (chunk, encoding, callback) {
|
|
227
|
-
sendAndCallback(chunk, callback)
|
|
228
|
-
},
|
|
229
|
-
writev (chunks, callback) {
|
|
230
|
-
sendAndCallback(new Uint8ArrayList(...chunks.map(({ chunk }) => chunk)), callback)
|
|
231
208
|
},
|
|
232
209
|
read () {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
210
|
+
iterator.next()
|
|
211
|
+
.then(result => {
|
|
212
|
+
if (result.done === true) {
|
|
213
|
+
this.push(null)
|
|
214
|
+
} else {
|
|
215
|
+
this.push(result.value)
|
|
216
|
+
}
|
|
217
|
+
}, (err) => {
|
|
218
|
+
this.destroy(err)
|
|
219
|
+
})
|
|
238
220
|
}
|
|
239
221
|
})
|
|
240
222
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
sendMore = socket.push(buf)
|
|
247
|
-
} else {
|
|
248
|
-
for (const chunk of buf) {
|
|
249
|
-
sendMore = socket.push(chunk)
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (!sendMore) {
|
|
254
|
-
stream.pause()
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
stream.addEventListener('message', onMessage)
|
|
258
|
-
|
|
259
|
-
const onClose = (evt: StreamCloseEvent): void => {
|
|
260
|
-
socket.destroy(evt.error)
|
|
261
|
-
}
|
|
262
|
-
stream.addEventListener('close', onClose)
|
|
223
|
+
// @ts-expect-error return type of sink is unknown
|
|
224
|
+
conn.sink(output)
|
|
225
|
+
.catch((err: any) => {
|
|
226
|
+
stream.destroy(err)
|
|
227
|
+
})
|
|
263
228
|
|
|
264
|
-
return
|
|
229
|
+
return stream
|
|
265
230
|
}
|
|
266
231
|
|
|
267
|
-
class
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* @param stream - The maConn that encrypted data is transferred over
|
|
272
|
-
* @param socket - Performs encryption/decryption
|
|
273
|
-
*/
|
|
274
|
-
constructor (stream: MessageStream, socket: tls.TLSSocket) {
|
|
275
|
-
super({
|
|
276
|
-
log: stream.log,
|
|
277
|
-
inactivityTimeout: stream.inactivityTimeout,
|
|
278
|
-
maxReadBufferLength: stream.maxReadBufferLength,
|
|
279
|
-
direction: stream.direction
|
|
280
|
-
})
|
|
232
|
+
class DuplexIterable implements Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
|
|
233
|
+
source: Pushable<Uint8Array>
|
|
234
|
+
private readonly stream: DuplexStream
|
|
281
235
|
|
|
282
|
-
|
|
236
|
+
constructor (stream: DuplexStream) {
|
|
237
|
+
this.stream = stream
|
|
238
|
+
this.source = queuelessPushable<Uint8Array>()
|
|
283
239
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
this.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
240
|
+
stream.addListener('data', (buf) => {
|
|
241
|
+
stream.pause()
|
|
242
|
+
this.source.push(buf.subarray())
|
|
243
|
+
.then(() => {
|
|
244
|
+
stream.resume()
|
|
245
|
+
}, (err) => {
|
|
246
|
+
stream.emit('error', err)
|
|
247
|
+
})
|
|
290
248
|
})
|
|
291
|
-
|
|
292
|
-
|
|
249
|
+
// both ends closed
|
|
250
|
+
stream.addListener('close', () => {
|
|
251
|
+
this.source.end()
|
|
293
252
|
.catch(err => {
|
|
294
|
-
stream.
|
|
253
|
+
stream.emit('error', err)
|
|
295
254
|
})
|
|
296
255
|
})
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
this.safeDispatchEvent('drain')
|
|
256
|
+
stream.addListener('error', (err) => {
|
|
257
|
+
this.source.end(err)
|
|
258
|
+
.catch(() => {})
|
|
301
259
|
})
|
|
302
|
-
|
|
303
|
-
stream.
|
|
304
|
-
|
|
305
|
-
|
|
260
|
+
// just writable end closed
|
|
261
|
+
stream.addListener('finish', () => {
|
|
262
|
+
this.source.end()
|
|
263
|
+
.catch(() => {})
|
|
306
264
|
})
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
async close (options?: AbortOptions): Promise<void> {
|
|
310
|
-
this.socket.destroySoon()
|
|
311
265
|
|
|
312
|
-
|
|
266
|
+
this.sink = this.sink.bind(this)
|
|
313
267
|
}
|
|
314
268
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
sendResume (): void {
|
|
320
|
-
this.socket.resume()
|
|
321
|
-
}
|
|
269
|
+
async sink (source: Source<Uint8Array | Uint8ArrayList>): Promise<void> {
|
|
270
|
+
try {
|
|
271
|
+
for await (const buf of source) {
|
|
272
|
+
const sendMore = this.stream.write(buf.subarray())
|
|
322
273
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
274
|
+
if (!sendMore) {
|
|
275
|
+
await waitForBackpressure(this.stream)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
327
278
|
|
|
328
|
-
|
|
329
|
-
|
|
279
|
+
// close writable end
|
|
280
|
+
this.stream.end()
|
|
281
|
+
} catch (err: any) {
|
|
282
|
+
this.stream.destroy(err)
|
|
283
|
+
throw err
|
|
284
|
+
}
|
|
330
285
|
}
|
|
286
|
+
}
|
|
331
287
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
for (const buf of data) {
|
|
337
|
-
sentBytes += buf.byteLength
|
|
338
|
-
canSendMore = this.socket.write(buf)
|
|
288
|
+
export function streamToIt (stream: DuplexStream): Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
|
|
289
|
+
return new DuplexIterable(stream)
|
|
290
|
+
}
|
|
339
291
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
292
|
+
async function waitForBackpressure (stream: DuplexStream): Promise<void> {
|
|
293
|
+
await new Promise<void>((resolve, reject) => {
|
|
294
|
+
const continueListener = (): void => {
|
|
295
|
+
cleanUp()
|
|
296
|
+
resolve()
|
|
297
|
+
}
|
|
298
|
+
const stopListener = (err?: Error): void => {
|
|
299
|
+
cleanUp()
|
|
300
|
+
reject(err ?? new Error('Stream ended'))
|
|
343
301
|
}
|
|
344
302
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
303
|
+
const cleanUp = (): void => {
|
|
304
|
+
stream.removeListener('drain', continueListener)
|
|
305
|
+
stream.removeListener('end', stopListener)
|
|
306
|
+
stream.removeListener('error', stopListener)
|
|
348
307
|
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
308
|
|
|
352
|
-
|
|
353
|
-
|
|
309
|
+
stream.addListener('drain', continueListener)
|
|
310
|
+
stream.addListener('end', stopListener)
|
|
311
|
+
stream.addListener('error', stopListener)
|
|
312
|
+
})
|
|
354
313
|
}
|