Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 257f92f

Browse files
committed
feat: allowJoinWithDisabledChallenge
See ipfs/js-ipfs#1095 (comment)
1 parent 188e594 commit 257f92f

File tree

9 files changed

+22
-15
lines changed

9 files changed

+22
-15
lines changed

.aegir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function boot (done) {
1414
refreshPeerListIntervalMS: 1000
1515
}, v)
1616

17-
parallel([['r1', {port: 15001, metrics: f}], ['r2', {port: 15002}], ['r3', {port: 15003, host: '::'}]].map((v) => (cb) => {
17+
parallel([['r1', {port: 15001, metrics: f}], ['r2', {port: 15002}], ['r3', {port: 15003, host: '::'}], ['r4', {port: 15004, cryptoChallenge: true}]].map((v) => (cb) => {
1818
rendezvous.start(base(v.pop()), (err, r) => {
1919
if (err) { return cb(err) }
2020
_r.push(r)

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class WebsocketStar {
2424
options = options || {}
2525

2626
this.id = options.id
27+
this.flag = options.allowJoinWithDisabledChallenge // let's just refer to it as "flag"
2728

2829
this.discovery = new EE()
2930
this.discovery.start = (callback) => {
@@ -84,7 +85,8 @@ class WebsocketStar {
8485
const listener = new Listener({
8586
id: this.id,
8687
handler,
87-
listeners: this.listeners_list
88+
listeners: this.listeners_list,
89+
flag: this.flag
8890
})
8991

9092
listener.on('peer', this._peerDiscovered)

src/listener.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Listener extends EE {
3737
this.canCrypto = Boolean(options.id)
3838
this._handler = options.handler || noop
3939
this.listeners_list = options.listeners || {}
40+
this.flag = options.flag
4041
}
4142

4243
// "private" functions
@@ -116,6 +117,7 @@ class Listener extends EE {
116117
this._join(callback)
117118
})
118119
} else {
120+
if (!this.flag) { return callback(new Error('Tried to listen on a server with crypto challenge disabled!\n This is prohibited by default and can lead to security issues!\n Please set "allowJoinWithDisabledChallenge" to true in the constructor options (but only if you know what you are doing)!')) }
119121
this.signature = '_'
120122
callback()
121123
}

test/dial.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('dial', () => {
3636

3737
const maLocalIP4 = '/ip4/127.0.0.1/tcp/15001'
3838
// const maLocalIP6 = '/ip6/::1/tcp/15003'
39-
const maGen = (base, id, sec) => multiaddr(`/${base}/${sec ? "wss" : "ws"}/p2p-websocket-star/ipfs/${id}`)
39+
const maGen = (base, id, sec) => multiaddr(`/${base}/${sec ? 'wss' : 'ws'}/p2p-websocket-star/ipfs/${id}`)
4040

4141
if (process.env.REMOTE_DNS) {
4242
// test with deployed signalling server using DNS
@@ -65,8 +65,8 @@ describe('dial', () => {
6565
before((done) => {
6666
map(require('./ids.json'), PeerId.createFromJSON, (err, ids) => {
6767
if (err) return done(err)
68-
ws1 = new WebSocketsStar({ id: ids[0] })
69-
ws2 = new WebSocketsStar({ id: ids[1] })
68+
ws1 = new WebSocketsStar({ id: ids[0], allowJoinWithDisabledChallenge: true })
69+
ws2 = new WebSocketsStar({ id: ids[1], allowJoinWithDisabledChallenge: true })
7070

7171
each([
7272
[ws1, ma1],

test/discovery.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('peer discovery', () => {
2020
const ma2 = multiaddr('/ip4/127.0.0.1/tcp/15003/ws/p2p-websocket-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo3B')
2121

2222
it('listen on the first', (done) => {
23-
ws1 = new WebSocketStar()
23+
ws1 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
2424

2525
const listener = ws1.createListener((/* conn */) => {})
2626

@@ -32,7 +32,7 @@ describe('peer discovery', () => {
3232
})
3333

3434
it('listen on the second, discover the first', (done) => {
35-
ws2 = new WebSocketStar()
35+
ws2 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
3636

3737
ws1.discovery.once('peer', (peerInfo) => {
3838
expect(peerInfo.multiaddrs.has(ma2)).to.equal(true)

test/listen.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('listen', () => {
2020
const mav6 = multiaddr('/ip6/::1/tcp/15003/ws/p2p-websocket-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooooB')
2121

2222
before(() => {
23-
ws = new WebSocketStar()
23+
ws = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
2424
})
2525

2626
it('listen, check for callback', (done) => {

test/reconnect.node.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('reconnect to signaling server', () => {
3535
after((done) => r.stop(done))
3636

3737
it('listen on the first', (done) => {
38-
ws1 = new WebSocketStar()
38+
ws1 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
3939

4040
const listener = ws1.createListener((conn) => {})
4141
listener.listen(ma1, (err) => {
@@ -45,7 +45,7 @@ describe('reconnect to signaling server', () => {
4545
})
4646

4747
it('listen on the second, discover the first', (done) => {
48-
ws2 = new WebSocketStar()
48+
ws2 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
4949

5050
ws1.discovery.once('peer', (peerInfo) => {
5151
expect(peerInfo.multiaddrs.has(ma2)).to.equal(true)
@@ -71,7 +71,7 @@ describe('reconnect to signaling server', () => {
7171
})
7272

7373
it('listen on the third, first discovers it', (done) => {
74-
ws3 = new WebSocketStar()
74+
ws3 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
7575

7676
const listener = ws3.createListener((conn) => {})
7777
listener.listen(ma3, (err) => expect(err).to.not.exist())

test/strict.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const pull = require('pull-stream')
1515

1616
const WebSocketStar = require('../src')
1717

18+
const SERVER_PORT = 15004
19+
1820
describe('strict', () => {
1921
let id1
2022
let ma1
@@ -32,8 +34,9 @@ describe('strict', () => {
3234

3335
id1 = keys.shift()
3436
id2 = keys.shift()
35-
ma1 = multiaddr('/ip4/127.0.0.1/tcp/15002/ws/p2p-websocket-star/ipfs/QmS8BL7M8jrXYhHo2ofEVeiq5aDKTr29ksmpcqWxjZGvpX')
36-
ma2 = multiaddr('/ip4/127.0.0.1/tcp/15002/ws/p2p-websocket-star/ipfs/QmeJGHUQ4hsMvPzAoXCdkT1Z9NBgjT7BenVPENUgpufENP')
37+
ma1 = multiaddr('/ip4/127.0.0.1/tcp/' + SERVER_PORT + '/ws/p2p-websocket-star/ipfs/' + id1.toB58String())
38+
ma2 = multiaddr('/ip4/127.0.0.1/tcp/' + SERVER_PORT + '/ws/p2p-websocket-star/ipfs/' + id2.toB58String())
39+
3740
done()
3841
})
3942
})

test/valid-connection.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ describe('valid Connection', () => {
2626
series([first, second], dial)
2727

2828
function first (next) {
29-
ws1 = new WebSocketStar()
29+
ws1 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
3030

3131
const listener = ws1.createListener((conn) => pull(conn, conn))
3232
listener.listen(ma1, next)
3333
}
3434

3535
function second (next) {
36-
ws2 = new WebSocketStar()
36+
ws2 = new WebSocketStar({ allowJoinWithDisabledChallenge: true })
3737

3838
const listener = ws2.createListener((conn) => pull(conn, conn))
3939
listener.listen(ma2, next)

0 commit comments

Comments
 (0)