Bump nim-eth and nim-bearssl and accompanying fixes (#1150)
This commit is contained in:
parent
0068e3b427
commit
fb12793482
|
@ -50,7 +50,7 @@ proc loadBootstrapFile*(bootstrapFile: string,
|
||||||
# However that would require the pull the keystore.nim and parts of
|
# However that would require the pull the keystore.nim and parts of
|
||||||
# keystore_management.nim out of nimbus-eth2.
|
# keystore_management.nim out of nimbus-eth2.
|
||||||
proc getPersistentNetKey*(
|
proc getPersistentNetKey*(
|
||||||
rng: var BrHmacDrbgContext, keyFilePath: string, dataDir: string):
|
rng: var HmacDrbgContext, keyFilePath: string, dataDir: string):
|
||||||
PrivateKey =
|
PrivateKey =
|
||||||
logScope:
|
logScope:
|
||||||
key_file = keyFilePath
|
key_file = keyFilePath
|
||||||
|
|
|
@ -78,7 +78,7 @@ type
|
||||||
contentOffers: seq[ContentOffer]
|
contentOffers: seq[ContentOffer]
|
||||||
connectionTimeout: Duration
|
connectionTimeout: Duration
|
||||||
contentReadTimeout*: Duration
|
contentReadTimeout*: Duration
|
||||||
rng: ref BrHmacDrbgContext
|
rng: ref HmacDrbgContext
|
||||||
udata: pointer
|
udata: pointer
|
||||||
contentHandler: ContentHandlerCallback
|
contentHandler: ContentHandlerCallback
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ proc addContentOffer*(
|
||||||
# TODO: Should we check if `NodeId` & `connectionId` combo already exists?
|
# TODO: Should we check if `NodeId` & `connectionId` combo already exists?
|
||||||
# What happens if we get duplicates?
|
# What happens if we get duplicates?
|
||||||
var connectionId: Bytes2
|
var connectionId: Bytes2
|
||||||
brHmacDrbgGenerate(stream.rng[], connectionId)
|
stream.rng[].generate(connectionId)
|
||||||
|
|
||||||
# uTP protocol uses BE for all values in the header, incl. connection id.
|
# uTP protocol uses BE for all values in the header, incl. connection id.
|
||||||
let id = uint16.fromBytesBE(connectionId)
|
let id = uint16.fromBytesBE(connectionId)
|
||||||
|
@ -122,7 +122,7 @@ proc addContentRequest*(
|
||||||
# TODO: Should we check if `NodeId` & `connectionId` combo already exists?
|
# TODO: Should we check if `NodeId` & `connectionId` combo already exists?
|
||||||
# What happens if we get duplicates?
|
# What happens if we get duplicates?
|
||||||
var connectionId: Bytes2
|
var connectionId: Bytes2
|
||||||
brHmacDrbgGenerate(stream.rng[], connectionId)
|
stream.rng[].generate(connectionId)
|
||||||
|
|
||||||
# uTP protocol uses BE for all values in the header, incl. connection id.
|
# uTP protocol uses BE for all values in the header, incl. connection id.
|
||||||
let id = uint16.fromBytesBE(connectionId)
|
let id = uint16.fromBytesBE(connectionId)
|
||||||
|
|
|
@ -15,12 +15,11 @@ import
|
||||||
../content_db,
|
../content_db,
|
||||||
./test_helpers
|
./test_helpers
|
||||||
|
|
||||||
proc generateNRandomU256(rng: var BrHmacDrbgContext, n: int): seq[UInt256] =
|
proc generateNRandomU256(rng: var HmacDrbgContext, n: int): seq[UInt256] =
|
||||||
var i = 0
|
var i = 0
|
||||||
var res = newSeq[Uint256]()
|
var res = newSeq[Uint256]()
|
||||||
while i < n:
|
while i < n:
|
||||||
var bytes = newSeq[byte](32)
|
let bytes = rng.generateBytes(32)
|
||||||
brHmacDrbgGenerate(rng, bytes)
|
|
||||||
let num = Uint256.fromBytesBE(bytes)
|
let num = Uint256.fromBytesBE(bytes)
|
||||||
res.add(num)
|
res.add(num)
|
||||||
inc i
|
inc i
|
||||||
|
|
|
@ -20,7 +20,7 @@ type TestCase = ref object
|
||||||
server: RpcProxy
|
server: RpcProxy
|
||||||
client: RpcHttpClient
|
client: RpcHttpClient
|
||||||
|
|
||||||
proc setupTest(rng: ref BrHmacDrbgContext): Future[TestCase] {.async.} =
|
proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} =
|
||||||
let
|
let
|
||||||
localSrvAddress = "127.0.0.1"
|
localSrvAddress = "127.0.0.1"
|
||||||
localSrvPort = 8545
|
localSrvPort = 8545
|
||||||
|
|
|
@ -15,7 +15,7 @@ proc localAddress*(port: int): Address =
|
||||||
Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(port))
|
Address(ip: ValidIpAddress.init("127.0.0.1"), port: Port(port))
|
||||||
|
|
||||||
proc initDiscoveryNode*(
|
proc initDiscoveryNode*(
|
||||||
rng: ref BrHmacDrbgContext,
|
rng: ref HmacDrbgContext,
|
||||||
privKey: PrivateKey,
|
privKey: PrivateKey,
|
||||||
address: Address,
|
address: Address,
|
||||||
bootstrapRecords: openArray[Record] = [],
|
bootstrapRecords: openArray[Record] = [],
|
||||||
|
@ -36,7 +36,7 @@ proc initDiscoveryNode*(
|
||||||
|
|
||||||
result.open()
|
result.open()
|
||||||
|
|
||||||
proc genByteSeq*(length: int): seq[byte] =
|
proc genByteSeq*(length: int): seq[byte] =
|
||||||
var i = 0
|
var i = 0
|
||||||
var resultSeq = newSeq[byte](length)
|
var resultSeq = newSeq[byte](length)
|
||||||
while i < length:
|
while i < length:
|
||||||
|
|
|
@ -29,7 +29,7 @@ proc validateContent(content: openArray[byte], contentKey: ByteList): bool =
|
||||||
true
|
true
|
||||||
|
|
||||||
proc initPortalProtocol(
|
proc initPortalProtocol(
|
||||||
rng: ref BrHmacDrbgContext,
|
rng: ref HmacDrbgContext,
|
||||||
privKey: PrivateKey,
|
privKey: PrivateKey,
|
||||||
address: Address,
|
address: Address,
|
||||||
bootstrapRecords: openArray[Record] = []): PortalProtocol =
|
bootstrapRecords: openArray[Record] = []): PortalProtocol =
|
||||||
|
@ -57,7 +57,7 @@ proc stopPortalProtocol(proto: PortalProtocol) {.async.} =
|
||||||
proto.stop()
|
proto.stop()
|
||||||
await proto.baseProtocol.closeWait()
|
await proto.baseProtocol.closeWait()
|
||||||
|
|
||||||
proc defaultTestSetup(rng: ref BrHmacDrbgContext):
|
proc defaultTestSetup(rng: ref HmacDrbgContext):
|
||||||
(PortalProtocol, PortalProtocol) =
|
(PortalProtocol, PortalProtocol) =
|
||||||
let
|
let
|
||||||
proto1 =
|
proto1 =
|
||||||
|
|
|
@ -268,11 +268,8 @@ proc run(config: PortalCliConf) =
|
||||||
else:
|
else:
|
||||||
echo nodes.error
|
echo nodes.error
|
||||||
of findcontent:
|
of findcontent:
|
||||||
proc random(T: type UInt256, rng: var BrHmacDrbgContext): T =
|
proc random(T: type UInt256, rng: var HmacDrbgContext): T =
|
||||||
var key: UInt256
|
rng.generate(T)
|
||||||
brHmacDrbgGenerate(addr rng, addr key, csize_t(sizeof(key)))
|
|
||||||
|
|
||||||
key
|
|
||||||
|
|
||||||
# For now just some random bytes
|
# For now just some random bytes
|
||||||
let contentKey = ByteList.init(@[1'u8])
|
let contentKey = ByteList.init(@[1'u8])
|
||||||
|
|
|
@ -12,20 +12,15 @@ import
|
||||||
eth/keys,
|
eth/keys,
|
||||||
./utp_test_client
|
./utp_test_client
|
||||||
|
|
||||||
proc generateByteSeq(rng: var BrHmacDrbgContext, length: int): seq[byte] =
|
proc generateBytesHex(rng: var HmacDrbgContext, length: int): string =
|
||||||
var bytes = newSeq[byte](length)
|
rng.generateBytes(length).toHex()
|
||||||
brHmacDrbgGenerate(rng, bytes)
|
|
||||||
return bytes
|
|
||||||
|
|
||||||
proc generateByteSeqHex(rng: var BrHmacDrbgContext, length: int): string =
|
|
||||||
generateByteSeq(rng, length).toHex()
|
|
||||||
|
|
||||||
# Before running the suit, there need to be two instances of utp_test_app running
|
# Before running the suit, there need to be two instances of utp_test_app running
|
||||||
# under provided ports (9042, 9041).
|
# under provided ports (9042, 9041).
|
||||||
# Those could be launched locally by running either
|
# Those could be launched locally by running either
|
||||||
# ./utp_test_app --udp-listen-address=127.0.0.1 --rpc-listen-address=0.0.0.0 --udp-port=9041 --rpc-port=9041
|
# ./utp_test_app --udp-listen-address=127.0.0.1 --rpc-listen-address=0.0.0.0 --udp-port=9041 --rpc-port=9041
|
||||||
# ./utp_test_app --udp-listen-address=127.0.0.1 --rpc-listen-address=0.0.0.0 --udp-port=9042 --rpc-port=9042
|
# ./utp_test_app --udp-listen-address=127.0.0.1 --rpc-listen-address=0.0.0.0 --udp-port=9042 --rpc-port=9042
|
||||||
# or
|
# or
|
||||||
# 1. running in docker dir: docker build -t test-utp --no-cache --build-arg BRANCH_NAME=branch-name .
|
# 1. running in docker dir: docker build -t test-utp --no-cache --build-arg BRANCH_NAME=branch-name .
|
||||||
# 2. running in docker dir: SCENARIO="scenario name and params " docker-compose up
|
# 2. running in docker dir: SCENARIO="scenario name and params " docker-compose up
|
||||||
procSuite "Utp integration tests":
|
procSuite "Utp integration tests":
|
||||||
|
@ -35,10 +30,10 @@ procSuite "Utp integration tests":
|
||||||
|
|
||||||
let serverContainerAddress = "127.0.0.1"
|
let serverContainerAddress = "127.0.0.1"
|
||||||
let serverContainerPort = Port(9041)
|
let serverContainerPort = Port(9041)
|
||||||
|
|
||||||
type
|
type
|
||||||
FutureCallback[A] = proc (): Future[A] {.gcsafe, raises: [Defect].}
|
FutureCallback[A] = proc (): Future[A] {.gcsafe, raises: [Defect].}
|
||||||
# combinator which repeatadly calls passed closure until returned future is
|
# combinator which repeatedly calls passed closure until returned future is
|
||||||
# successfull
|
# successfull
|
||||||
# TODO: currently works only for non void types
|
# TODO: currently works only for non void types
|
||||||
proc repeatTillSuccess[A](f: FutureCallback[A], maxTries: int = 20): Future[A] {.async.} =
|
proc repeatTillSuccess[A](f: FutureCallback[A], maxTries: int = 20): Future[A] {.async.} =
|
||||||
|
@ -61,8 +56,8 @@ procSuite "Utp integration tests":
|
||||||
proc findServerConnection(
|
proc findServerConnection(
|
||||||
connections: openArray[SKey],
|
connections: openArray[SKey],
|
||||||
clientId: NodeId,
|
clientId: NodeId,
|
||||||
clientConnectionId: uint16): Option[Skey] =
|
clientConnectionId: uint16): Option[Skey] =
|
||||||
let conns: seq[SKey] =
|
let conns: seq[SKey] =
|
||||||
connections.filter((key:Skey) => key.id == (clientConnectionId + 1) and key.nodeId == clientId)
|
connections.filter((key:Skey) => key.id == (clientConnectionId + 1) and key.nodeId == clientId)
|
||||||
if len(conns) == 0:
|
if len(conns) == 0:
|
||||||
none[Skey]()
|
none[Skey]()
|
||||||
|
@ -83,13 +78,13 @@ procSuite "Utp integration tests":
|
||||||
|
|
||||||
# nodes need to have established session before the utp try
|
# nodes need to have established session before the utp try
|
||||||
discard await repeatTillSuccess(() => client.discv5_ping(serverInfo.nodeEnr))
|
discard await repeatTillSuccess(() => client.discv5_ping(serverInfo.nodeEnr))
|
||||||
|
|
||||||
return (client, clientInfo, server, serverInfo)
|
return (client, clientInfo, server, serverInfo)
|
||||||
|
|
||||||
asyncTest "Transfer 100k bytes of data over utp stream from client to server":
|
asyncTest "Transfer 100k bytes of data over utp stream from client to server":
|
||||||
let (client, clientInfo, server, serverInfo) = await setupTest()
|
let (client, clientInfo, server, serverInfo) = await setupTest()
|
||||||
let numOfBytes = 100000
|
let numOfBytes = 100000
|
||||||
let
|
let
|
||||||
clientConnectionKey = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
clientConnectionKey = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
||||||
serverConnections = await repeatTillSuccess(() => server.utp_get_connections())
|
serverConnections = await repeatTillSuccess(() => server.utp_get_connections())
|
||||||
maybeServerConnectionKey = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey.id)
|
maybeServerConnectionKey = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey.id)
|
||||||
|
@ -100,7 +95,7 @@ procSuite "Utp integration tests":
|
||||||
let serverConnectionKey = maybeServerConnectionKey.unsafeGet()
|
let serverConnectionKey = maybeServerConnectionKey.unsafeGet()
|
||||||
|
|
||||||
let
|
let
|
||||||
bytesToWrite = generateByteSeqHex(rng[], numOfBytes)
|
bytesToWrite = generateBytesHex(rng[], numOfBytes)
|
||||||
writeRes = await client.utp_write(clientConnectionKey, bytesToWrite)
|
writeRes = await client.utp_write(clientConnectionKey, bytesToWrite)
|
||||||
readData = await server.utp_read(serverConnectionKey, numOfBytes)
|
readData = await server.utp_read(serverConnectionKey, numOfBytes)
|
||||||
|
|
||||||
|
@ -109,12 +104,12 @@ procSuite "Utp integration tests":
|
||||||
readData == bytesToWrite
|
readData == bytesToWrite
|
||||||
|
|
||||||
asyncTest "Transfer 100k bytes of data over utp stream from server to client":
|
asyncTest "Transfer 100k bytes of data over utp stream from server to client":
|
||||||
# In classic uTP this would not be possible, as when uTP works over udp
|
# In classic uTP this would not be possible, as when uTP works over udp
|
||||||
# client needs to transfer first, but when working over discv5 it should be possible
|
# client needs to transfer first, but when working over discv5 it should be possible
|
||||||
# to transfer data from server to client from the start
|
# to transfer data from server to client from the start
|
||||||
let (client, clientInfo, server, serverInfo) = await setupTest()
|
let (client, clientInfo, server, serverInfo) = await setupTest()
|
||||||
let numOfBytes = 100000
|
let numOfBytes = 100000
|
||||||
let
|
let
|
||||||
clientConnectionKey = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
clientConnectionKey = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
||||||
serverConnections = await repeatTillSuccess(() => server.utp_get_connections())
|
serverConnections = await repeatTillSuccess(() => server.utp_get_connections())
|
||||||
maybeServerConnectionKey = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey.id)
|
maybeServerConnectionKey = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey.id)
|
||||||
|
@ -125,7 +120,7 @@ procSuite "Utp integration tests":
|
||||||
let serverConnectionKey = maybeServerConnectionKey.unsafeGet()
|
let serverConnectionKey = maybeServerConnectionKey.unsafeGet()
|
||||||
|
|
||||||
let
|
let
|
||||||
bytesToWrite = generateByteSeqHex(rng[], numOfBytes)
|
bytesToWrite = generateBytesHex(rng[], numOfBytes)
|
||||||
writeRes = await server.utp_write(serverConnectionKey, bytesToWrite)
|
writeRes = await server.utp_write(serverConnectionKey, bytesToWrite)
|
||||||
readData = await client.utp_read(clientConnectionKey, numOfBytes)
|
readData = await client.utp_read(clientConnectionKey, numOfBytes)
|
||||||
|
|
||||||
|
@ -136,7 +131,7 @@ procSuite "Utp integration tests":
|
||||||
asyncTest "Multiple 10k bytes transfers over utp stream":
|
asyncTest "Multiple 10k bytes transfers over utp stream":
|
||||||
let (client, clientInfo, server, serverInfo) = await setupTest()
|
let (client, clientInfo, server, serverInfo) = await setupTest()
|
||||||
let numOfBytes = 10000
|
let numOfBytes = 10000
|
||||||
let
|
let
|
||||||
clientConnectionKey = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
clientConnectionKey = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
||||||
serverConnections = await repeatTillSuccess(() => server.utp_get_connections())
|
serverConnections = await repeatTillSuccess(() => server.utp_get_connections())
|
||||||
maybeServerConnectionKey = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey.id)
|
maybeServerConnectionKey = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey.id)
|
||||||
|
@ -147,9 +142,9 @@ procSuite "Utp integration tests":
|
||||||
let serverConnectionKey = maybeServerConnectionKey.unsafeGet()
|
let serverConnectionKey = maybeServerConnectionKey.unsafeGet()
|
||||||
|
|
||||||
let
|
let
|
||||||
bytesToWrite = generateByteSeqHex(rng[], numOfBytes)
|
bytesToWrite = generateBytesHex(rng[], numOfBytes)
|
||||||
bytesToWrite1 = generateByteSeqHex(rng[], numOfBytes)
|
bytesToWrite1 = generateBytesHex(rng[], numOfBytes)
|
||||||
bytesToWrite2 = generateByteSeqHex(rng[], numOfBytes)
|
bytesToWrite2 = generateBytesHex(rng[], numOfBytes)
|
||||||
writeRes = await client.utp_write(clientConnectionKey, bytesToWrite)
|
writeRes = await client.utp_write(clientConnectionKey, bytesToWrite)
|
||||||
writeRes1 = await client.utp_write(clientConnectionKey, bytesToWrite1)
|
writeRes1 = await client.utp_write(clientConnectionKey, bytesToWrite1)
|
||||||
writeRes2 = await client.utp_write(clientConnectionKey, bytesToWrite2)
|
writeRes2 = await client.utp_write(clientConnectionKey, bytesToWrite2)
|
||||||
|
@ -166,12 +161,12 @@ procSuite "Utp integration tests":
|
||||||
asyncTest "Handle mulitplie sockets over one utp server instance ":
|
asyncTest "Handle mulitplie sockets over one utp server instance ":
|
||||||
let (client, clientInfo, server, serverInfo) = await setupTest()
|
let (client, clientInfo, server, serverInfo) = await setupTest()
|
||||||
let numOfBytes = 10000
|
let numOfBytes = 10000
|
||||||
let
|
let
|
||||||
clientConnectionKey1 = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
clientConnectionKey1 = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
||||||
clientConnectionKey2 = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
clientConnectionKey2 = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
||||||
clientConnectionKey3 = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
clientConnectionKey3 = await repeatTillSuccess(() => client.utp_connect(serverInfo.nodeEnr))
|
||||||
serverConnections = await repeatTillSuccess(() => server.utp_get_connections())
|
serverConnections = await repeatTillSuccess(() => server.utp_get_connections())
|
||||||
|
|
||||||
maybeServerConnectionKey1 = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey1.id)
|
maybeServerConnectionKey1 = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey1.id)
|
||||||
maybeServerConnectionKey2 = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey2.id)
|
maybeServerConnectionKey2 = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey2.id)
|
||||||
maybeServerConnectionKey3 = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey3.id)
|
maybeServerConnectionKey3 = serverConnections.findServerConnection(clientInfo.nodeId, clientConnectionKey3.id)
|
||||||
|
@ -186,9 +181,9 @@ procSuite "Utp integration tests":
|
||||||
let serverConnectionKey3 = maybeServerConnectionKey3.unsafeGet()
|
let serverConnectionKey3 = maybeServerConnectionKey3.unsafeGet()
|
||||||
|
|
||||||
let
|
let
|
||||||
bytesToWrite1 = generateByteSeqHex(rng[], numOfBytes)
|
bytesToWrite1 = generateBytesHex(rng[], numOfBytes)
|
||||||
bytesToWrite2 = generateByteSeqHex(rng[], numOfBytes)
|
bytesToWrite2 = generateBytesHex(rng[], numOfBytes)
|
||||||
bytesToWrite3 = generateByteSeqHex(rng[], numOfBytes)
|
bytesToWrite3 = generateBytesHex(rng[], numOfBytes)
|
||||||
|
|
||||||
writeRes1 = await client.utp_write(clientConnectionKey1, bytesToWrite1)
|
writeRes1 = await client.utp_write(clientConnectionKey1, bytesToWrite1)
|
||||||
writeRes2 = await client.utp_write(clientConnectionKey2, bytesToWrite2)
|
writeRes2 = await client.utp_write(clientConnectionKey2, bytesToWrite2)
|
||||||
|
|
|
@ -40,7 +40,7 @@ type
|
||||||
# Created accounts are tracked in this map.
|
# Created accounts are tracked in this map.
|
||||||
accounts: Table[EthAddress, PrivateKey]
|
accounts: Table[EthAddress, PrivateKey]
|
||||||
|
|
||||||
rng: ref BrHmacDrbgContext
|
rng: ref HmacDrbgContext
|
||||||
chainID: ChainID
|
chainID: ChainID
|
||||||
gasPrice: GasInt
|
gasPrice: GasInt
|
||||||
vaultKey: PrivateKey
|
vaultKey: PrivateKey
|
||||||
|
|
|
@ -19,7 +19,7 @@ type
|
||||||
am*: AccountsManager
|
am*: AccountsManager
|
||||||
# You should only create one instance of the RNG per application / library
|
# You should only create one instance of the RNG per application / library
|
||||||
# Ref is used so that it can be shared between components
|
# Ref is used so that it can be shared between components
|
||||||
rng*: ref BrHmacDrbgContext
|
rng*: ref HmacDrbgContext
|
||||||
|
|
||||||
proc newEthContext*(): EthContext =
|
proc newEthContext*(): EthContext =
|
||||||
result = new(EthContext)
|
result = new(EthContext)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[base64, json, options, os, strutils, times],
|
std/[base64, json, options, os, strutils, times],
|
||||||
bearssl,
|
bearssl/rand,
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
chronos/apps/http/httptable,
|
chronos/apps/http/httptable,
|
||||||
|
@ -54,7 +54,7 @@ type
|
||||||
JwtGenSecret* = ##\
|
JwtGenSecret* = ##\
|
||||||
## Random generator function producing a shared key. Typically, this\
|
## Random generator function producing a shared key. Typically, this\
|
||||||
## will be a wrapper around a random generator type, such as\
|
## will be a wrapper around a random generator type, such as\
|
||||||
## `BrHmacDrbgContext`.
|
## `HmacDrbgContext`.
|
||||||
proc(): JwtSharedKey {.gcsafe.}
|
proc(): JwtSharedKey {.gcsafe.}
|
||||||
|
|
||||||
JwtExcept* = object of CatchableError
|
JwtExcept* = object of CatchableError
|
||||||
|
@ -183,7 +183,7 @@ proc fromHex*(key: var JwtSharedKey, src: string): Result[void,JwtError] =
|
||||||
except ValueError:
|
except ValueError:
|
||||||
err(jwtKeyInvalidHexString)
|
err(jwtKeyInvalidHexString)
|
||||||
|
|
||||||
proc jwtGenSecret*(rng: ref BrHmacDrbgContext): JwtGenSecret =
|
proc jwtGenSecret*(rng: ref HmacDrbgContext): JwtGenSecret =
|
||||||
## Standard shared key random generator. If a fixed key is needed, a
|
## Standard shared key random generator. If a fixed key is needed, a
|
||||||
## function like
|
## function like
|
||||||
## ::
|
## ::
|
||||||
|
@ -195,7 +195,7 @@ proc jwtGenSecret*(rng: ref BrHmacDrbgContext): JwtGenSecret =
|
||||||
## only.
|
## only.
|
||||||
result = proc: JwtSharedKey =
|
result = proc: JwtSharedKey =
|
||||||
var data: array[jwtMinSecretLen,byte]
|
var data: array[jwtMinSecretLen,byte]
|
||||||
rng[].brHmacDrbgGenerate(data)
|
rng[].generate(data)
|
||||||
data.JwtSharedKey
|
data.JwtSharedKey
|
||||||
|
|
||||||
proc jwtSharedSecret*(rndSecret: JwtGenSecret; config: NimbusConf):
|
proc jwtSharedSecret*(rndSecret: JwtGenSecret; config: NimbusConf):
|
||||||
|
@ -255,7 +255,7 @@ proc jwtSharedSecret*(rndSecret: JwtGenSecret; config: NimbusConf):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return err(jwtKeyInvalidHexString)
|
return err(jwtKeyInvalidHexString)
|
||||||
|
|
||||||
proc jwtSharedSecret*(rng: ref BrHmacDrbgContext; config: NimbusConf):
|
proc jwtSharedSecret*(rng: ref HmacDrbgContext; config: NimbusConf):
|
||||||
Result[JwtSharedKey, JwtError]
|
Result[JwtSharedKey, JwtError]
|
||||||
{.gcsafe, raises: [Defect,JwtExcept].} =
|
{.gcsafe, raises: [Defect,JwtExcept].} =
|
||||||
## Variant of `jwtSharedSecret()` with explicit random generator argument.
|
## Variant of `jwtSharedSecret()` with explicit random generator argument.
|
||||||
|
|
|
@ -16,7 +16,6 @@ import
|
||||||
std/[options, strutils],
|
std/[options, strutils],
|
||||||
../utils,
|
../utils,
|
||||||
./pow/[pow_cache, pow_dataset],
|
./pow/[pow_cache, pow_dataset],
|
||||||
bearssl,
|
|
||||||
eth/[common, keys, p2p, rlp],
|
eth/[common, keys, p2p, rlp],
|
||||||
ethash,
|
ethash,
|
||||||
nimcrypto,
|
nimcrypto,
|
||||||
|
@ -63,7 +62,7 @@ type
|
||||||
|
|
||||||
# You should only create one instance of the RNG per application / library
|
# You should only create one instance of the RNG per application / library
|
||||||
# Ref is used so that it can be shared between components
|
# Ref is used so that it can be shared between components
|
||||||
rng: ref BrHmacDrbgContext
|
rng: ref HmacDrbgContext
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Private functions: RLP support
|
# Private functions: RLP support
|
||||||
|
@ -161,7 +160,7 @@ proc mineFull(tm: PowRef; blockNumber: BlockNumber; powHeaderDigest: Hash256,
|
||||||
# ---------------
|
# ---------------
|
||||||
|
|
||||||
proc init(tm: PowRef;
|
proc init(tm: PowRef;
|
||||||
rng: Option[ref BrHmacDrbgContext];
|
rng: Option[ref HmacDrbgContext];
|
||||||
light: Option[PowCacheRef];
|
light: Option[PowCacheRef];
|
||||||
full: Option[PowDatasetRef]) =
|
full: Option[PowDatasetRef]) =
|
||||||
## Constructor
|
## Constructor
|
||||||
|
@ -185,7 +184,7 @@ proc init(tm: PowRef;
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc new*(T: type PowRef;
|
proc new*(T: type PowRef;
|
||||||
rng: ref BrHmacDrbgContext;
|
rng: ref HmacDrbgContext;
|
||||||
cache: PowCacheRef;
|
cache: PowCacheRef;
|
||||||
dataset: PowDatasetRef): T =
|
dataset: PowDatasetRef): T =
|
||||||
## Constructor
|
## Constructor
|
||||||
|
@ -197,9 +196,9 @@ proc new*(T: type PowRef; cache: PowCacheRef; dataset: PowDatasetRef): T =
|
||||||
## Constructor
|
## Constructor
|
||||||
new result
|
new result
|
||||||
result.init(
|
result.init(
|
||||||
none(ref BrHmacDrbgContext), some(cache), some(dataset))
|
none(ref HmacDrbgContext), some(cache), some(dataset))
|
||||||
|
|
||||||
proc new*(T: type PowRef; rng: ref BrHmacDrbgContext): T =
|
proc new*(T: type PowRef; rng: ref HmacDrbgContext): T =
|
||||||
## Constructor
|
## Constructor
|
||||||
new result
|
new result
|
||||||
result.init(
|
result.init(
|
||||||
|
@ -209,7 +208,7 @@ proc new*(T: type PowRef): T =
|
||||||
## Constructor
|
## Constructor
|
||||||
new result
|
new result
|
||||||
result.init(
|
result.init(
|
||||||
none(ref BrHmacDrbgContext), none(PowCacheRef), none(PowDatasetRef))
|
none(ref HmacDrbgContext), none(PowCacheRef), none(PowDatasetRef))
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions
|
# Public functions
|
||||||
|
@ -298,7 +297,7 @@ proc getNonce*(tm: PowRef; number: BlockNumber; powHeaderDigest: Hash256;
|
||||||
{.gcsafe,raises: [Defect,CatchableError].} =
|
{.gcsafe,raises: [Defect,CatchableError].} =
|
||||||
## Variant of `getNonce()`
|
## Variant of `getNonce()`
|
||||||
var startNonce: array[8,byte]
|
var startNonce: array[8,byte]
|
||||||
tm.rng[].brHmacDrbgGenerate(startNonce)
|
tm.rng[].generate(startNonce)
|
||||||
tm.getNonce(number, powHeaderDigest, difficulty, startNonce)
|
tm.getNonce(number, powHeaderDigest, difficulty, startNonce)
|
||||||
|
|
||||||
proc getNonce*(tm: PowRef; header: BlockHeader): BlockNonce
|
proc getNonce*(tm: PowRef; header: BlockHeader): BlockNonce
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 65b74302e03912ab5bde64b6da10d05896139007
|
Subproject commit 32e125015ae4251675763842366380795a91b722
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8761ea3222f8d4fbd7ebae6755665e791499d7f2
|
Subproject commit 2c08626ed8261fa18adc22eaf465b57931b88a65
|
Loading…
Reference in New Issue