diff --git a/quic.nimble b/quic.nimble index 3ea049b..f90bbac 100644 --- a/quic.nimble +++ b/quic.nimble @@ -7,5 +7,5 @@ license = "MIT" requires "nim >= 1.2.6" requires "stew >= 0.1.0 & < 0.2.0" requires "chronos >= 2.5.2 & < 3.0.0" -requires "https://github.com/status-im/nim-ngtcp2.git >= 0.1.0 & < 0.2.0" +requires "https://github.com/status-im/nim-ngtcp2.git >= 0.32.0 & < 0.33.0" requires "sysrandom >= 1.1.0 & < 2.0.0" diff --git a/quic/ngtcp2/client.nim b/quic/ngtcp2/client.nim index 3109ac6..d8f4fb4 100644 --- a/quic/ngtcp2/client.nim +++ b/quic/ngtcp2/client.nim @@ -13,7 +13,7 @@ import connection import path import streams -let zeroKey = Key() +var zeroKey = dummyKey() proc clientInitial(connection: ptr ngtcp2_conn, user_data: pointer): cint {.cdecl.} = connection.install0RttKey(zeroKey) @@ -56,7 +56,7 @@ proc newClientConnection*(local, remote: TransportAddress): Connection = unsafeAddr destination, unsafeAddr source, path.toPathPtr, - cast[uint32](NGTCP2_PROTO_VER), + cast[uint32](NGTCP2_PROTO_VER_MAX), addr callbacks, unsafeAddr settings, nil, diff --git a/quic/ngtcp2/keys.nim b/quic/ngtcp2/keys.nim index 2ace27e..ddc7bfd 100644 --- a/quic/ngtcp2/keys.nim +++ b/quic/ngtcp2/keys.nim @@ -2,11 +2,15 @@ import ngtcp2 type Key* = object + cryptoContext*: ngtcp2_crypto_ctx aeadContext*: ngtcp2_crypto_aead_ctx hpContext*: ngtcp2_crypto_cipher_ctx iv*: array[16, uint8] secret*: array[16, uint8] +proc dummyKey*: Key = + result.cryptoContext.max_encryption = 1000 + proc install0RttKey*(connection: ptr ngtcp2_conn, key: Key) = var key = key doAssert 0 == connection.ngtcp2_conn_install_initial_key( @@ -18,6 +22,7 @@ proc install0RttKey*(connection: ptr ngtcp2_conn, key: Key) = addr key.hpContext, key.iv.len.uint ) + connection.ngtcp2_conn_set_initial_crypto_ctx(addr key.cryptoContext) proc installHandshakeKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) = var rx = rx @@ -36,6 +41,7 @@ proc installHandshakeKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) = tx.iv.len.uint, addr tx.hpContext ) + connection.ngtcp2_conn_set_crypto_ctx(addr rx.cryptoContext) proc install1RttKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) = var rx = rx @@ -58,3 +64,4 @@ proc install1RttKeys*(connection: ptr ngtcp2_conn, rx, tx: Key) = tx.iv.len.uint, addr tx.hpContext ) + connection.ngtcp2_conn_set_crypto_ctx(addr rx.cryptoContext) diff --git a/quic/ngtcp2/server.nim b/quic/ngtcp2/server.nim index 2f50500..c2c7697 100644 --- a/quic/ngtcp2/server.nim +++ b/quic/ngtcp2/server.nim @@ -14,7 +14,7 @@ import path import errors import streams -let zeroKey = Key() +let zeroKey = dummyKey() proc receiveClientInitial(connection: ptr ngtcp2_conn, dcid: ptr ngtcp2_cid, userData: pointer): cint {.cdecl.} = connection.install0RttKey(zeroKey) @@ -57,7 +57,7 @@ proc newServerConnection(local, remote: TransportAddress, source, destination: n unsafeAddr source, unsafeAddr id, path.toPathPtr, - cast[uint32](NGTCP2_PROTO_VER), + cast[uint32](NGTCP2_PROTO_VER_MAX), addr callbacks, addr settings, nil, diff --git a/quic/ngtcp2/udp.nim b/quic/ngtcp2/udp.nim index 6f44b92..57419e8 100644 --- a/quic/ngtcp2/udp.nim +++ b/quic/ngtcp2/udp.nim @@ -23,6 +23,7 @@ proc trySend(connection: Connection): Datagram = 0, getMonoTime().ticks.uint ) + checkResult length.cint let data = connection.buffer[0..