Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
## Nim-LibP2P
|
|
|
|
## Copyright (c) 2020 Status Research & Development GmbH
|
|
|
|
## Licensed under either of
|
|
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
## at your option.
|
|
|
|
## This file may not be copied, modified, or distributed except according to
|
|
|
|
## those terms.
|
|
|
|
|
2020-05-06 16:31:47 +00:00
|
|
|
{.used.}
|
|
|
|
|
2021-05-21 16:27:01 +00:00
|
|
|
import tables, bearssl
|
2020-06-03 02:21:11 +00:00
|
|
|
import chronos, stew/byteutils
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
import chronicles
|
|
|
|
import ../libp2p/crypto/crypto
|
|
|
|
import ../libp2p/[switch,
|
2020-04-21 01:24:42 +00:00
|
|
|
errors,
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
multistream,
|
2020-04-21 01:24:42 +00:00
|
|
|
stream/bufferstream,
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
protocols/identify,
|
2020-06-19 17:29:43 +00:00
|
|
|
stream/connection,
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
transports/transport,
|
|
|
|
transports/tcptransport,
|
|
|
|
multiaddress,
|
|
|
|
peerinfo,
|
|
|
|
crypto/crypto,
|
|
|
|
protocols/protocol,
|
|
|
|
muxers/muxer,
|
|
|
|
muxers/mplex/mplex,
|
|
|
|
protocols/secure/noise,
|
2020-11-04 14:24:41 +00:00
|
|
|
protocols/secure/secio,
|
2021-03-18 15:20:36 +00:00
|
|
|
protocols/secure/secure,
|
|
|
|
upgrademngrs/muxedupgrade,
|
|
|
|
connmanager]
|
2020-05-08 20:10:06 +00:00
|
|
|
import ./helpers
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
|
2020-04-21 01:24:42 +00:00
|
|
|
const
|
|
|
|
TestCodec = "/test/proto/1.0.0"
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
TestProto = ref object of LPProtocol
|
|
|
|
|
|
|
|
method init(p: TestProto) {.gcsafe.} =
|
|
|
|
proc handle(conn: Connection, proto: string) {.async, gcsafe.} =
|
2020-06-03 02:21:11 +00:00
|
|
|
let msg = string.fromBytes(await conn.readLp(1024))
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
check "Hello!" == msg
|
|
|
|
await conn.writeLp("Hello!")
|
|
|
|
await conn.close()
|
|
|
|
|
|
|
|
p.codec = TestCodec
|
|
|
|
p.handler = handle
|
|
|
|
|
2020-11-04 14:24:41 +00:00
|
|
|
proc createSwitch(ma: MultiAddress; outgoing: bool, secio: bool = false): (Switch, PeerInfo) =
|
2021-09-08 09:07:46 +00:00
|
|
|
var
|
|
|
|
privateKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
peerInfo = PeerInfo.new(privateKey)
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
peerInfo.addrs.add(ma)
|
|
|
|
|
|
|
|
proc createMplex(conn: Connection): Muxer =
|
2021-10-25 08:26:32 +00:00
|
|
|
result = Mplex.new(conn)
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
|
2021-03-18 15:20:36 +00:00
|
|
|
let
|
2021-06-07 07:32:08 +00:00
|
|
|
identify = Identify.new(peerInfo)
|
|
|
|
mplexProvider = MuxerProvider.new(createMplex, MplexCodec)
|
2021-03-18 15:20:36 +00:00
|
|
|
muxers = [(MplexCodec, mplexProvider)].toTable()
|
|
|
|
secureManagers = if secio:
|
2021-09-08 09:07:46 +00:00
|
|
|
[Secure(Secio.new(rng, privateKey))]
|
2020-11-04 14:24:41 +00:00
|
|
|
else:
|
2021-09-08 09:07:46 +00:00
|
|
|
[Secure(Noise.new(rng, privateKey, outgoing = outgoing))]
|
2021-10-25 08:26:32 +00:00
|
|
|
connManager = ConnManager.new()
|
2021-06-07 07:32:08 +00:00
|
|
|
ms = MultistreamSelect.new()
|
2021-10-25 08:26:32 +00:00
|
|
|
muxedUpgrade = MuxedUpgrade.new(identify, muxers, secureManagers, connManager, ms)
|
2021-06-30 08:59:30 +00:00
|
|
|
transports = @[Transport(TcpTransport.new(upgrade = muxedUpgrade))]
|
2021-03-18 15:20:36 +00:00
|
|
|
|
|
|
|
let switch = newSwitch(
|
|
|
|
peerInfo,
|
|
|
|
transports,
|
|
|
|
identify,
|
|
|
|
muxers,
|
|
|
|
secureManagers,
|
|
|
|
connManager,
|
|
|
|
ms)
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
result = (switch, peerInfo)
|
|
|
|
|
|
|
|
suite "Noise":
|
2020-04-21 01:24:42 +00:00
|
|
|
teardown:
|
2020-09-21 17:48:19 +00:00
|
|
|
checkTrackers()
|
2020-05-06 16:31:47 +00:00
|
|
|
|
2020-11-13 03:44:02 +00:00
|
|
|
asyncTest "e2e: handle write + noise":
|
|
|
|
let
|
|
|
|
server = Multiaddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
2021-09-08 09:07:46 +00:00
|
|
|
serverPrivKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
serverInfo = PeerInfo.new(serverPrivKey, [server])
|
2021-09-08 09:07:46 +00:00
|
|
|
serverNoise = Noise.new(rng, serverPrivKey, outgoing = false)
|
2020-11-13 03:44:02 +00:00
|
|
|
|
2021-06-30 08:59:30 +00:00
|
|
|
let transport1: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
2021-06-14 23:21:44 +00:00
|
|
|
asyncSpawn transport1.start(server)
|
2020-11-19 02:06:42 +00:00
|
|
|
|
|
|
|
proc acceptHandler() {.async.} =
|
|
|
|
let conn = await transport1.accept()
|
2020-11-13 03:44:02 +00:00
|
|
|
let sconn = await serverNoise.secure(conn, false)
|
|
|
|
try:
|
|
|
|
await sconn.write("Hello!")
|
|
|
|
finally:
|
|
|
|
await sconn.close()
|
|
|
|
await conn.close()
|
|
|
|
|
|
|
|
let
|
2020-11-19 02:06:42 +00:00
|
|
|
acceptFut = acceptHandler()
|
2021-06-30 08:59:30 +00:00
|
|
|
transport2: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
2021-09-08 09:07:46 +00:00
|
|
|
clientPrivKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
clientInfo = PeerInfo.new(clientPrivKey, [transport1.ma])
|
2021-09-08 09:07:46 +00:00
|
|
|
clientNoise = Noise.new(rng, clientPrivKey, outgoing = true)
|
2020-11-13 03:44:02 +00:00
|
|
|
conn = await transport2.dial(transport1.ma)
|
2021-09-08 09:07:46 +00:00
|
|
|
|
|
|
|
conn.peerId = serverInfo.peerId
|
|
|
|
let sconn = await clientNoise.secure(conn, true)
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
var msg = newSeq[byte](6)
|
|
|
|
await sconn.readExactly(addr msg[0], 6)
|
|
|
|
|
|
|
|
await sconn.close()
|
|
|
|
await conn.close()
|
2020-11-19 02:06:42 +00:00
|
|
|
await acceptFut
|
|
|
|
await transport1.stop()
|
|
|
|
await transport2.stop()
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
check string.fromBytes(msg) == "Hello!"
|
|
|
|
|
|
|
|
asyncTest "e2e: handle write + noise (wrong prologue)":
|
|
|
|
let
|
|
|
|
server = Multiaddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
2021-09-08 09:07:46 +00:00
|
|
|
serverPrivKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
serverInfo = PeerInfo.new(serverPrivKey, [server])
|
2021-09-08 09:07:46 +00:00
|
|
|
serverNoise = Noise.new(rng, serverPrivKey, outgoing = false)
|
2020-11-13 03:44:02 +00:00
|
|
|
|
2020-11-19 02:06:42 +00:00
|
|
|
let
|
2021-06-30 08:59:30 +00:00
|
|
|
transport1: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
2020-11-19 02:06:42 +00:00
|
|
|
|
2021-06-14 23:21:44 +00:00
|
|
|
asyncSpawn transport1.start(server)
|
2020-11-19 02:06:42 +00:00
|
|
|
|
|
|
|
proc acceptHandler() {.async, gcsafe.} =
|
|
|
|
var conn: Connection
|
2020-11-13 03:44:02 +00:00
|
|
|
try:
|
2020-11-19 02:06:42 +00:00
|
|
|
conn = await transport1.accept()
|
|
|
|
discard await serverNoise.secure(conn, false)
|
|
|
|
except CatchableError:
|
|
|
|
discard
|
2020-11-13 03:44:02 +00:00
|
|
|
finally:
|
|
|
|
await conn.close()
|
|
|
|
|
|
|
|
let
|
2020-11-19 02:06:42 +00:00
|
|
|
handlerWait = acceptHandler()
|
2021-06-30 08:59:30 +00:00
|
|
|
transport2: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
2021-09-08 09:07:46 +00:00
|
|
|
clientPrivKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
clientInfo = PeerInfo.new(clientPrivKey, [transport1.ma])
|
2021-09-08 09:07:46 +00:00
|
|
|
clientNoise = Noise.new(rng, clientPrivKey, outgoing = true, commonPrologue = @[1'u8, 2'u8, 3'u8])
|
2020-11-13 03:44:02 +00:00
|
|
|
conn = await transport2.dial(transport1.ma)
|
2021-09-08 09:07:46 +00:00
|
|
|
conn.peerId = serverInfo.peerId
|
|
|
|
|
2020-11-13 03:44:02 +00:00
|
|
|
var sconn: Connection = nil
|
|
|
|
expect(NoiseDecryptTagError):
|
|
|
|
sconn = await clientNoise.secure(conn, true)
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
|
2020-11-13 03:44:02 +00:00
|
|
|
await conn.close()
|
2020-11-19 02:06:42 +00:00
|
|
|
await handlerWait
|
|
|
|
await transport1.stop()
|
|
|
|
await transport2.stop()
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
asyncTest "e2e: handle read + noise":
|
|
|
|
let
|
|
|
|
server = Multiaddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
2021-09-08 09:07:46 +00:00
|
|
|
serverPrivKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
serverInfo = PeerInfo.new(serverPrivKey, [server])
|
2021-09-08 09:07:46 +00:00
|
|
|
serverNoise = Noise.new(rng, serverPrivKey, outgoing = false)
|
2020-11-13 03:44:02 +00:00
|
|
|
readTask = newFuture[void]()
|
|
|
|
|
2021-06-30 08:59:30 +00:00
|
|
|
let transport1: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
2021-06-14 23:21:44 +00:00
|
|
|
asyncSpawn transport1.start(server)
|
2020-11-19 02:06:42 +00:00
|
|
|
|
|
|
|
proc acceptHandler() {.async, gcsafe.} =
|
|
|
|
let conn = await transport1.accept()
|
2020-11-13 03:44:02 +00:00
|
|
|
let sconn = await serverNoise.secure(conn, false)
|
|
|
|
defer:
|
|
|
|
await sconn.close()
|
|
|
|
await conn.close()
|
2020-11-19 02:06:42 +00:00
|
|
|
|
2020-05-15 04:02:05 +00:00
|
|
|
var msg = newSeq[byte](6)
|
|
|
|
await sconn.readExactly(addr msg[0], 6)
|
2020-11-13 03:44:02 +00:00
|
|
|
check string.fromBytes(msg) == "Hello!"
|
|
|
|
|
|
|
|
let
|
2020-11-19 02:06:42 +00:00
|
|
|
acceptFut = acceptHandler()
|
2021-06-30 08:59:30 +00:00
|
|
|
transport2: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
2021-09-08 09:07:46 +00:00
|
|
|
clientPrivKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
clientInfo = PeerInfo.new(clientPrivKey, [transport1.ma])
|
2021-09-08 09:07:46 +00:00
|
|
|
clientNoise = Noise.new(rng, clientPrivKey, outgoing = true)
|
2020-11-13 03:44:02 +00:00
|
|
|
conn = await transport2.dial(transport1.ma)
|
2021-09-08 09:07:46 +00:00
|
|
|
conn.peerId = serverInfo.peerId
|
|
|
|
let sconn = await clientNoise.secure(conn, true)
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
await sconn.write("Hello!")
|
2020-11-19 02:06:42 +00:00
|
|
|
await acceptFut
|
2020-11-13 03:44:02 +00:00
|
|
|
await sconn.close()
|
|
|
|
await conn.close()
|
2020-11-19 02:06:42 +00:00
|
|
|
await transport1.stop()
|
|
|
|
await transport2.stop()
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
asyncTest "e2e: handle read + noise fragmented":
|
|
|
|
let
|
|
|
|
server = Multiaddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
2021-09-08 09:07:46 +00:00
|
|
|
serverPrivKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
serverInfo = PeerInfo.new(serverPrivKey, [server])
|
2021-09-08 09:07:46 +00:00
|
|
|
serverNoise = Noise.new(rng, serverPrivKey, outgoing = false)
|
2020-11-13 03:44:02 +00:00
|
|
|
readTask = newFuture[void]()
|
|
|
|
|
|
|
|
var hugePayload = newSeq[byte](0xFFFFF)
|
|
|
|
brHmacDrbgGenerate(rng[], hugePayload)
|
|
|
|
trace "Sending huge payload", size = hugePayload.len
|
|
|
|
|
2020-11-19 02:06:42 +00:00
|
|
|
let
|
2021-06-30 08:59:30 +00:00
|
|
|
transport1: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
2020-11-19 02:06:42 +00:00
|
|
|
listenFut = transport1.start(server)
|
|
|
|
|
|
|
|
proc acceptHandler() {.async, gcsafe.} =
|
|
|
|
let conn = await transport1.accept()
|
2020-11-13 03:44:02 +00:00
|
|
|
let sconn = await serverNoise.secure(conn, false)
|
|
|
|
defer:
|
|
|
|
await sconn.close()
|
|
|
|
let msg = await sconn.readLp(1024*1024)
|
|
|
|
check msg == hugePayload
|
|
|
|
readTask.complete()
|
|
|
|
|
|
|
|
let
|
2020-11-19 02:06:42 +00:00
|
|
|
acceptFut = acceptHandler()
|
2021-06-30 08:59:30 +00:00
|
|
|
transport2: TcpTransport = TcpTransport.new(upgrade = Upgrade())
|
2021-09-08 09:07:46 +00:00
|
|
|
clientPrivKey = PrivateKey.random(ECDSA, rng[]).get()
|
2021-10-25 08:26:32 +00:00
|
|
|
clientInfo = PeerInfo.new(clientPrivKey, [transport1.ma])
|
2021-09-08 09:07:46 +00:00
|
|
|
clientNoise = Noise.new(rng, clientPrivKey, outgoing = true)
|
2020-11-13 03:44:02 +00:00
|
|
|
conn = await transport2.dial(transport1.ma)
|
2021-09-08 09:07:46 +00:00
|
|
|
conn.peerId = serverInfo.peerId
|
|
|
|
let sconn = await clientNoise.secure(conn, true)
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
await sconn.writeLp(hugePayload)
|
|
|
|
await readTask
|
|
|
|
|
|
|
|
await sconn.close()
|
|
|
|
await conn.close()
|
2020-11-19 02:06:42 +00:00
|
|
|
await acceptFut
|
|
|
|
await transport2.stop()
|
|
|
|
await transport1.stop()
|
2020-11-13 03:44:02 +00:00
|
|
|
await listenFut
|
|
|
|
|
|
|
|
asyncTest "e2e use switch dial proto string":
|
|
|
|
let ma1: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
|
|
|
let ma2: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
|
|
|
|
|
|
|
var peerInfo1, peerInfo2: PeerInfo
|
|
|
|
var switch1, switch2: Switch
|
|
|
|
var awaiters: seq[Future[void]]
|
|
|
|
|
|
|
|
(switch1, peerInfo1) = createSwitch(ma1, false)
|
|
|
|
|
|
|
|
let testProto = new TestProto
|
|
|
|
testProto.init()
|
|
|
|
testProto.codec = TestCodec
|
|
|
|
switch1.mount(testProto)
|
|
|
|
(switch2, peerInfo2) = createSwitch(ma2, true)
|
|
|
|
awaiters.add(await switch1.start())
|
|
|
|
awaiters.add(await switch2.start())
|
2021-09-08 09:07:46 +00:00
|
|
|
let conn = await switch2.dial(switch1.peerInfo.peerId, switch1.peerInfo.addrs, TestCodec)
|
2020-11-13 03:44:02 +00:00
|
|
|
await conn.writeLp("Hello!")
|
|
|
|
let msg = string.fromBytes(await conn.readLp(1024))
|
|
|
|
check "Hello!" == msg
|
|
|
|
await conn.close()
|
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)
* Add Curve25519 (BearSSL) required operations for noise
* Fix curve mulgen iterate/derive
* Fix misleading header
* Add chachapoly proper test
* Curve25519 integration tests (failing, something is wrong)
* Add few converters, finish c25519 integration tests
* Remove implicit converters
* removed internal globals
* Start noise implementation
* Fix public() using proper bear mulgen
* Noise protocol WIP
* Noise progress
* Add a quick nim version of HKDF
* Converted hkdf to iterator, useful for noise
* Noise protocol implementation progress
* Noise progress
* XX handshake almost there
* noise progress
* Noise, testing handshake with test vectors
* Noise handshake progress, still wrong somewhere!
* Noise handshake success!
* Full verified noise XX handshake completed
* Fix and rewrite test to be similar to switch one
* Start with connection upgrade
* Switch chachapoly to CT implementations
* Improve HKDF implementation
* Use a type insted of tuple for HandshakeResult
* Remove unnecessary Let
* More cosmetic fixes
* Properly check randomBytes result
* Fix chachapoly signature
* Noise full circle (altho dispatcher is nil cursed)
* Allow nil aads in chachapoly routines
* Noise implementation up to running full test
* Use bearssl HKDF as well
* Directly use bearssl rng for curve25519 keys
* Add a (disabled/no CI) noise interop test server
* WIP on fixing interop issues
* More fixes in noise implementation for interop
* bump chronos requirement (nimble)
* Add a chachapoly test for very small size payloads
* Noise, more tracing
* Add 2 properly working noise tests
* Fix payload packing, following the spec properly (and not go version but
rather rust)
* Sanity, replace discard with asyncCheck
* Small fixes and optimization
* Use stew endian2 rather then system endian module
* Update nimble deps (chronos)
* Minor cosmetic/code sanity fixes
* Noise, handle Nonce max
* Noise tests, make sure to close secured conns
* More polish, improve code readability too
* More polish and testing again which test fails
* Further polishing
* Restore noise tests
* Remove useless Future[void]
* Remove useless CipherState initializer
* add a proper read wait future in second noise test
* Remove noise generic secure implementation for now
* Few fixes to run eth2 sim
* Add more debug info in noise traces
* Merge size + payload write in sendEncryptedMessage
* Revert secure interface, add outgoing property directly in newNoise
* remove sendEncrypted and receiveEncrypted
* Use openarray in chachapoly and curve25519 helpers
2020-03-17 12:30:01 +00:00
|
|
|
|
2020-11-13 03:44:02 +00:00
|
|
|
await allFuturesThrowing(
|
|
|
|
switch1.stop(),
|
|
|
|
switch2.stop())
|
|
|
|
await allFuturesThrowing(awaiters)
|
|
|
|
|
|
|
|
asyncTest "e2e test wrong secure negotiation":
|
|
|
|
let ma1: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
|
|
|
let ma2: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
|
|
|
|
|
|
|
var peerInfo1, peerInfo2: PeerInfo
|
|
|
|
var switch1, switch2: Switch
|
|
|
|
var awaiters: seq[Future[void]]
|
|
|
|
|
|
|
|
(switch1, peerInfo1) = createSwitch(ma1, false)
|
|
|
|
|
|
|
|
let testProto = new TestProto
|
|
|
|
testProto.init()
|
|
|
|
testProto.codec = TestCodec
|
|
|
|
switch1.mount(testProto)
|
|
|
|
(switch2, peerInfo2) = createSwitch(ma2, true, true) # secio, we want to fail
|
|
|
|
awaiters.add(await switch1.start())
|
|
|
|
awaiters.add(await switch2.start())
|
|
|
|
expect(UpgradeFailedError):
|
2021-09-08 09:07:46 +00:00
|
|
|
let conn = await switch2.dial(switch1.peerInfo.peerId, switch1.peerInfo.addrs, TestCodec)
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
await allFuturesThrowing(
|
|
|
|
switch1.stop(),
|
|
|
|
switch2.stop())
|
|
|
|
|
|
|
|
await allFuturesThrowing(awaiters)
|