Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Tune the logic of sending verification request to verifiers. #194

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add timestamp field to VerificationRequest for replay attack prevention.
leopold-portkey committed Feb 22, 2024
commit 0be77b89cba888d2f3ca19e57df37db8a3b402af
Original file line number Diff line number Diff line change
@@ -22,14 +22,15 @@ public static partial class VerificationRequestReflection {
static VerificationRequestReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"Chp2ZXJpZmljYXRpb25fcmVxdWVzdC5wcm90bxoPYWVsZi9jb3JlLnByb3Rv",
"Il0KE1ZlcmlmaWNhdGlvblJlcXVlc3QSDAoEdHlwZRgBIAEoCRIbChNndWFy",
"ZGlhbl9pZGVudGlmaWVyGAIgASgJEhsKE3ZlcmlmaWVyX3Nlc3Npb25faWQY",
"AyABKAliBnByb3RvMw=="));
"Chp2ZXJpZmljYXRpb25fcmVxdWVzdC5wcm90bxofZ29vZ2xlL3Byb3RvYnVm",
"L3RpbWVzdGFtcC5wcm90byKMAQoTVmVyaWZpY2F0aW9uUmVxdWVzdBIMCgR0",
"eXBlGAEgASgJEhsKE2d1YXJkaWFuX2lkZW50aWZpZXIYAiABKAkSGwoTdmVy",
"aWZpZXJfc2Vzc2lvbl9pZBgDIAEoCRItCgl0aW1lc3RhbXAYBCABKAsyGi5n",
"b29nbGUucHJvdG9idWYuVGltZXN0YW1wYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::AElf.Types.CoreReflection.Descriptor, },
new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::VerificationRequest), global::VerificationRequest.Parser, new[]{ "Type", "GuardianIdentifier", "VerifierSessionId" }, null, null, null, null)
new pbr::GeneratedClrTypeInfo(typeof(global::VerificationRequest), global::VerificationRequest.Parser, new[]{ "Type", "GuardianIdentifier", "VerifierSessionId", "Timestamp" }, null, null, null, null)
}));
}
#endregion
@@ -73,6 +74,7 @@ public VerificationRequest(VerificationRequest other) : this() {
type_ = other.type_;
guardianIdentifier_ = other.guardianIdentifier_;
verifierSessionId_ = other.verifierSessionId_;
timestamp_ = other.timestamp_ != null ? other.timestamp_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}

@@ -118,6 +120,18 @@ public string VerifierSessionId {
}
}

/// <summary>Field number for the "timestamp" field.</summary>
public const int TimestampFieldNumber = 4;
private global::Google.Protobuf.WellKnownTypes.Timestamp timestamp_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public global::Google.Protobuf.WellKnownTypes.Timestamp Timestamp {
get { return timestamp_; }
set {
timestamp_ = value;
}
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
@@ -136,6 +150,7 @@ public bool Equals(VerificationRequest other) {
if (Type != other.Type) return false;
if (GuardianIdentifier != other.GuardianIdentifier) return false;
if (VerifierSessionId != other.VerifierSessionId) return false;
if (!object.Equals(Timestamp, other.Timestamp)) return false;
return Equals(_unknownFields, other._unknownFields);
}

@@ -146,6 +161,7 @@ public override int GetHashCode() {
if (Type.Length != 0) hash ^= Type.GetHashCode();
if (GuardianIdentifier.Length != 0) hash ^= GuardianIdentifier.GetHashCode();
if (VerifierSessionId.Length != 0) hash ^= VerifierSessionId.GetHashCode();
if (timestamp_ != null) hash ^= Timestamp.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@@ -176,6 +192,10 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(26);
output.WriteString(VerifierSessionId);
}
if (timestamp_ != null) {
output.WriteRawTag(34);
output.WriteMessage(Timestamp);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
@@ -198,6 +218,10 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(26);
output.WriteString(VerifierSessionId);
}
if (timestamp_ != null) {
output.WriteRawTag(34);
output.WriteMessage(Timestamp);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
@@ -217,6 +241,9 @@ public int CalculateSize() {
if (VerifierSessionId.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(VerifierSessionId);
}
if (timestamp_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Timestamp);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
@@ -238,6 +265,12 @@ public void MergeFrom(VerificationRequest other) {
if (other.VerifierSessionId.Length != 0) {
VerifierSessionId = other.VerifierSessionId;
}
if (other.timestamp_ != null) {
if (timestamp_ == null) {
Timestamp = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
Timestamp.MergeFrom(other.Timestamp);
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}

@@ -265,6 +298,13 @@ public void MergeFrom(pb::CodedInputStream input) {
VerifierSessionId = input.ReadString();
break;
}
case 34: {
if (timestamp_ == null) {
Timestamp = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
input.ReadMessage(Timestamp);
break;
}
}
}
#endif
@@ -292,6 +332,13 @@ public void MergeFrom(pb::CodedInputStream input) {
VerifierSessionId = input.ReadString();
break;
}
case 34: {
if (timestamp_ == null) {
Timestamp = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
input.ReadMessage(Timestamp);
break;
}
}
}
}
4 changes: 3 additions & 1 deletion src/CAServer.Application/Verifier/VerifierServerClient.cs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using System.Threading.Tasks;
using AElf;
using AElf.Cryptography;
using AElf.Kernel;
using CAServer.Common;
using CAServer.Dtos;
using CAServer.Options;
@@ -80,7 +81,8 @@ public async Task<ResponseResultDto<VerifierServerResponse>> SendVerificationReq
{
Type = dto.Type,
GuardianIdentifier = dto.GuardianIdentifier,
VerifierSessionId = dto.VerifierSessionId.ToString()
VerifierSessionId = dto.VerifierSessionId.ToString(),
Timestamp = TimestampHelper.GetUtcNow()
};
var hash = HashHelper.ComputeFrom(verificationRequest);
var privateKey = _chainOptions.ChainInfos.FirstOrDefault(i => i.Key == dto.ChainId).Value.PrivateKey;