@libp2p/tls 2.2.6-cfe2be4c9 → 2.2.7
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.d.ts +4 -6
- package/dist/src/tls.d.ts.map +1 -1
- package/dist/src/tls.js +4 -3
- package/dist/src/tls.js.map +1 -1
- package/dist/typedoc-urls.json +8 -0
- package/package.json +5 -5
- package/src/tls.ts +8 -9
package/dist/src/tls.d.ts
CHANGED
|
@@ -19,9 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { serviceCapabilities } from '@libp2p/interface';
|
|
21
21
|
import type { TLSComponents } from './index.js';
|
|
22
|
-
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions } from '@libp2p/interface';
|
|
23
|
-
import type { Duplex } from 'it-stream-types';
|
|
24
|
-
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
22
|
+
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions, SecurableStream } from '@libp2p/interface';
|
|
25
23
|
export declare class TLS implements ConnectionEncrypter {
|
|
26
24
|
protocol: string;
|
|
27
25
|
private readonly log;
|
|
@@ -30,11 +28,11 @@ export declare class TLS implements ConnectionEncrypter {
|
|
|
30
28
|
constructor(components: TLSComponents);
|
|
31
29
|
readonly [Symbol.toStringTag] = "@libp2p/tls";
|
|
32
30
|
readonly [serviceCapabilities]: string[];
|
|
33
|
-
secureInbound<Stream extends
|
|
34
|
-
secureOutbound<Stream extends
|
|
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>>;
|
|
35
33
|
/**
|
|
36
34
|
* Encrypt connection
|
|
37
35
|
*/
|
|
38
|
-
_encrypt<Stream extends
|
|
36
|
+
_encrypt<Stream extends SecurableStream = MultiaddrConnection>(conn: Stream, isServer: boolean, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>>;
|
|
39
37
|
}
|
|
40
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,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
|
@@ -67,6 +67,7 @@ export class TLS {
|
|
|
67
67
|
* Encrypt connection
|
|
68
68
|
*/
|
|
69
69
|
async _encrypt(conn, isServer, options) {
|
|
70
|
+
const log = conn.log?.newScope('tls') ?? this.log;
|
|
70
71
|
let streamMuxer;
|
|
71
72
|
let streamMuxers = [];
|
|
72
73
|
if (options?.skipStreamMuxerNegotiation !== true) {
|
|
@@ -86,7 +87,7 @@ export class TLS {
|
|
|
86
87
|
'libp2p'
|
|
87
88
|
],
|
|
88
89
|
ALPNCallback: ({ protocols }) => {
|
|
89
|
-
|
|
90
|
+
log.trace('received protocols %s', protocols);
|
|
90
91
|
let chosenProtocol;
|
|
91
92
|
for (const protocol of protocols) {
|
|
92
93
|
if (protocol === 'libp2p') {
|
|
@@ -130,7 +131,7 @@ export class TLS {
|
|
|
130
131
|
const remote = socket.getPeerCertificate();
|
|
131
132
|
verifyPeerCertificate(remote.raw, options?.remotePeer, this.log)
|
|
132
133
|
.then(remotePeer => {
|
|
133
|
-
|
|
134
|
+
log('remote certificate ok, remote peer %p', remotePeer);
|
|
134
135
|
// 'libp2p' is a special protocol - if it's sent the remote does not
|
|
135
136
|
// support early muxer negotiation
|
|
136
137
|
if (!isServer && typeof socket.alpnProtocol === 'string' && socket.alpnProtocol !== 'libp2p' && options?.skipStreamMuxerNegotiation !== true) {
|
|
@@ -138,7 +139,7 @@ export class TLS {
|
|
|
138
139
|
streamMuxer = this.components.upgrader.getStreamMuxers().get(socket.alpnProtocol);
|
|
139
140
|
if (streamMuxer == null) {
|
|
140
141
|
const err = new InvalidCryptoExchangeError(`Selected muxer ${socket.alpnProtocol} did not exist`);
|
|
141
|
-
|
|
142
|
+
log.error(`Selected muxer ${socket.alpnProtocol} did not exist - %e`, err);
|
|
142
143
|
if (isAbortable(conn)) {
|
|
143
144
|
conn.abort(err);
|
|
144
145
|
reject(err);
|
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,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC/F,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;
|
|
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,E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EAAE,CAAC,SAAS,EAAE,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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tls",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7",
|
|
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,9 +41,9 @@
|
|
|
41
41
|
"doc-check": "aegir doc-check"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@libp2p/crypto": "5.1.
|
|
45
|
-
"@libp2p/interface": "2.
|
|
46
|
-
"@libp2p/peer-id": "5.1.
|
|
44
|
+
"@libp2p/crypto": "^5.1.8",
|
|
45
|
+
"@libp2p/interface": "^2.11.0",
|
|
46
|
+
"@libp2p/peer-id": "^5.1.9",
|
|
47
47
|
"@peculiar/asn1-schema": "^2.3.15",
|
|
48
48
|
"@peculiar/asn1-x509": "^2.3.15",
|
|
49
49
|
"@peculiar/webcrypto": "^1.5.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"uint8arrays": "^5.1.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@libp2p/logger": "5.
|
|
59
|
+
"@libp2p/logger": "^5.2.0",
|
|
60
60
|
"aegir": "^47.0.14",
|
|
61
61
|
"it-pair": "^2.0.6",
|
|
62
62
|
"protons": "^7.6.1",
|
package/src/tls.ts
CHANGED
|
@@ -24,10 +24,8 @@ import { HandshakeTimeoutError } from './errors.js'
|
|
|
24
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 { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, Logger, SecureConnectionOptions, CounterGroup, StreamMuxerFactory } from '@libp2p/interface'
|
|
28
|
-
import type { Duplex } from 'it-stream-types'
|
|
27
|
+
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, Logger, SecureConnectionOptions, CounterGroup, StreamMuxerFactory, SecurableStream } from '@libp2p/interface'
|
|
29
28
|
import type { TLSSocketOptions } from 'node:tls'
|
|
30
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
31
29
|
|
|
32
30
|
export class TLS implements ConnectionEncrypter {
|
|
33
31
|
public protocol: string = PROTOCOL
|
|
@@ -77,18 +75,19 @@ export class TLS implements ConnectionEncrypter {
|
|
|
77
75
|
'@libp2p/connection-encryption'
|
|
78
76
|
]
|
|
79
77
|
|
|
80
|
-
async secureInbound <Stream extends
|
|
78
|
+
async secureInbound <Stream extends SecurableStream = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
81
79
|
return this._encrypt(conn, true, options)
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
async secureOutbound <Stream extends
|
|
82
|
+
async secureOutbound <Stream extends SecurableStream = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
85
83
|
return this._encrypt(conn, false, options)
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
/**
|
|
89
87
|
* Encrypt connection
|
|
90
88
|
*/
|
|
91
|
-
async _encrypt <Stream extends
|
|
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
|
|
92
91
|
let streamMuxer: StreamMuxerFactory | undefined
|
|
93
92
|
|
|
94
93
|
let streamMuxers: string[] = []
|
|
@@ -112,7 +111,7 @@ export class TLS implements ConnectionEncrypter {
|
|
|
112
111
|
'libp2p'
|
|
113
112
|
],
|
|
114
113
|
ALPNCallback: ({ protocols }) => {
|
|
115
|
-
|
|
114
|
+
log.trace('received protocols %s', protocols)
|
|
116
115
|
let chosenProtocol: string | undefined
|
|
117
116
|
|
|
118
117
|
for (const protocol of protocols) {
|
|
@@ -165,7 +164,7 @@ export class TLS implements ConnectionEncrypter {
|
|
|
165
164
|
|
|
166
165
|
verifyPeerCertificate(remote.raw, options?.remotePeer, this.log)
|
|
167
166
|
.then(remotePeer => {
|
|
168
|
-
|
|
167
|
+
log('remote certificate ok, remote peer %p', remotePeer)
|
|
169
168
|
|
|
170
169
|
// 'libp2p' is a special protocol - if it's sent the remote does not
|
|
171
170
|
// support early muxer negotiation
|
|
@@ -175,7 +174,7 @@ export class TLS implements ConnectionEncrypter {
|
|
|
175
174
|
|
|
176
175
|
if (streamMuxer == null) {
|
|
177
176
|
const err = new InvalidCryptoExchangeError(`Selected muxer ${socket.alpnProtocol} did not exist`)
|
|
178
|
-
|
|
177
|
+
log.error(`Selected muxer ${socket.alpnProtocol} did not exist - %e`, err)
|
|
179
178
|
|
|
180
179
|
if (isAbortable(conn)) {
|
|
181
180
|
conn.abort(err)
|