2023-05-18 08:24:17 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
# Nim-Libp2p
|
2023-01-20 14:47:40 +00:00
|
|
|
# Copyright (c) 2023 Status Research & Development GmbH
|
2022-07-01 18:19:57 +00:00
|
|
|
# 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.
|
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-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/[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
|
|
|
|
|
2022-08-03 11:33:19 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
method init(p: TestProto) {.gcsafe.} =
|
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
|
|
|
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
|
|
|
|
|
2022-08-03 11:33:19 +00:00
|
|
|
{.pop.}
|
|
|
|
|
|
|
|
|
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()
|
2022-10-20 10:22:28 +00:00
|
|
|
peerInfo = PeerInfo.new(privateKey, @[ma])
|
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
|
|
|
|
|
|
|
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)
|
2023-03-08 11:30:19 +00:00
|
|
|
peerStore = PeerStore.new(identify)
|
2021-06-07 07:32:08 +00:00
|
|
|
mplexProvider = MuxerProvider.new(createMplex, MplexCodec)
|
2022-07-22 10:54:09 +00:00
|
|
|
muxers = @[mplexProvider]
|
2021-03-18 15:20:36 +00:00
|
|
|
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()
|
2023-03-08 11:30:19 +00:00
|
|
|
muxedUpgrade = MuxedUpgrade.new(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,
|
|
|
|
secureManagers,
|
|
|
|
connManager,
|
2023-03-08 11:30:19 +00:00
|
|
|
ms,
|
|
|
|
peerStore)
|
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
|
2021-12-16 10:05:20 +00:00
|
|
|
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-11-24 20:01:12 +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()
|
2022-09-05 12:31:14 +00:00
|
|
|
let sconn = await serverNoise.secure(conn, false, Opt.none(PeerId))
|
2020-11-13 03:44:02 +00:00
|
|
|
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-11-24 20:01:12 +00:00
|
|
|
clientInfo = PeerInfo.new(clientPrivKey, transport1.addrs)
|
2021-09-08 09:07:46 +00:00
|
|
|
clientNoise = Noise.new(rng, clientPrivKey, outgoing = true)
|
2021-11-24 20:01:12 +00:00
|
|
|
conn = await transport2.dial(transport1.addrs[0])
|
2021-09-08 09:07:46 +00:00
|
|
|
|
2022-09-05 12:31:14 +00:00
|
|
|
let sconn = await clientNoise.secure(conn, true, Opt.some(serverInfo.peerId))
|
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
|
2021-12-16 10:05:20 +00:00
|
|
|
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-11-24 20:01:12 +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()
|
2022-09-05 12:31:14 +00:00
|
|
|
discard await serverNoise.secure(conn, false, Opt.none(PeerId))
|
2020-11-19 02:06:42 +00:00
|
|
|
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-11-24 20:01:12 +00:00
|
|
|
clientInfo = PeerInfo.new(clientPrivKey, transport1.addrs)
|
2021-09-08 09:07:46 +00:00
|
|
|
clientNoise = Noise.new(rng, clientPrivKey, outgoing = true, commonPrologue = @[1'u8, 2'u8, 3'u8])
|
2021-11-24 20:01:12 +00:00
|
|
|
conn = await transport2.dial(transport1.addrs[0])
|
2021-09-08 09:07:46 +00:00
|
|
|
|
2020-11-13 03:44:02 +00:00
|
|
|
var sconn: Connection = nil
|
|
|
|
expect(NoiseDecryptTagError):
|
2022-09-05 12:31:14 +00:00
|
|
|
sconn = await clientNoise.secure(conn, true, Opt.some(conn.peerId))
|
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
|
2021-12-16 10:05:20 +00:00
|
|
|
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-11-24 20:01:12 +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()
|
2022-09-05 12:31:14 +00:00
|
|
|
let sconn = await serverNoise.secure(conn, false, Opt.none(PeerId))
|
2020-11-13 03:44:02 +00:00
|
|
|
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-11-24 20:01:12 +00:00
|
|
|
clientInfo = PeerInfo.new(clientPrivKey, transport1.addrs)
|
2021-09-08 09:07:46 +00:00
|
|
|
clientNoise = Noise.new(rng, clientPrivKey, outgoing = true)
|
2021-11-24 20:01:12 +00:00
|
|
|
conn = await transport2.dial(transport1.addrs[0])
|
2022-09-05 12:31:14 +00:00
|
|
|
let sconn = await clientNoise.secure(conn, true, Opt.some(serverInfo.peerId))
|
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
|
2021-12-16 10:05:20 +00:00
|
|
|
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-11-24 20:01:12 +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)
|
2022-06-16 08:08:52 +00:00
|
|
|
hmacDrbgGenerate(rng[], hugePayload)
|
2020-11-13 03:44:02 +00:00
|
|
|
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()
|
2022-09-05 12:31:14 +00:00
|
|
|
let sconn = await serverNoise.secure(conn, false, Opt.none(PeerId))
|
2020-11-13 03:44:02 +00:00
|
|
|
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-11-24 20:01:12 +00:00
|
|
|
clientInfo = PeerInfo.new(clientPrivKey, transport1.addrs)
|
2021-09-08 09:07:46 +00:00
|
|
|
clientNoise = Noise.new(rng, clientPrivKey, outgoing = true)
|
2021-11-24 20:01:12 +00:00
|
|
|
conn = await transport2.dial(transport1.addrs[0])
|
2022-09-05 12:31:14 +00:00
|
|
|
let sconn = await clientNoise.secure(conn, true, Opt.some(serverInfo.peerId))
|
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":
|
2021-12-16 10:05:20 +00:00
|
|
|
let ma1 = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
|
|
|
let ma2 = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
var peerInfo1, peerInfo2: PeerInfo
|
|
|
|
var switch1, switch2: Switch
|
|
|
|
|
|
|
|
(switch1, peerInfo1) = createSwitch(ma1, false)
|
|
|
|
|
|
|
|
let testProto = new TestProto
|
|
|
|
testProto.init()
|
|
|
|
testProto.codec = TestCodec
|
|
|
|
switch1.mount(testProto)
|
|
|
|
(switch2, peerInfo2) = createSwitch(ma2, true)
|
2021-12-03 18:23:12 +00:00
|
|
|
await switch1.start()
|
|
|
|
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())
|
|
|
|
|
|
|
|
asyncTest "e2e test wrong secure negotiation":
|
2021-12-16 10:05:20 +00:00
|
|
|
let ma1 = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
|
|
|
let ma2 = MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()
|
2020-11-13 03:44:02 +00:00
|
|
|
|
|
|
|
var peerInfo1, peerInfo2: PeerInfo
|
|
|
|
var switch1, switch2: Switch
|
|
|
|
|
|
|
|
(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
|
2021-12-03 18:23:12 +00:00
|
|
|
await switch1.start()
|
|
|
|
await switch2.start()
|
2022-09-26 09:03:24 +00:00
|
|
|
expect(DialFailedError):
|
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())
|