mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-04-25 17:52:13 +00:00
fix(signatures): Add signature checks [fixes DXJ-488] (#357)
Add signature checks
This commit is contained in:
parent
47a610b71e
commit
a8e5eb6c1e
@ -121,17 +121,17 @@ export class RelayConnection implements IConnection {
|
|||||||
},
|
},
|
||||||
connectionGater: {
|
connectionGater: {
|
||||||
// By default, this function forbids connections to private peers. For example multiaddr with ip 127.0.0.1 isn't allowed
|
// By default, this function forbids connections to private peers. For example multiaddr with ip 127.0.0.1 isn't allowed
|
||||||
denyDialMultiaddr: () => Promise.resolve(false)
|
denyDialMultiaddr: () => Promise.resolve(false),
|
||||||
},
|
},
|
||||||
services: {
|
services: {
|
||||||
identify: identifyService(),
|
identify: identifyService(),
|
||||||
ping: pingService()
|
ping: pingService(),
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const supportedProtocols = (await this.lib2p2Peer.peerStore.get(this.lib2p2Peer.peerId)).protocols;
|
const supportedProtocols = (await this.lib2p2Peer.peerStore.get(this.lib2p2Peer.peerId)).protocols;
|
||||||
await this.lib2p2Peer.peerStore.patch(this.lib2p2Peer.peerId, {
|
await this.lib2p2Peer.peerStore.patch(this.lib2p2Peer.peerId, {
|
||||||
protocols: [...supportedProtocols, PROTOCOL_NAME]
|
protocols: [...supportedProtocols, PROTOCOL_NAME],
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.connect();
|
await this.connect();
|
||||||
@ -166,11 +166,7 @@ export class RelayConnection implements IConnection {
|
|||||||
log.trace('created stream with id ', stream.id);
|
log.trace('created stream with id ', stream.id);
|
||||||
const sink = stream.sink;
|
const sink = stream.sink;
|
||||||
|
|
||||||
await pipe(
|
await pipe([fromString(serializeToString(particle))], encode(), sink);
|
||||||
[fromString(serializeToString(particle))],
|
|
||||||
encode(),
|
|
||||||
sink,
|
|
||||||
);
|
|
||||||
log.trace('data written to sink');
|
log.trace('data written to sink');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,13 +178,19 @@ export class RelayConnection implements IConnection {
|
|||||||
const initPeerId = peerIdFromString(particle.initPeerId);
|
const initPeerId = peerIdFromString(particle.initPeerId);
|
||||||
|
|
||||||
if (initPeerId.publicKey === undefined) {
|
if (initPeerId.publicKey === undefined) {
|
||||||
log.error('cannot retrieve public key from init_peer_id. particle id: %s. init_peer_id: %s', particle.id, particle.initPeerId);
|
log.error(
|
||||||
|
'cannot retrieve public key from init_peer_id. particle id: %s. init_peer_id: %s',
|
||||||
|
particle.id,
|
||||||
|
particle.initPeerId,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: uncomment this after nox rolls out signature verification
|
const isVerified = await KeyPair.verifyWithPublicKey(
|
||||||
// const isVerified = await KeyPair.verifyWithPublicKey(initPeerId.publicKey, buildParticleMessage(particle), particle.signature);
|
initPeerId.publicKey,
|
||||||
const isVerified = true;
|
buildParticleMessage(particle),
|
||||||
|
particle.signature,
|
||||||
|
);
|
||||||
if (isVerified) {
|
if (isVerified) {
|
||||||
this.particleSource.next(particle);
|
this.particleSource.next(particle);
|
||||||
} else {
|
} else {
|
||||||
@ -208,7 +210,8 @@ export class RelayConnection implements IConnection {
|
|||||||
|
|
||||||
await this.lib2p2Peer.handle(
|
await this.lib2p2Peer.handle(
|
||||||
[PROTOCOL_NAME],
|
[PROTOCOL_NAME],
|
||||||
async ({ connection, stream }) => pipe(
|
async ({ connection, stream }) =>
|
||||||
|
pipe(
|
||||||
stream.source,
|
stream.source,
|
||||||
decode(),
|
decode(),
|
||||||
(source) => map(source, (buf) => toString(buf.subarray())),
|
(source) => map(source, (buf) => toString(buf.subarray())),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user