Stuff works
This commit is contained in:
@@ -58,7 +58,7 @@ public static class Encryption
|
||||
/// <returns>the decrypted bytes</returns>
|
||||
public static byte[] Decrypt(byte[] encryptedData, string udId)
|
||||
{
|
||||
using (var rj = new RijndaelManaged())
|
||||
using (var rj = Aes.Create())
|
||||
{
|
||||
rj.KeySize = EncryptionKeySize;
|
||||
rj.Mode = EncryptionMode;
|
||||
@@ -71,16 +71,8 @@ public static class Encryption
|
||||
Array.Copy(encryptedData, 0, encryptedValueBytes, 0, encryptedValueBytes.Length);
|
||||
ICryptoTransform transform = rj.CreateDecryptor(keyBytes, rgbIv);
|
||||
byte[] decryptedValueBytes = new byte[encryptedValueBytes.Length];
|
||||
using (MemoryStream ms = new MemoryStream(encryptedValueBytes))
|
||||
{
|
||||
using (CryptoStream cs = new CryptoStream(ms, transform, CryptoStreamMode.Read))
|
||||
{
|
||||
cs.CopyTo(decryptedValueBytes);
|
||||
cs.Flush();
|
||||
ms.Flush();
|
||||
}
|
||||
}
|
||||
return decryptedValueBytes;
|
||||
rj.Key = keyBytes;
|
||||
return rj.DecryptCbc(encryptedValueBytes, rgbIv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using SVSim.Database.Enums;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.EmulatedEntrypoint.Constants;
|
||||
using SVSim.EmulatedEntrypoint.Extensions;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
|
||||
using SVSim.EmulatedEntrypoint.Services;
|
||||
|
||||
@@ -26,18 +27,28 @@ public class SteamSessionAuthenticationHandler : AuthenticationHandler<SteamAuth
|
||||
protected async override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
{
|
||||
byte[] requestBytes;
|
||||
using (var requestBytesStream = new MemoryStream())
|
||||
try
|
||||
{
|
||||
await Request.Body.CopyToAsync(requestBytesStream);
|
||||
requestBytes = requestBytesStream.ToArray();
|
||||
using (var requestBytesStream = new MemoryStream())
|
||||
{
|
||||
// Reset request stream
|
||||
Request.Body.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
await Request.Body.CopyToAsync(requestBytesStream);
|
||||
requestBytes = requestBytesStream.ToArray();
|
||||
|
||||
// Reset request stream
|
||||
Request.Body.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return AuthenticateResult.Fail("Failed to read request body.");
|
||||
}
|
||||
|
||||
// Convert bytes to json
|
||||
string requestString = Encoding.UTF8.GetString(requestBytes);
|
||||
BaseRequest? requestJson = JsonConvert.DeserializeObject<BaseRequest>(requestString);
|
||||
|
||||
// Reset request stream
|
||||
Request.Body.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
if (requestJson is null)
|
||||
{
|
||||
@@ -58,9 +69,12 @@ public class SteamSessionAuthenticationHandler : AuthenticationHandler<SteamAuth
|
||||
{
|
||||
return AuthenticateResult.Fail("User not found.");
|
||||
}
|
||||
|
||||
// Add viewer to context
|
||||
Context.SetViewer(viewer);
|
||||
|
||||
// Build identity
|
||||
ClaimsIdentity identity = new ClaimsIdentity();
|
||||
ClaimsIdentity identity = new ClaimsIdentity(SteamAuthenticationConstants.SchemeName);
|
||||
identity.AddClaim(new Claim(ClaimTypes.Name, viewer.DisplayName));
|
||||
identity.AddClaim(new Claim(ShadowverseClaimTypes.ShortUdidClaim, viewer.ShortUdid.ToString()));
|
||||
identity.AddClaim(new Claim(ShadowverseClaimTypes.ViewerIdClaim, viewer.Id.ToString()));
|
||||
@@ -68,7 +82,7 @@ public class SteamSessionAuthenticationHandler : AuthenticationHandler<SteamAuth
|
||||
|
||||
// Build and return final ticket
|
||||
AuthenticationTicket ticket =
|
||||
new AuthenticationTicket(new ClaimsPrincipal(), SteamAuthenticationConstants.SchemeName);
|
||||
new AuthenticationTicket(new ClaimsPrincipal(identity), SteamAuthenticationConstants.SchemeName);
|
||||
return AuthenticateResult.Success(ticket);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user