@libp2p/interface-compliance-tests 7.0.33-5c4cdb2d6 → 7.0.33-be63a4416
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-encryption/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAU,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEhF,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,UAAU,CAAA;CACvB;yBAEe,QAAQ,SAAS,CAAC,mBAAmB,EAAE,4BAA4B,CAAC,KAAG,IAAI;AAA3F,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-encryption/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAU,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEhF,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,UAAU,CAAA;CACvB;yBAEe,QAAQ,SAAS,CAAC,mBAAmB,EAAE,4BAA4B,CAAC,KAAG,IAAI;AAA3F,wBAiMC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateKeyPair } from '@libp2p/crypto/keys';
|
|
2
|
-
import { peerIdFromPrivateKey } from '@libp2p/peer-id';
|
|
2
|
+
import { peerIdFromPrivateKey, peerIdFromString } from '@libp2p/peer-id';
|
|
3
3
|
import { multiaddrConnectionPair, echo } from '@libp2p/utils';
|
|
4
4
|
import { expect } from 'aegir/chai';
|
|
5
5
|
import all from 'it-all';
|
|
@@ -88,6 +88,70 @@ export default (common) => {
|
|
|
88
88
|
expect(err).to.have.property('name', 'UnexpectedPeerError');
|
|
89
89
|
});
|
|
90
90
|
});
|
|
91
|
+
describe('remote peer id parsed from a string', () => {
|
|
92
|
+
let rsaPeer;
|
|
93
|
+
let cryptoRsa;
|
|
94
|
+
before(async () => {
|
|
95
|
+
const rsaKey = await generateKeyPair('RSA', 512);
|
|
96
|
+
rsaPeer = peerIdFromPrivateKey(rsaKey);
|
|
97
|
+
cryptoRsa = await common.setup({
|
|
98
|
+
privateKey: rsaKey
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
async function secure(opts) {
|
|
102
|
+
const [remoteConn, localConn] = multiaddrConnectionPair();
|
|
103
|
+
try {
|
|
104
|
+
const [inboundResult, outboundResult] = await Promise.all([
|
|
105
|
+
opts.responder.secureInbound(localConn, {
|
|
106
|
+
remotePeer: opts.expectedByResponder
|
|
107
|
+
}),
|
|
108
|
+
opts.initiator.secureOutbound(remoteConn, {
|
|
109
|
+
remotePeer: opts.expectedByInitiator
|
|
110
|
+
})
|
|
111
|
+
]);
|
|
112
|
+
return { inbound: inboundResult.remotePeer, outbound: outboundResult.remotePeer };
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
localConn.abort(new Error('test finished'));
|
|
116
|
+
remoteConn.abort(new Error('test finished'));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function parse(peerId) {
|
|
120
|
+
return peerIdFromString(peerId.toString());
|
|
121
|
+
}
|
|
122
|
+
it('should match an RSA peer id on outbound connections', async () => {
|
|
123
|
+
const expected = parse(rsaPeer);
|
|
124
|
+
expect(expected.publicKey).to.be.undefined();
|
|
125
|
+
const { outbound } = await secure({ initiator: crypto, responder: cryptoRsa, expectedByInitiator: expected });
|
|
126
|
+
expect(outbound.equals(rsaPeer)).to.be.true();
|
|
127
|
+
});
|
|
128
|
+
it('should not match an RSA peer id against a different key on outbound connections', async () => {
|
|
129
|
+
const expected = parse(rsaPeer);
|
|
130
|
+
expect(expected.publicKey).to.be.undefined();
|
|
131
|
+
await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: expected })).to.eventually.be.rejected
|
|
132
|
+
.with.property('name', 'UnexpectedPeerError');
|
|
133
|
+
});
|
|
134
|
+
it('should match an RSA peer id on inbound connections', async () => {
|
|
135
|
+
const expected = parse(rsaPeer);
|
|
136
|
+
expect(expected.publicKey).to.be.undefined();
|
|
137
|
+
const { inbound } = await secure({ initiator: cryptoRsa, responder: cryptoRemote, expectedByResponder: expected });
|
|
138
|
+
expect(inbound.equals(rsaPeer)).to.be.true();
|
|
139
|
+
});
|
|
140
|
+
it('should not match an RSA peer id against a different key on inbound connections', async () => {
|
|
141
|
+
const expected = parse(rsaPeer);
|
|
142
|
+
expect(expected.publicKey).to.be.undefined();
|
|
143
|
+
await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByResponder: expected })).to.eventually.be.rejected
|
|
144
|
+
.with.property('name', 'UnexpectedPeerError');
|
|
145
|
+
});
|
|
146
|
+
it('should match an Ed25519 peer id', async () => {
|
|
147
|
+
const { outbound } = await secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: parse(remotePeer) });
|
|
148
|
+
expect(outbound.equals(remotePeer)).to.be.true();
|
|
149
|
+
});
|
|
150
|
+
it('should not match a different Ed25519 peer id', async () => {
|
|
151
|
+
await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: parse(mitmPeer) })).to.eventually.be.rejected
|
|
152
|
+
.with.property('name', 'UnexpectedPeerError');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
91
155
|
});
|
|
92
156
|
};
|
|
93
157
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection-encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection-encryption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EAAE;gBAC/C,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;gBACzH,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;YAClD,CAAC,CAAC,CAAA;YAEF,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;gBAC5D,MAAM,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ;qBACjI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAA;YACjD,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interface-compliance-tests",
|
|
3
|
-
"version": "7.0.33-
|
|
3
|
+
"version": "7.0.33-be63a4416",
|
|
4
4
|
"description": "Compliance tests for JS libp2p interfaces",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface-compliance-tests#readme",
|
|
@@ -86,15 +86,15 @@
|
|
|
86
86
|
"test:electron-main": "aegir test -t electron-main"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@libp2p/crypto": "5.1.24-
|
|
90
|
-
"@libp2p/echo": "3.1.15-
|
|
91
|
-
"@libp2p/interface": "3.3.1-
|
|
92
|
-
"@libp2p/interface-internal": "3.1.14-
|
|
93
|
-
"@libp2p/logger": "6.2.14-
|
|
94
|
-
"@libp2p/memory": "2.0.29-
|
|
95
|
-
"@libp2p/peer-id": "6.0.16-
|
|
96
|
-
"@libp2p/plaintext": "3.0.29-
|
|
97
|
-
"@libp2p/utils": "7.4.2-
|
|
89
|
+
"@libp2p/crypto": "5.1.24-be63a4416",
|
|
90
|
+
"@libp2p/echo": "3.1.15-be63a4416",
|
|
91
|
+
"@libp2p/interface": "3.3.1-be63a4416",
|
|
92
|
+
"@libp2p/interface-internal": "3.1.14-be63a4416",
|
|
93
|
+
"@libp2p/logger": "6.2.14-be63a4416",
|
|
94
|
+
"@libp2p/memory": "2.0.29-be63a4416",
|
|
95
|
+
"@libp2p/peer-id": "6.0.16-be63a4416",
|
|
96
|
+
"@libp2p/plaintext": "3.0.29-be63a4416",
|
|
97
|
+
"@libp2p/utils": "7.4.2-be63a4416",
|
|
98
98
|
"@multiformats/multiaddr": "^13.0.3",
|
|
99
99
|
"@multiformats/multiaddr-matcher": "^3.0.2",
|
|
100
100
|
"aegir": "^48.1.1",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"it-map": "^3.1.4",
|
|
105
105
|
"it-pushable": "^3.2.3",
|
|
106
106
|
"it-to-buffer": "^5.0.0",
|
|
107
|
-
"libp2p": "3.3.12-
|
|
107
|
+
"libp2p": "3.3.12-be63a4416",
|
|
108
108
|
"p-defer": "^4.0.1",
|
|
109
109
|
"p-event": "^7.0.0",
|
|
110
110
|
"p-retry": "^8.0.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateKeyPair } from '@libp2p/crypto/keys'
|
|
2
|
-
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
|
|
2
|
+
import { peerIdFromPrivateKey, peerIdFromString } from '@libp2p/peer-id'
|
|
3
3
|
import { multiaddrConnectionPair, echo } from '@libp2p/utils'
|
|
4
4
|
import { expect } from 'aegir/chai'
|
|
5
5
|
import all from 'it-all'
|
|
@@ -119,5 +119,91 @@ export default (common: TestSetup<ConnectionEncrypter, ConnectionEncrypterSetupA
|
|
|
119
119
|
expect(err).to.have.property('name', 'UnexpectedPeerError')
|
|
120
120
|
})
|
|
121
121
|
})
|
|
122
|
+
|
|
123
|
+
describe('remote peer id parsed from a string', () => {
|
|
124
|
+
let rsaPeer: PeerId
|
|
125
|
+
let cryptoRsa: ConnectionEncrypter
|
|
126
|
+
|
|
127
|
+
before(async () => {
|
|
128
|
+
const rsaKey = await generateKeyPair('RSA', 512)
|
|
129
|
+
rsaPeer = peerIdFromPrivateKey(rsaKey)
|
|
130
|
+
cryptoRsa = await common.setup({
|
|
131
|
+
privateKey: rsaKey
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
interface SecureOptions {
|
|
136
|
+
initiator: ConnectionEncrypter
|
|
137
|
+
responder: ConnectionEncrypter
|
|
138
|
+
expectedByInitiator?: PeerId
|
|
139
|
+
expectedByResponder?: PeerId
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function secure (opts: SecureOptions): Promise<{ inbound: PeerId, outbound: PeerId }> {
|
|
143
|
+
const [remoteConn, localConn] = multiaddrConnectionPair()
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
const [inboundResult, outboundResult] = await Promise.all([
|
|
147
|
+
opts.responder.secureInbound(localConn, {
|
|
148
|
+
remotePeer: opts.expectedByResponder
|
|
149
|
+
}),
|
|
150
|
+
opts.initiator.secureOutbound(remoteConn, {
|
|
151
|
+
remotePeer: opts.expectedByInitiator
|
|
152
|
+
})
|
|
153
|
+
])
|
|
154
|
+
|
|
155
|
+
return { inbound: inboundResult.remotePeer, outbound: outboundResult.remotePeer }
|
|
156
|
+
} finally {
|
|
157
|
+
localConn.abort(new Error('test finished'))
|
|
158
|
+
remoteConn.abort(new Error('test finished'))
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function parse (peerId: PeerId): PeerId {
|
|
163
|
+
return peerIdFromString(peerId.toString())
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
it('should match an RSA peer id on outbound connections', async () => {
|
|
167
|
+
const expected = parse(rsaPeer)
|
|
168
|
+
expect(expected.publicKey).to.be.undefined()
|
|
169
|
+
|
|
170
|
+
const { outbound } = await secure({ initiator: crypto, responder: cryptoRsa, expectedByInitiator: expected })
|
|
171
|
+
expect(outbound.equals(rsaPeer)).to.be.true()
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('should not match an RSA peer id against a different key on outbound connections', async () => {
|
|
175
|
+
const expected = parse(rsaPeer)
|
|
176
|
+
expect(expected.publicKey).to.be.undefined()
|
|
177
|
+
|
|
178
|
+
await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: expected })).to.eventually.be.rejected
|
|
179
|
+
.with.property('name', 'UnexpectedPeerError')
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('should match an RSA peer id on inbound connections', async () => {
|
|
183
|
+
const expected = parse(rsaPeer)
|
|
184
|
+
expect(expected.publicKey).to.be.undefined()
|
|
185
|
+
|
|
186
|
+
const { inbound } = await secure({ initiator: cryptoRsa, responder: cryptoRemote, expectedByResponder: expected })
|
|
187
|
+
expect(inbound.equals(rsaPeer)).to.be.true()
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('should not match an RSA peer id against a different key on inbound connections', async () => {
|
|
191
|
+
const expected = parse(rsaPeer)
|
|
192
|
+
expect(expected.publicKey).to.be.undefined()
|
|
193
|
+
|
|
194
|
+
await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByResponder: expected })).to.eventually.be.rejected
|
|
195
|
+
.with.property('name', 'UnexpectedPeerError')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('should match an Ed25519 peer id', async () => {
|
|
199
|
+
const { outbound } = await secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: parse(remotePeer) })
|
|
200
|
+
expect(outbound.equals(remotePeer)).to.be.true()
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it('should not match a different Ed25519 peer id', async () => {
|
|
204
|
+
await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: parse(mitmPeer) })).to.eventually.be.rejected
|
|
205
|
+
.with.property('name', 'UnexpectedPeerError')
|
|
206
|
+
})
|
|
207
|
+
})
|
|
122
208
|
})
|
|
123
209
|
}
|