-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Linwenxuan
authored and
Linwenxuan
committed
Jan 26, 2024
1 parent
ba29128
commit e388d5b
Showing
9 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Lagrange.Core.Event.EventArg; | ||
|
||
public class BotNewDeviceVerifyEvent : EventBase | ||
{ | ||
public string Url { get; } | ||
|
||
public byte[] QrCode { get; } | ||
|
||
public BotNewDeviceVerifyEvent(string url, byte[] qrCode) | ||
{ | ||
Url = url; | ||
EventMessage = $"[{nameof(BotNewDeviceVerifyEvent)}]: Url: {url}"; | ||
QrCode = qrCode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Lagrange.Core.Internal.Event.Login; | ||
|
||
internal class NewDeviceLoginEvent : ProtocolEvent | ||
{ | ||
public bool Success { get; set; } | ||
|
||
private NewDeviceLoginEvent() : base(true) { } | ||
|
||
private NewDeviceLoginEvent(int result) : base(result) | ||
{ | ||
Success = result == 0; | ||
} | ||
|
||
public static NewDeviceLoginEvent Create() => new(); | ||
|
||
public static NewDeviceLoginEvent Result(int result) => new(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Lagrange.Core/Internal/Service/Login/NewDeviceLoginService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Lagrange.Core.Common; | ||
using Lagrange.Core.Internal.Event; | ||
using Lagrange.Core.Internal.Event.Login; | ||
using Lagrange.Core.Internal.Packets.Login.NTLogin; | ||
using Lagrange.Core.Internal.Packets.Login.NTLogin.Plain; | ||
using Lagrange.Core.Internal.Packets.Login.NTLogin.Plain.Body; | ||
using Lagrange.Core.Utility.Binary; | ||
using Lagrange.Core.Utility.Crypto; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Service.Login; | ||
|
||
[Service("trpc.login.ecdh.EcdhService.SsoNTLoginPasswordLoginNewDevice")] | ||
internal class NewDeviceLoginService : BaseService<NewDeviceLoginEvent> | ||
{ | ||
protected override bool Build(NewDeviceLoginEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out BinaryPacket output, out List<BinaryPacket>? extraPackets) | ||
{ | ||
if (keystore.Session.TempPassword == null) throw new InvalidOperationException("TempPassword is null"); | ||
|
||
output = SsoNTLoginCommon.BuildNTLoginPacket(keystore, appInfo, device, keystore.Session.TempPassword); | ||
extraPackets = null; | ||
return true; | ||
} | ||
|
||
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out NewDeviceLoginEvent output, out List<ProtocolEvent>? extraEvents) | ||
{ | ||
if (keystore.Session.ExchangeKey == null) throw new InvalidOperationException("ExchangeKey is null"); | ||
|
||
var encrypted = Serializer.Deserialize<SsoNTLoginEncryptedData>(input.AsSpan()); | ||
|
||
if (encrypted.GcmCalc != null) | ||
{ | ||
var decrypted = new AesGcmImpl().Decrypt(encrypted.GcmCalc, keystore.Session.ExchangeKey); | ||
var response = Serializer.Deserialize<SsoNTLoginBase<SsoNTLoginResponse>>(decrypted.AsSpan()); | ||
var body = response.Body; | ||
|
||
if (response.Header?.Error != null || body is not { Credentials: not null }) | ||
{ | ||
output = NewDeviceLoginEvent.Result((int)(response.Header?.Error?.ErrorCode ?? 1)); | ||
} | ||
else | ||
{ | ||
keystore.Session.Tgt = body.Credentials.Tgt; | ||
keystore.Session.D2 = body.Credentials.D2; | ||
keystore.Session.D2Key = body.Credentials.D2Key; | ||
keystore.Session.TempPassword = body.Credentials.TempPassword; | ||
|
||
output = NewDeviceLoginEvent.Result(0); | ||
} | ||
} | ||
else | ||
{ | ||
output = NewDeviceLoginEvent.Result(1); | ||
} | ||
|
||
extraEvents = null; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters