Skip to content

Commit

Permalink
Merge pull request #231 from onerain88/fix-rtm-signature
Browse files Browse the repository at this point in the history
fix: signature check
  • Loading branch information
onerain88 authored Oct 26, 2022
2 parents 52987fd + 0d7fb49 commit ee172e6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 37 deletions.
31 changes: 16 additions & 15 deletions Realtime/Realtime.Test/LocalSignatureFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Realtime.Test {
public class LocalSignatureFactory : ILCIMSignatureFactory {
const string MasterKey = "VFbnm4iaAdqQPzAdXT2M8KjP";
const string MasterKey = "8Z0R6fd5eohDAHlgtiRgpkAu";

public Task<LCIMSignature> CreateConnectSignature(string clientId) {
long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
Expand Down Expand Up @@ -57,20 +57,21 @@ public Task<LCIMSignature> CreateConversationSignature(string conversationId, st
}

public Task<LCIMSignature> CreateBlacklistSignature(string conversationId, string clientId, IEnumerable<string> memberIds, string action) {
string sortedMemberIds = string.Empty;
if (memberIds != null) {
List<string> sortedMemberList = memberIds.ToList();
sortedMemberList.Sort();
sortedMemberIds = string.Join(":", sortedMemberList);
}
long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
string nonce = NewNonce();
string signature = GenerateSignature(LCCore.AppId, clientId, conversationId, sortedMemberIds, timestamp.ToString(), nonce, action);
return Task.FromResult(new LCIMSignature {
Signature = signature,
Timestamp = timestamp,
Nonce = nonce
});
//string sortedMemberIds = string.Empty;
//if (memberIds != null) {
// List<string> sortedMemberList = memberIds.ToList();
// sortedMemberList.Sort();
// sortedMemberIds = string.Join(":", sortedMemberList);
//}
//long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
//string nonce = NewNonce();
//string signature = GenerateSignature(LCCore.AppId, clientId, conversationId, sortedMemberIds, timestamp.ToString(), nonce, action);
//return Task.FromResult(new LCIMSignature {
// Signature = signature,
// Timestamp = timestamp,
// Nonce = nonce
//});
return Task.FromResult<LCIMSignature>(null);
}

private static string SignSHA1(string key, string text) {
Expand Down
6 changes: 3 additions & 3 deletions Realtime/Realtime.Test/Signature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace Realtime.Test {
public class Signature {
internal const string AppId = "3zWMOXuO9iSdnjXM942i6DdI-gzGzoHsz";
internal const string AppKey = "bkwiNq4Tj417eUaHlTWS5sPm";
internal const string AppServer = "https://3zwmoxuo.lc-cn-n1-shared.com";
internal const string AppId = "7oDgNicekFVXBMkRKcLpvX5w-gzGzoHsz";
internal const string AppKey = "tPT17REZjS3DfjTJodw6fJzj";
internal const string AppServer = "https://7odgnice.lc-cn-n1-shared.com";

private LCIMClient hello;
private LCIMClient world;
Expand Down
40 changes: 25 additions & 15 deletions Realtime/Realtime/Internal/Controller/LCIMConversationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ internal async Task<LCIMConversation> CreateConv(
};
if (Client.SignatureFactory != null) {
LCIMSignature signature = await Client.SignatureFactory.CreateStartConversationSignature(Client.Id, members);
conv.S = signature.Signature;
conv.T = signature.Timestamp;
conv.N = signature.Nonce;
if (signature != null && signature.IsValid) {
conv.S = signature.Signature;
conv.T = signature.Timestamp;
conv.N = signature.Nonce;
}
}
request.ConvMessage = conv;
GenericCommand response = await Connection.SendRequest(request);
Expand Down Expand Up @@ -138,9 +140,11 @@ internal async Task<LCIMPartiallySuccessResult> AddMembers(string convId,
Client.Id,
clientIds,
LCIMSignatureAction.Invite);
conv.S = signature.Signature;
conv.T = signature.Timestamp;
conv.N = signature.Nonce;
if (signature != null && signature.IsValid) {
conv.S = signature.Signature;
conv.T = signature.Timestamp;
conv.N = signature.Nonce;
}
}
GenericCommand request = NewCommand(CommandType.Conv, OpType.Add);
request.ConvMessage = conv;
Expand All @@ -163,9 +167,11 @@ internal async Task<LCIMPartiallySuccessResult> RemoveMembers(string convId,
Client.Id,
removeIds,
LCIMSignatureAction.Kick);
conv.S = signature.Signature;
conv.T = signature.Timestamp;
conv.N = signature.Nonce;
if (signature != null && signature.IsValid) {
conv.S = signature.Signature;
conv.T = signature.Timestamp;
conv.N = signature.Nonce;
}
}
GenericCommand request = NewCommand(CommandType.Conv, OpType.Remove);
request.ConvMessage = conv;
Expand Down Expand Up @@ -234,9 +240,11 @@ internal async Task<LCIMPartiallySuccessResult> BlockMembers(string convId,
Client.Id,
clientIds,
LCIMSignatureAction.ConversationBlockClients);
blacklist.S = signature.Signature;
blacklist.T = signature.Timestamp;
blacklist.N = signature.Nonce;
if (signature != null && signature.IsValid) {
blacklist.S = signature.Signature;
blacklist.T = signature.Timestamp;
blacklist.N = signature.Nonce;
}
}
GenericCommand request = NewCommand(CommandType.Blacklist, OpType.Block);
request.BlacklistMessage = blacklist;
Expand All @@ -256,9 +264,11 @@ internal async Task<LCIMPartiallySuccessResult> UnblockMembers(string convId,
Client.Id,
clientIds,
LCIMSignatureAction.ConversationUnblockClients);
blacklist.S = signature.Signature;
blacklist.T = signature.Timestamp;
blacklist.N = signature.Nonce;
if (signature != null && signature.IsValid) {
blacklist.S = signature.Signature;
blacklist.T = signature.Timestamp;
blacklist.N = signature.Nonce;
}
}
GenericCommand request = NewCommand(CommandType.Blacklist, OpType.Unblock);
request.BlacklistMessage = blacklist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private async Task<SessionCommand> NewSessionCommand() {
Nonce = ret["nonce"] as string
};
}
if (signature != null) {
if (signature != null && signature.IsValid) {
session.S = signature.Signature;
session.T = signature.Timestamp;
session.N = signature.Nonce;
Expand Down
5 changes: 5 additions & 0 deletions Realtime/Realtime/Public/Signature/LCIMSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ public long Timestamp {
public string Nonce {
get; set;
}

public bool IsValid =>
!string.IsNullOrEmpty(Signature) &&
!string.IsNullOrEmpty(Nonce) &&
Timestamp > 0;
}
}
9 changes: 6 additions & 3 deletions Storage/Storage.Test/FileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class FileTest : BaseTest {
static readonly string APKFilePath = "../../../../../assets/test.apk";
static readonly string VideoFilePath = "../../../../../assets/video.mp4";

static readonly string US_APP_ID = "ldCRr8t23k3ydo7FxmJlKQmn-MdYXbMMI";
static readonly string US_APP_KEY = "GwQDHkmsQTSF2ZXWegzXio5F";
static readonly string US_SERVER = "https://ldcrr8t2.api.lncldglobal.com";

private LCFile video;

[Test]
Expand Down Expand Up @@ -109,7 +113,7 @@ public async Task FileACL() {
[Test]
[Order(10)]
public async Task AWS() {
LCApplication.Initialize("HudJvWWmAuGMifwxByDVLmQi-MdYXbMMI", "YjoQr1X8wHoFIfsSGXzeJaAM");
LCApplication.Initialize(US_APP_ID, US_APP_KEY);
LCFile file = new LCFile("avatar.png", AvatarFilePath);
await file.Save((count, total) => {
TestContext.WriteLine($"progress: {count}/{total}");
Expand All @@ -121,8 +125,7 @@ await file.Save((count, total) => {
[Test]
[Order(11)]
public async Task AWSBigFile() {
LCApplication.Initialize("HudJvWWmAuGMifwxByDVLmQi-MdYXbMMI", "YjoQr1X8wHoFIfsSGXzeJaAM",
"https://hudjvwwm.api.lncldglobal.com");
LCApplication.Initialize(US_APP_ID, US_APP_KEY, US_SERVER);
LCFile file = new LCFile("video.mp4", VideoFilePath);
await file.Save((count, total) => {
TestContext.WriteLine($"progress: {count}/{total}");
Expand Down

0 comments on commit ee172e6

Please sign in to comment.