[#13] Client: Use code analyzers
All checks were successful
DCO / DCO (pull_request) Successful in 35s
All checks were successful
DCO / DCO (pull_request) Successful in 35s
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
d7dbbf8da8
commit
d1271df207
102 changed files with 2168 additions and 733 deletions
|
@ -45,7 +45,7 @@ public static class Verifier
|
|||
var ecParameters = new ECDomainParameters(secp256R1.Curve, secp256R1.G, secp256R1.N);
|
||||
var bcPublicKey = new ECPublicKeyParameters(secp256R1.Curve.DecodePoint(publicKey), ecParameters);
|
||||
var hash = new byte[digest.GetDigestSize()];
|
||||
|
||||
|
||||
digest.BlockUpdate(data, 0, data.Length);
|
||||
digest.DoFinal(hash, 0);
|
||||
signer.Init(false, bcPublicKey);
|
||||
|
@ -55,11 +55,25 @@ public static class Verifier
|
|||
|
||||
public static bool VerifyRFC6979(this SignatureRFC6979 signature, IMessage message)
|
||||
{
|
||||
if (signature is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(signature));
|
||||
}
|
||||
|
||||
return signature.Key.ToByteArray().VerifyRFC6979(message.ToByteArray(), signature.Sign.ToByteArray());
|
||||
}
|
||||
|
||||
public static bool VerifyData(this ECDsa key, byte[] data, byte[] sig)
|
||||
{
|
||||
if (key is null)
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
|
||||
if (data is null)
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
|
||||
if (sig is null)
|
||||
throw new ArgumentNullException(nameof(sig));
|
||||
|
||||
return key.VerifyHash(data.Sha512(), sig[1..]);
|
||||
}
|
||||
|
||||
|
@ -70,36 +84,41 @@ public static class Verifier
|
|||
|
||||
using var key = sig.Key.ToByteArray().LoadPublicKey();
|
||||
var data2Verify = data is null ? [] : data.ToByteArray();
|
||||
|
||||
|
||||
return key.VerifyData(data2Verify, sig.Sign.ToByteArray());
|
||||
}
|
||||
|
||||
public static bool VerifyMatryoskaLevel(IMessage body, IMetaHeader meta, IVerificationHeader verification)
|
||||
internal static bool VerifyMatryoskaLevel(IMessage body, IMetaHeader meta, IVerificationHeader verification)
|
||||
{
|
||||
if (!verification.MetaSignature.VerifyMessagePart(meta))
|
||||
if (!verification.MetaSignature.VerifyMessagePart(meta))
|
||||
return false;
|
||||
|
||||
|
||||
var origin = verification.GetOrigin();
|
||||
|
||||
if (!verification.OriginSignature.VerifyMessagePart(origin))
|
||||
|
||||
if (!verification.OriginSignature.VerifyMessagePart(origin))
|
||||
return false;
|
||||
|
||||
|
||||
if (origin is null)
|
||||
return verification.BodySignature.VerifyMessagePart(body);
|
||||
|
||||
|
||||
return verification.BodySignature is null && VerifyMatryoskaLevel(body, meta.GetOrigin(), origin);
|
||||
}
|
||||
|
||||
public static bool Verify(this IVerifiableMessage message)
|
||||
{
|
||||
if (message is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
|
||||
return VerifyMatryoskaLevel(message.GetBody(), message.GetMetaHeader(), message.GetVerificationHeader());
|
||||
}
|
||||
|
||||
public static void CheckResponse(IResponse resp)
|
||||
internal static void CheckResponse(IResponse resp)
|
||||
{
|
||||
if (!resp.Verify())
|
||||
throw new FormatException($"invalid response, type={resp.GetType()}");
|
||||
|
||||
|
||||
var status = resp.MetaHeader.Status.ToModel();
|
||||
|
||||
if (status != null && !status.IsSuccess)
|
||||
|
@ -112,6 +131,11 @@ public static class Verifier
|
|||
/// <param name="request">Created by SDK request to gRpc proxy</param>
|
||||
public static void CheckRequest(IRequest request)
|
||||
{
|
||||
if (request is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (!request.Verify())
|
||||
throw new FormatException($"invalid response, type={request.GetType()}");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue