Added package length validation

This commit is contained in:
Yuriy Glukhov 2019-03-25 11:20:53 +02:00
parent f0bf0570d1
commit d1e713cfb3
No known key found for this signature in database
GPG Key ID: 733560674BB43E6C
1 changed files with 7 additions and 5 deletions

View File

@ -86,11 +86,13 @@ proc pack(cmdId: CommandId, payload: BytesRange, pk: PrivateKey): Bytes =
result = @(msgHash.data) & signature & encodedData result = @(msgHash.data) & signature & encodedData
proc validateMsgHash(msg: Bytes, msgHash: var MDigest[256]): bool = proc validateMsgHash(msg: Bytes, msgHash: var MDigest[256]): bool =
if msg.len > HEAD_SIZE:
msgHash.data[0 .. ^1] = msg.toOpenArray(0, msgHash.data.high) msgHash.data[0 .. ^1] = msg.toOpenArray(0, msgHash.data.high)
result = msgHash == keccak256.digest(msg.toOpenArray(MAC_SIZE, msg.high)) result = msgHash == keccak256.digest(msg.toOpenArray(MAC_SIZE, msg.high))
proc recoverMsgPublicKey(msg: Bytes, pk: var PublicKey): bool = proc recoverMsgPublicKey(msg: Bytes, pk: var PublicKey): bool =
recoverSignatureKey(msg.toOpenArray(MAC_SIZE, MAC_SIZE + 65), msg.len > HEAD_SIZE and
recoverSignatureKey(msg.toOpenArray(MAC_SIZE, HEAD_SIZE),
keccak256.digest(msg.toOpenArray(HEAD_SIZE, msg.high)).data, keccak256.digest(msg.toOpenArray(HEAD_SIZE, msg.high)).data,
pk) == EthKeysStatus.Success pk) == EthKeysStatus.Success