@libp2p/tls 2.2.7 → 3.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/dist/src/tls.browser.d.ts +3 -5
- 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 +21 -27
- package/dist/src/tls.js.map +1 -1
- package/dist/src/utils.d.ts +5 -6
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +121 -91
- package/dist/src/utils.js.map +1 -1
- package/package.json +14 -15
- package/src/tls.browser.ts +3 -5
- package/src/tls.ts +25 -35
- package/src/utils.ts +135 -94
- package/dist/typedoc-urls.json +0 -8
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { serviceCapabilities } from '@libp2p/interface';
|
|
2
|
-
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions } from '@libp2p/interface';
|
|
3
|
-
import type { Duplex } from 'it-stream-types';
|
|
4
|
-
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
2
|
+
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions, MessageStream } from '@libp2p/interface';
|
|
5
3
|
export declare class TLS implements ConnectionEncrypter {
|
|
6
4
|
protocol: string;
|
|
7
5
|
constructor();
|
|
8
6
|
readonly [Symbol.toStringTag] = "@libp2p/tls";
|
|
9
7
|
readonly [serviceCapabilities]: string[];
|
|
10
|
-
secureInbound<Stream extends
|
|
11
|
-
secureOutbound<Stream extends
|
|
8
|
+
secureInbound<Stream extends MessageStream = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>>;
|
|
9
|
+
secureOutbound<Stream extends MessageStream = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>>;
|
|
12
10
|
}
|
|
13
11
|
//# 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,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAE5I,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,aAAa,GAAG,mBAAmB,EAAG,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAIxJ,cAAc,CAAE,MAAM,SAAS,aAAa,GAAG,mBAAmB,EAAG,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAGhK"}
|
|
@@ -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;AAGrC,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,CAAuD,IAAY,EAAE,OAAiC;QACvH,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC/D,CAAC;IAED,KAAK,CAAC,cAAc,CAAuD,IAAY,EAAE,OAAiC;QACxH,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 {
|
|
22
|
+
import type { ConnectionEncrypter, SecuredConnection, SecureConnectionOptions, MessageStream } 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(connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection>;
|
|
32
|
+
secureOutbound(connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection>;
|
|
33
33
|
/**
|
|
34
34
|
* Encrypt connection
|
|
35
35
|
*/
|
|
36
|
-
_encrypt
|
|
36
|
+
_encrypt(connection: MessageStream, isServer: boolean, options?: SecureConnectionOptions): Promise<SecuredConnection>;
|
|
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,
|
|
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,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjK,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,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIxG,cAAc,CAAE,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI/G;;OAEG;IACG,QAAQ,CAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAuJ7H"}
|
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, toNodeDuplex, toMessageStream } 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(connection, options) {
|
|
61
|
+
return this._encrypt(connection, true, options);
|
|
62
62
|
}
|
|
63
|
-
async secureOutbound(
|
|
64
|
-
return this._encrypt(
|
|
63
|
+
async secureOutbound(connection, options) {
|
|
64
|
+
return this._encrypt(connection, false, options);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Encrypt connection
|
|
68
68
|
*/
|
|
69
|
-
async _encrypt(
|
|
70
|
-
const log =
|
|
69
|
+
async _encrypt(connection, isServer, options) {
|
|
70
|
+
const log = connection.log?.newScope('tls') ?? this.log;
|
|
71
71
|
let streamMuxer;
|
|
72
72
|
let streamMuxers = [];
|
|
73
73
|
if (options?.skipStreamMuxerNegotiation !== true) {
|
|
@@ -102,9 +102,10 @@ export class TLS {
|
|
|
102
102
|
return chosenProtocol;
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
+
const duplex = toNodeDuplex(connection);
|
|
105
106
|
let socket;
|
|
106
107
|
if (isServer) {
|
|
107
|
-
socket = new TLSSocket(
|
|
108
|
+
socket = new TLSSocket(duplex, {
|
|
108
109
|
...opts,
|
|
109
110
|
// require clients to send certificates
|
|
110
111
|
requestCert: true
|
|
@@ -112,10 +113,13 @@ export class TLS {
|
|
|
112
113
|
}
|
|
113
114
|
else {
|
|
114
115
|
socket = connect({
|
|
115
|
-
socket:
|
|
116
|
+
socket: duplex,
|
|
116
117
|
...opts
|
|
117
118
|
});
|
|
118
119
|
}
|
|
120
|
+
duplex.on('error', (err) => {
|
|
121
|
+
socket.emit('error', err);
|
|
122
|
+
});
|
|
119
123
|
const onAbort = () => {
|
|
120
124
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
121
125
|
abort: true
|
|
@@ -129,7 +133,7 @@ export class TLS {
|
|
|
129
133
|
return new Promise((resolve, reject) => {
|
|
130
134
|
const verifyRemote = () => {
|
|
131
135
|
const remote = socket.getPeerCertificate();
|
|
132
|
-
verifyPeerCertificate(remote.raw, options?.remotePeer,
|
|
136
|
+
verifyPeerCertificate(remote.raw, options?.remotePeer, log)
|
|
133
137
|
.then(remotePeer => {
|
|
134
138
|
log('remote certificate ok, remote peer %p', remotePeer);
|
|
135
139
|
// 'libp2p' is a special protocol - if it's sent the remote does not
|
|
@@ -140,18 +144,13 @@ export class TLS {
|
|
|
140
144
|
if (streamMuxer == null) {
|
|
141
145
|
const err = new InvalidCryptoExchangeError(`Selected muxer ${socket.alpnProtocol} did not exist`);
|
|
142
146
|
log.error(`Selected muxer ${socket.alpnProtocol} did not exist - %e`, err);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
reject(err);
|
|
146
|
-
}
|
|
147
|
+
connection.abort(err);
|
|
148
|
+
reject(err);
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
resolve({
|
|
150
152
|
remotePeer,
|
|
151
|
-
|
|
152
|
-
...conn,
|
|
153
|
-
...streamToIt(socket)
|
|
154
|
-
},
|
|
153
|
+
connection: toMessageStream(connection, socket),
|
|
155
154
|
streamMuxer
|
|
156
155
|
});
|
|
157
156
|
})
|
|
@@ -163,20 +162,18 @@ export class TLS {
|
|
|
163
162
|
});
|
|
164
163
|
};
|
|
165
164
|
socket.on('error', (err) => {
|
|
166
|
-
|
|
165
|
+
log.error('error encrypting %s connection - %e', connection.direction, err);
|
|
167
166
|
if (err.name !== 'HandshakeTimeoutError') {
|
|
168
167
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
169
168
|
error: true
|
|
170
169
|
});
|
|
171
170
|
}
|
|
172
|
-
socket.destroy(
|
|
173
|
-
|
|
174
|
-
conn.abort(err);
|
|
175
|
-
}
|
|
171
|
+
socket.destroy();
|
|
172
|
+
connection.abort(err);
|
|
176
173
|
reject(err);
|
|
177
174
|
});
|
|
178
175
|
socket.once('secure', () => {
|
|
179
|
-
|
|
176
|
+
log('verifying remote certificate of %s connection', connection.direction);
|
|
180
177
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
181
178
|
secure: true
|
|
182
179
|
});
|
|
@@ -198,7 +195,4 @@ export class TLS {
|
|
|
198
195
|
});
|
|
199
196
|
}
|
|
200
197
|
}
|
|
201
|
-
function isAbortable(obj) {
|
|
202
|
-
return typeof obj?.abort === 'function';
|
|
203
|
-
}
|
|
204
198
|
//# 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;;;;;;;;;;;;;;;;;;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|
-
import { Duplex
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
1
|
+
import { Duplex } from 'node:stream';
|
|
2
|
+
import tls from 'node:tls';
|
|
3
|
+
import type { PeerId, Logger, PrivateKey, AbortOptions, MessageStream } from '@libp2p/interface';
|
|
5
4
|
export declare function verifyPeerCertificate(rawCertificate: Uint8Array, expectedPeerId?: PeerId, log?: Logger): Promise<PeerId>;
|
|
6
5
|
export declare function generateCertificate(privateKey: PrivateKey, options?: AbortOptions): Promise<{
|
|
7
6
|
cert: string;
|
|
@@ -11,6 +10,6 @@ export declare function generateCertificate(privateKey: PrivateKey, options?: Ab
|
|
|
11
10
|
* @see https://github.com/libp2p/specs/blob/master/tls/tls.md#libp2p-public-key-extension
|
|
12
11
|
*/
|
|
13
12
|
export declare function encodeSignatureData(certPublicKey: ArrayBuffer): Uint8Array;
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function
|
|
13
|
+
export declare function toNodeDuplex(stream: MessageStream): Duplex;
|
|
14
|
+
export declare function toMessageStream(stream: MessageStream, socket: tls.TLSSocket): MessageStream;
|
|
16
15
|
//# 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":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,GAAG,MAAM,UAAU,CAAA;AAiB1B,OAAO,KAAK,EAAE,MAAM,EAAgC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAoB,MAAM,mBAAmB,CAAA;AAchJ,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,YAAY,CAAE,MAAM,EAAE,aAAa,GAAG,MAAM,CAqE3D;AAuFD,wBAAgB,eAAe,CAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,CAAC,SAAS,GAAG,aAAa,CAE5F"}
|
package/dist/src/utils.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
import { Duplex } from 'node:stream';
|
|
3
|
+
import tls from 'node:tls';
|
|
2
4
|
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys';
|
|
3
|
-
import { InvalidCryptoExchangeError, UnexpectedPeerError } from '@libp2p/interface';
|
|
5
|
+
import { InvalidCryptoExchangeError, UnexpectedPeerError, StreamMessageEvent } from '@libp2p/interface';
|
|
4
6
|
import { peerIdFromCID } from '@libp2p/peer-id';
|
|
7
|
+
import { AbstractMessageStream } from '@libp2p/utils';
|
|
5
8
|
import { AsnConvert } from '@peculiar/asn1-schema';
|
|
6
9
|
import * as asn1X509 from '@peculiar/asn1-x509';
|
|
7
10
|
import { Crypto } from '@peculiar/webcrypto';
|
|
8
11
|
import * as x509 from '@peculiar/x509';
|
|
9
12
|
import * as asn1js from 'asn1js';
|
|
10
|
-
import {
|
|
13
|
+
import { pEvent } from 'p-event';
|
|
14
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
11
15
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
12
16
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
13
17
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
@@ -62,7 +66,7 @@ export async function verifyPeerCertificate(rawCertificate, expectedPeerId, log)
|
|
|
62
66
|
}
|
|
63
67
|
const remotePeerId = peerIdFromCID(remoteLibp2pPublicKey.toCID());
|
|
64
68
|
if (expectedPeerId?.equals(remotePeerId) === false) {
|
|
65
|
-
log?.error('invalid peer id');
|
|
69
|
+
log?.error('invalid peer id - expected %p got %p', expectedPeerId, remotePeerId);
|
|
66
70
|
throw new UnexpectedPeerError();
|
|
67
71
|
}
|
|
68
72
|
return remotePeerId;
|
|
@@ -150,112 +154,138 @@ function formatAsPem(str) {
|
|
|
150
154
|
finalString = finalString + '-----END PRIVATE KEY-----';
|
|
151
155
|
return finalString;
|
|
152
156
|
}
|
|
153
|
-
export function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
export function toNodeDuplex(stream) {
|
|
158
|
+
function sendAndCallback(chunk, callback) {
|
|
159
|
+
try {
|
|
160
|
+
const sendMore = stream.send(chunk);
|
|
161
|
+
if (sendMore) {
|
|
162
|
+
callback();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
socket.pause();
|
|
166
|
+
pEvent(stream, 'drain', {
|
|
167
|
+
rejectionEvents: ['close']
|
|
168
|
+
})
|
|
161
169
|
.then(() => {
|
|
170
|
+
socket.resume();
|
|
162
171
|
callback();
|
|
163
|
-
}, err => {
|
|
172
|
+
}, (err) => {
|
|
164
173
|
callback(err);
|
|
165
174
|
});
|
|
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);
|
|
166
188
|
},
|
|
167
189
|
read() {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
else {
|
|
174
|
-
this.push(result.value);
|
|
175
|
-
}
|
|
176
|
-
}, (err) => {
|
|
177
|
-
this.destroy(err);
|
|
178
|
-
});
|
|
190
|
+
stream.resume();
|
|
191
|
+
},
|
|
192
|
+
final(cb) {
|
|
193
|
+
stream.close()
|
|
194
|
+
.then(() => cb(), (err) => cb(err));
|
|
179
195
|
}
|
|
180
196
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
this.source = queuelessPushable();
|
|
194
|
-
stream.addListener('data', (buf) => {
|
|
197
|
+
const onMessage = (evt) => {
|
|
198
|
+
const buf = evt.data;
|
|
199
|
+
let sendMore = true;
|
|
200
|
+
if (buf instanceof Uint8Array) {
|
|
201
|
+
sendMore = socket.push(buf);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
for (const chunk of buf) {
|
|
205
|
+
sendMore = socket.push(chunk);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (!sendMore) {
|
|
195
209
|
stream.pause();
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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;
|
|
218
|
+
}
|
|
219
|
+
class EncryptedMultiaddrConnection extends AbstractMessageStream {
|
|
220
|
+
socket;
|
|
221
|
+
/**
|
|
222
|
+
* @param stream - The maConn that encrypted data is transferred over
|
|
223
|
+
* @param socket - Performs encryption/decryption
|
|
224
|
+
*/
|
|
225
|
+
constructor(stream, socket) {
|
|
226
|
+
super({
|
|
227
|
+
log: stream.log,
|
|
228
|
+
inactivityTimeout: stream.inactivityTimeout,
|
|
229
|
+
maxReadBufferLength: stream.maxReadBufferLength,
|
|
230
|
+
direction: stream.direction
|
|
231
|
+
});
|
|
232
|
+
this.socket = socket;
|
|
233
|
+
// accept decrypted data
|
|
234
|
+
this.socket.on('data', (buf) => {
|
|
235
|
+
this.onData(buf);
|
|
202
236
|
});
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
237
|
+
this.socket.on('error', err => {
|
|
238
|
+
stream.abort(err);
|
|
239
|
+
});
|
|
240
|
+
this.socket.on('close', () => {
|
|
241
|
+
stream.close()
|
|
206
242
|
.catch(err => {
|
|
207
|
-
stream.
|
|
243
|
+
stream.abort(err);
|
|
208
244
|
});
|
|
209
245
|
});
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
246
|
+
// can accept more plaintext data
|
|
247
|
+
this.socket.on('drain', () => {
|
|
248
|
+
this.safeDispatchEvent('drain');
|
|
213
249
|
});
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.
|
|
217
|
-
.catch(() => { });
|
|
250
|
+
stream.addEventListener('close', () => {
|
|
251
|
+
socket.destroy();
|
|
252
|
+
this.onTransportClosed();
|
|
218
253
|
});
|
|
219
|
-
this.sink = this.sink.bind(this);
|
|
220
254
|
}
|
|
221
|
-
async
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
255
|
+
async close(options) {
|
|
256
|
+
this.socket.destroySoon();
|
|
257
|
+
await pEvent(this.socket, 'close', options);
|
|
258
|
+
}
|
|
259
|
+
sendPause() {
|
|
260
|
+
this.socket.pause();
|
|
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;
|
|
228
280
|
}
|
|
229
|
-
// close writable end
|
|
230
|
-
this.stream.end();
|
|
231
|
-
}
|
|
232
|
-
catch (err) {
|
|
233
|
-
this.stream.destroy(err);
|
|
234
|
-
throw err;
|
|
235
281
|
}
|
|
282
|
+
return {
|
|
283
|
+
sentBytes,
|
|
284
|
+
canSendMore
|
|
285
|
+
};
|
|
236
286
|
}
|
|
237
287
|
}
|
|
238
|
-
export function
|
|
239
|
-
return new
|
|
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
|
-
});
|
|
288
|
+
export function toMessageStream(stream, socket) {
|
|
289
|
+
return new EncryptedMultiaddrConnection(stream, socket);
|
|
260
290
|
}
|
|
261
291
|
//# 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,GAAG,MAAM,UAAU,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,GAAG,MAAM,UAAU,CAAA;AAC1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACvG,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,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,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EA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AC,WAAW,EAAE,CAAA;QACzB,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;IACnC,CAAC;IAED,SAAS;QACP,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAA;IAC/B,CAAC;IAED,QAAQ,CAAE,IAAoB;QAC5B,IAAI,SAAS,GAAG,CAAC,CAAA;QACjB,IAAI,WAAW,GAAG,IAAI,CAAA;QAEtB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,SAAS,IAAI,GAAG,CAAC,UAAU,CAAA;YAC3B,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAEpC,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAK;YACP,CAAC;QACH,CAAC;QAED,OAAO;YACL,SAAS;YACT,WAAW;SACZ,CAAA;IACH,CAAC;CACF;AAED,MAAM,UAAU,eAAe,CAAE,MAAqB,EAAE,MAAqB;IAC3E,OAAO,IAAI,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tls",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-049bfa0fa",
|
|
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,26 +41,25 @@
|
|
|
41
41
|
"doc-check": "aegir doc-check"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@libp2p/crypto": "
|
|
45
|
-
"@libp2p/interface": "
|
|
46
|
-
"@libp2p/peer-id": "
|
|
47
|
-
"@
|
|
48
|
-
"@peculiar/asn1-
|
|
44
|
+
"@libp2p/crypto": "5.1.9-049bfa0fa",
|
|
45
|
+
"@libp2p/interface": "3.0.0-049bfa0fa",
|
|
46
|
+
"@libp2p/peer-id": "6.0.0-049bfa0fa",
|
|
47
|
+
"@libp2p/utils": "7.0.0-049bfa0fa",
|
|
48
|
+
"@peculiar/asn1-schema": "^2.4.0",
|
|
49
|
+
"@peculiar/asn1-x509": "^2.4.0",
|
|
49
50
|
"@peculiar/webcrypto": "^1.5.0",
|
|
50
|
-
"@peculiar/x509": "^1.
|
|
51
|
+
"@peculiar/x509": "^1.13.0",
|
|
51
52
|
"asn1js": "^3.0.6",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"protons-runtime": "^5.5.0",
|
|
53
|
+
"p-event": "^6.0.1",
|
|
54
|
+
"protons-runtime": "^5.6.0",
|
|
55
55
|
"uint8arraylist": "^2.4.8",
|
|
56
56
|
"uint8arrays": "^5.1.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@libp2p/logger": "
|
|
60
|
-
"aegir": "^47.0.
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"sinon": "^20.0.0",
|
|
59
|
+
"@libp2p/logger": "6.0.0-049bfa0fa",
|
|
60
|
+
"aegir": "^47.0.22",
|
|
61
|
+
"protons": "^7.7.0",
|
|
62
|
+
"sinon": "^21.0.0",
|
|
64
63
|
"sinon-ts": "^2.0.0"
|
|
65
64
|
},
|
|
66
65
|
"browser": {
|
package/src/tls.browser.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { serviceCapabilities } from '@libp2p/interface'
|
|
2
2
|
import { PROTOCOL } from './index.js'
|
|
3
|
-
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions } from '@libp2p/interface'
|
|
4
|
-
import type { Duplex } from 'it-stream-types'
|
|
5
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
3
|
+
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions, MessageStream } from '@libp2p/interface'
|
|
6
4
|
|
|
7
5
|
export class TLS implements ConnectionEncrypter {
|
|
8
6
|
public protocol: string = PROTOCOL
|
|
@@ -17,11 +15,11 @@ export class TLS implements ConnectionEncrypter {
|
|
|
17
15
|
'@libp2p/connection-encryption'
|
|
18
16
|
]
|
|
19
17
|
|
|
20
|
-
async secureInbound <Stream extends
|
|
18
|
+
async secureInbound <Stream extends MessageStream = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
21
19
|
throw new Error('TLS encryption is not possible in browsers')
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
async secureOutbound <Stream extends
|
|
22
|
+
async secureOutbound <Stream extends MessageStream = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
25
23
|
throw new Error('TLS encryption is not possible in browsers')
|
|
26
24
|
}
|
|
27
25
|
}
|
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, toNodeDuplex, toMessageStream } from './utils.js'
|
|
25
25
|
import { PROTOCOL } from './index.js'
|
|
26
26
|
import type { TLSComponents } from './index.js'
|
|
27
|
-
import type {
|
|
27
|
+
import type { ConnectionEncrypter, SecuredConnection, Logger, SecureConnectionOptions, CounterGroup, StreamMuxerFactory, MessageStream } 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 (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
79
|
+
return this._encrypt(connection, true, options)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
async secureOutbound
|
|
83
|
-
return this._encrypt(
|
|
82
|
+
async secureOutbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
83
|
+
return this._encrypt(connection, false, options)
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* Encrypt connection
|
|
88
88
|
*/
|
|
89
|
-
async _encrypt
|
|
90
|
-
const log =
|
|
89
|
+
async _encrypt (connection: MessageStream, isServer: boolean, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
90
|
+
const log = connection.log?.newScope('tls') ?? this.log
|
|
91
91
|
let streamMuxer: StreamMuxerFactory | undefined
|
|
92
92
|
|
|
93
93
|
let streamMuxers: string[] = []
|
|
@@ -131,21 +131,26 @@ export class TLS implements ConnectionEncrypter {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
const duplex = toNodeDuplex(connection)
|
|
134
135
|
let socket: TLSSocket
|
|
135
136
|
|
|
136
137
|
if (isServer) {
|
|
137
|
-
socket = new TLSSocket(
|
|
138
|
+
socket = new TLSSocket(duplex, {
|
|
138
139
|
...opts,
|
|
139
140
|
// require clients to send certificates
|
|
140
141
|
requestCert: true
|
|
141
142
|
})
|
|
142
143
|
} else {
|
|
143
144
|
socket = connect({
|
|
144
|
-
socket:
|
|
145
|
+
socket: duplex,
|
|
145
146
|
...opts
|
|
146
147
|
})
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
duplex.on('error', (err) => {
|
|
151
|
+
socket.emit('error', err)
|
|
152
|
+
})
|
|
153
|
+
|
|
149
154
|
const onAbort = (): void => {
|
|
150
155
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
151
156
|
abort: true
|
|
@@ -158,11 +163,11 @@ export class TLS implements ConnectionEncrypter {
|
|
|
158
163
|
|
|
159
164
|
options?.signal?.addEventListener('abort', onAbort)
|
|
160
165
|
|
|
161
|
-
return new Promise<SecuredConnection<
|
|
166
|
+
return new Promise<SecuredConnection<MessageStream>>((resolve, reject) => {
|
|
162
167
|
const verifyRemote = (): void => {
|
|
163
168
|
const remote = socket.getPeerCertificate()
|
|
164
169
|
|
|
165
|
-
verifyPeerCertificate(remote.raw, options?.remotePeer,
|
|
170
|
+
verifyPeerCertificate(remote.raw, options?.remotePeer, log)
|
|
166
171
|
.then(remotePeer => {
|
|
167
172
|
log('remote certificate ok, remote peer %p', remotePeer)
|
|
168
173
|
|
|
@@ -176,19 +181,14 @@ export class TLS implements ConnectionEncrypter {
|
|
|
176
181
|
const err = new InvalidCryptoExchangeError(`Selected muxer ${socket.alpnProtocol} did not exist`)
|
|
177
182
|
log.error(`Selected muxer ${socket.alpnProtocol} did not exist - %e`, err)
|
|
178
183
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
reject(err)
|
|
182
|
-
}
|
|
184
|
+
connection.abort(err)
|
|
185
|
+
reject(err)
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
resolve({
|
|
187
190
|
remotePeer,
|
|
188
|
-
|
|
189
|
-
...conn,
|
|
190
|
-
...streamToIt(socket)
|
|
191
|
-
},
|
|
191
|
+
connection: toMessageStream(connection, socket),
|
|
192
192
|
streamMuxer
|
|
193
193
|
})
|
|
194
194
|
})
|
|
@@ -196,12 +196,13 @@ export class TLS implements ConnectionEncrypter {
|
|
|
196
196
|
this.metrics[isServer ? 'server' : 'client'].errors?.increment({
|
|
197
197
|
verify_peer_certificate: true
|
|
198
198
|
})
|
|
199
|
+
|
|
199
200
|
socket.emit('error', err)
|
|
200
201
|
})
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
socket.on('error', (err: Error) => {
|
|
204
|
-
|
|
205
|
+
log.error('error encrypting %s connection - %e', connection.direction, err)
|
|
205
206
|
|
|
206
207
|
if (err.name !== 'HandshakeTimeoutError') {
|
|
207
208
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
@@ -209,16 +210,13 @@ export class TLS implements ConnectionEncrypter {
|
|
|
209
210
|
})
|
|
210
211
|
}
|
|
211
212
|
|
|
212
|
-
socket.destroy(
|
|
213
|
-
|
|
214
|
-
if (isAbortable(conn)) {
|
|
215
|
-
conn.abort(err)
|
|
216
|
-
}
|
|
213
|
+
socket.destroy()
|
|
214
|
+
connection.abort(err)
|
|
217
215
|
|
|
218
216
|
reject(err)
|
|
219
217
|
})
|
|
220
218
|
socket.once('secure', () => {
|
|
221
|
-
|
|
219
|
+
log('verifying remote certificate of %s connection', connection.direction)
|
|
222
220
|
this.metrics[isServer ? 'server' : 'client'].events?.increment({
|
|
223
221
|
secure: true
|
|
224
222
|
})
|
|
@@ -240,11 +238,3 @@ export class TLS implements ConnectionEncrypter {
|
|
|
240
238
|
})
|
|
241
239
|
}
|
|
242
240
|
}
|
|
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,22 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import net from 'node:net'
|
|
2
|
+
import { Duplex } from 'node:stream'
|
|
3
|
+
import tls from 'node:tls'
|
|
2
4
|
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'
|
|
3
|
-
import { InvalidCryptoExchangeError, UnexpectedPeerError } from '@libp2p/interface'
|
|
5
|
+
import { InvalidCryptoExchangeError, UnexpectedPeerError, StreamMessageEvent } from '@libp2p/interface'
|
|
4
6
|
import { peerIdFromCID } from '@libp2p/peer-id'
|
|
7
|
+
import { AbstractMessageStream } from '@libp2p/utils'
|
|
5
8
|
import { AsnConvert } from '@peculiar/asn1-schema'
|
|
6
9
|
import * as asn1X509 from '@peculiar/asn1-x509'
|
|
7
10
|
import { Crypto } from '@peculiar/webcrypto'
|
|
8
11
|
import * as x509 from '@peculiar/x509'
|
|
9
12
|
import * as asn1js from 'asn1js'
|
|
10
|
-
import {
|
|
13
|
+
import { pEvent } from 'p-event'
|
|
14
|
+
import { Uint8ArrayList } from 'uint8arraylist'
|
|
11
15
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
12
16
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
13
17
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
14
18
|
import { InvalidCertificateError } from './errors.js'
|
|
15
19
|
import { KeyType, PublicKey } from './pb/index.js'
|
|
16
|
-
import type { PeerId, PublicKey as Libp2pPublicKey, Logger, PrivateKey, AbortOptions } from '@libp2p/interface'
|
|
17
|
-
import type {
|
|
18
|
-
import type { Duplex, Source } from 'it-stream-types'
|
|
19
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
20
|
+
import type { PeerId, PublicKey as Libp2pPublicKey, Logger, PrivateKey, AbortOptions, MessageStream, StreamCloseEvent } from '@libp2p/interface'
|
|
21
|
+
import type { SendResult } from '@libp2p/utils'
|
|
20
22
|
|
|
21
23
|
const crypto = new Crypto()
|
|
22
24
|
x509.cryptoProvider.set(crypto)
|
|
@@ -84,7 +86,7 @@ export async function verifyPeerCertificate (rawCertificate: Uint8Array, expecte
|
|
|
84
86
|
const remotePeerId = peerIdFromCID(remoteLibp2pPublicKey.toCID())
|
|
85
87
|
|
|
86
88
|
if (expectedPeerId?.equals(remotePeerId) === false) {
|
|
87
|
-
log?.error('invalid peer id')
|
|
89
|
+
log?.error('invalid peer id - expected %p got %p', expectedPeerId, remotePeerId)
|
|
88
90
|
throw new UnexpectedPeerError()
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -191,123 +193,162 @@ function formatAsPem (str: string): string {
|
|
|
191
193
|
return finalString
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
export function
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
export function toNodeDuplex (stream: MessageStream): Duplex {
|
|
197
|
+
function sendAndCallback (chunk: Uint8Array | Uint8ArrayList, callback: (err?: Error | null) => void): void {
|
|
198
|
+
try {
|
|
199
|
+
const sendMore = stream.send(chunk)
|
|
197
200
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
if (sendMore) {
|
|
202
|
+
callback()
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
socket.pause()
|
|
207
|
+
|
|
208
|
+
pEvent(stream, 'drain', {
|
|
209
|
+
rejectionEvents: ['close']
|
|
210
|
+
})
|
|
203
211
|
.then(() => {
|
|
212
|
+
socket.resume()
|
|
204
213
|
callback()
|
|
205
|
-
}, err => {
|
|
214
|
+
}, (err) => {
|
|
206
215
|
callback(err)
|
|
207
216
|
})
|
|
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)
|
|
208
231
|
},
|
|
209
232
|
read () {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
this.push(result.value)
|
|
216
|
-
}
|
|
217
|
-
}, (err) => {
|
|
218
|
-
this.destroy(err)
|
|
219
|
-
})
|
|
233
|
+
stream.resume()
|
|
234
|
+
},
|
|
235
|
+
final (cb) {
|
|
236
|
+
stream.close()
|
|
237
|
+
.then(() => cb(), (err) => cb(err))
|
|
220
238
|
}
|
|
221
239
|
})
|
|
222
240
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
241
|
+
const onMessage = (evt: StreamMessageEvent): void => {
|
|
242
|
+
const buf = evt.data
|
|
243
|
+
let sendMore = true
|
|
244
|
+
|
|
245
|
+
if (buf instanceof Uint8Array) {
|
|
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)
|
|
228
263
|
|
|
229
|
-
return
|
|
264
|
+
return socket
|
|
230
265
|
}
|
|
231
266
|
|
|
232
|
-
class
|
|
233
|
-
|
|
234
|
-
|
|
267
|
+
class EncryptedMultiaddrConnection extends AbstractMessageStream {
|
|
268
|
+
private socket: net.Socket
|
|
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
|
+
})
|
|
235
281
|
|
|
236
|
-
|
|
237
|
-
this.stream = stream
|
|
238
|
-
this.source = queuelessPushable<Uint8Array>()
|
|
282
|
+
this.socket = socket
|
|
239
283
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
this.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
stream.emit('error', err)
|
|
247
|
-
})
|
|
284
|
+
// accept decrypted data
|
|
285
|
+
this.socket.on('data', (buf) => {
|
|
286
|
+
this.onData(buf)
|
|
287
|
+
})
|
|
288
|
+
this.socket.on('error', err => {
|
|
289
|
+
stream.abort(err)
|
|
248
290
|
})
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
this.source.end()
|
|
291
|
+
this.socket.on('close', () => {
|
|
292
|
+
stream.close()
|
|
252
293
|
.catch(err => {
|
|
253
|
-
stream.
|
|
294
|
+
stream.abort(err)
|
|
254
295
|
})
|
|
255
296
|
})
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
297
|
+
|
|
298
|
+
// can accept more plaintext data
|
|
299
|
+
this.socket.on('drain', () => {
|
|
300
|
+
this.safeDispatchEvent('drain')
|
|
259
301
|
})
|
|
260
|
-
|
|
261
|
-
stream.
|
|
262
|
-
|
|
263
|
-
|
|
302
|
+
|
|
303
|
+
stream.addEventListener('close', () => {
|
|
304
|
+
socket.destroy()
|
|
305
|
+
this.onTransportClosed()
|
|
264
306
|
})
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async close (options?: AbortOptions): Promise<void> {
|
|
310
|
+
this.socket.destroySoon()
|
|
265
311
|
|
|
266
|
-
this.
|
|
312
|
+
await pEvent(this.socket, 'close', options)
|
|
267
313
|
}
|
|
268
314
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const sendMore = this.stream.write(buf.subarray())
|
|
315
|
+
sendPause (): void {
|
|
316
|
+
this.socket.pause()
|
|
317
|
+
}
|
|
273
318
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
319
|
+
sendResume (): void {
|
|
320
|
+
this.socket.resume()
|
|
321
|
+
}
|
|
278
322
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
this.stream.destroy(err)
|
|
283
|
-
throw err
|
|
284
|
-
}
|
|
323
|
+
async sendClose (options?: AbortOptions): Promise<void> {
|
|
324
|
+
this.socket.destroySoon()
|
|
325
|
+
options?.signal?.throwIfAborted()
|
|
285
326
|
}
|
|
286
|
-
}
|
|
287
327
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
328
|
+
sendReset (): void {
|
|
329
|
+
this.socket.resetAndDestroy()
|
|
330
|
+
}
|
|
291
331
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
332
|
+
sendData (data: Uint8ArrayList): SendResult {
|
|
333
|
+
let sentBytes = 0
|
|
334
|
+
let canSendMore = true
|
|
335
|
+
|
|
336
|
+
for (const buf of data) {
|
|
337
|
+
sentBytes += buf.byteLength
|
|
338
|
+
canSendMore = this.socket.write(buf)
|
|
339
|
+
|
|
340
|
+
if (!canSendMore) {
|
|
341
|
+
break
|
|
342
|
+
}
|
|
301
343
|
}
|
|
302
344
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
stream.removeListener('error', stopListener)
|
|
345
|
+
return {
|
|
346
|
+
sentBytes,
|
|
347
|
+
canSendMore
|
|
307
348
|
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
308
351
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
stream.addListener('error', stopListener)
|
|
312
|
-
})
|
|
352
|
+
export function toMessageStream (stream: MessageStream, socket: tls.TLSSocket): MessageStream {
|
|
353
|
+
return new EncryptedMultiaddrConnection(stream, socket)
|
|
313
354
|
}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"TLSComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tls.TLSComponents.html",
|
|
3
|
-
".:TLSComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tls.TLSComponents.html",
|
|
4
|
-
"PROTOCOL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_tls.PROTOCOL.html",
|
|
5
|
-
".:PROTOCOL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_tls.PROTOCOL.html",
|
|
6
|
-
"tls": "https://libp2p.github.io/js-libp2p/functions/_libp2p_tls.tls.html",
|
|
7
|
-
".:tls": "https://libp2p.github.io/js-libp2p/functions/_libp2p_tls.tls.html"
|
|
8
|
-
}
|