1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Fixed multiple warnings and deprecations

This commit is contained in:
Uncled1023 2022-05-22 20:51:09 -07:00
parent f31a42d40d
commit 0f410485f4
12 changed files with 38 additions and 35 deletions

View File

@ -50,7 +50,7 @@ namespace Teknik.BillingService
if (options.SyncSubscriptions)
{
// Sync subscription information
SyncSubscriptions(config, db);
SyncSubscriptions(config, db).Wait();
}
}

View File

@ -36,5 +36,10 @@ namespace Teknik.IdentityServer
}
}
}
public bool Exists<T>(T entity) where T : class
{
return this.Set<T>().Local.Any(e => e == entity);
}
}
}

View File

@ -731,7 +731,7 @@ namespace Teknik.IdentityServer.Controllers
}
[HttpGet]
public async Task<IActionResult> GetAuthTokens(string username)
public async Task<IActionResult> GetAuthTokens(string username, [FromServices] ApplicationDbContext dbContext)
{
if (string.IsNullOrEmpty(username))
return new JsonResult(new { success = false, message = "Username is required" });
@ -739,6 +739,9 @@ namespace Teknik.IdentityServer.Controllers
var foundUser = await GetCachedUser(username);
if (foundUser != null)
{
if (!dbContext.Exists(foundUser))
dbContext.Attach(foundUser);
var authTokens = foundUser.AuthTokens.Select(t => new { authTokenId = t.AuthTokenId, name = t.Name, token = t.Token, lastUsed = t.LastUsed }).ToList();
return new JsonResult(new { success = true, data = authTokens });
}
@ -746,15 +749,18 @@ namespace Teknik.IdentityServer.Controllers
}
[HttpPost]
public IActionResult CreateAuthToken(CreateAuthTokenModel model, [FromServices] ApplicationDbContext dbContext)
public async Task<IActionResult> CreateAuthToken(CreateAuthTokenModel model, [FromServices] ApplicationDbContext dbContext)
{
if (string.IsNullOrEmpty(model.Username))
return new JsonResult(new { success = false, message = "Username is required" });
var foundUser = dbContext.Users.FirstOrDefault(u => u.UserName == model.Username);
var foundUser = await GetCachedUser(model.Username);
if (foundUser != null)
{
if (!dbContext.Exists(foundUser))
dbContext.Attach(foundUser);
// Generate a unique token
var token = StringHelper.RandomString(40, "abcdefghjkmnpqrstuvwxyz1234567890");
while (dbContext.AuthTokens.FirstOrDefault(t => t.Token == token) != null)

View File

@ -4,7 +4,7 @@
@using Teknik.Utilities
@using Teknik.Utilities.TagHelpers
@inject Microsoft.AspNetCore.Hosting.IHostingEnvironment HostingEnvironment
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@inject Config Config
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -111,7 +111,7 @@ namespace Teknik.Areas.Help.Controllers
}
[AllowAnonymous]
public async Task<IActionResult> Upload()
public IActionResult Upload()
{
ViewBag.Title = "Upload Service Help";
UploadHelpViewModel model = new UploadHelpViewModel();

View File

@ -52,9 +52,12 @@ namespace Teknik.Attributes
// Fire and forget. Don't need to wait for it.
_queue.QueueBackgroundWorkItem(async token =>
{
await Task.Run(() =>
{
Tracking.Tracking.TrackDownload(filterContext.HttpContext, _config, userAgent, clientIp, url, urlReferrer);
});
});
}
}
}

View File

@ -97,7 +97,7 @@ namespace Teknik.Controllers
using (var writer = new StringWriter())
{
string path = (new Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
string path = (new Uri(Assembly.GetExecutingAssembly().Location)).AbsolutePath;
ViewEngineResult viewResult =
viewEngine.GetView(path, viewName, false);

View File

@ -21,7 +21,7 @@ namespace Teknik.Utilities.Cryptography
}
}
public static byte[] Encrypt(RijndaelManaged cipher, byte[] value)
public static byte[] Encrypt(Aes cipher, byte[] value)
{
byte[] encryptedBytes;
using (var encryptor = cipher.CreateEncryptor())
@ -37,7 +37,7 @@ namespace Teknik.Utilities.Cryptography
return encryptedBytes;
}
public static byte[] Decrypt(RijndaelManaged cipher, byte[] value)
public static byte[] Decrypt(Aes cipher, byte[] value)
{
byte[] decryptedBytes;
using (var decryptor = cipher.CreateDecryptor())
@ -53,9 +53,9 @@ namespace Teknik.Utilities.Cryptography
return decryptedBytes;
}
public static RijndaelManaged CreateCipher(byte[] key, byte[] iv, int keyLength, int blockSize, int feedbackSize, CipherMode mode, PaddingMode paddingMode)
public static Aes CreateCipher(byte[] key, byte[] iv, int keyLength, int blockSize, int feedbackSize, CipherMode mode, PaddingMode paddingMode)
{
RijndaelManaged cipher = new RijndaelManaged();
Aes cipher = Aes.Create();
cipher.Mode = mode;
cipher.Padding = paddingMode;
cipher.Key = key;

View File

@ -60,7 +60,7 @@ namespace Teknik.Utilities.Cryptography
public static void ProcessCipher(bool encrypt, byte[] text, byte[] key, byte[] iv, int blockSize, int keySize, ref byte[] output, int offset)
{
using (var cipher = new RijndaelManaged())
using (var cipher = Aes.Create())
{
cipher.BlockSize = blockSize;
cipher.KeySize = keySize;

View File

@ -8,7 +8,7 @@ namespace Teknik.Utilities.Cryptography
// Internal Variables
private const int _BlockSize = 16;
private readonly byte[] _InitialCounter;
private readonly AesManaged _Algo;
private readonly Aes _Algo;
public AesCounterMode() : this(new byte[_BlockSize]) { }
@ -20,11 +20,9 @@ namespace Teknik.Utilities.Cryptography
initialCounter.Length, _BlockSize));
// Generate a new instance of the Aes Algorithm in ECB mode with no padding
_Algo = new AesManaged
{
Mode = CipherMode.ECB,
Padding = PaddingMode.None
};
_Algo = Aes.Create();
_Algo.Mode = CipherMode.ECB;
_Algo.Padding = PaddingMode.None;
// Set the internal variables
_InitialCounter = initialCounter;

View File

@ -15,7 +15,7 @@ namespace Teknik.Utilities.Cryptography
public static string Hash(byte[] value)
{
HashAlgorithm hash = new SHA256CryptoServiceProvider();
var hash = System.Security.Cryptography.SHA256.Create();
byte[] hashBytes = hash.ComputeHash(value);
return Convert.ToBase64String(hashBytes);
@ -23,20 +23,20 @@ namespace Teknik.Utilities.Cryptography
public static byte[] Hash(Stream value)
{
HashAlgorithm hash = new SHA256CryptoServiceProvider();
var hash = System.Security.Cryptography.SHA256.Create();
return hash.ComputeHash(value);
}
public static string Hash(string value, string salt1, string salt2)
{
SHA256Managed hash = new SHA256Managed();
var hash = System.Security.Cryptography.SHA256.Create();
// gen salt2 hash
byte[] dataSalt2 = Encoding.UTF8.GetBytes(salt2);
byte[] salt2Bytes = hash.ComputeHash(dataSalt2);
string salt2Str = string.Empty;
foreach (byte x in salt2Bytes)
{
salt2Str += String.Format("{0:x2}", x);
salt2Str += string.Format("{0:x2}", x);
}
string dataStr = salt1 + value + salt2Str;
string sha1Str = SHA1.Hash(dataStr);
@ -45,19 +45,9 @@ namespace Teknik.Utilities.Cryptography
string hashString = string.Empty;
foreach (byte x in valueBytes)
{
hashString += String.Format("{0:x2}", x);
hashString += string.Format("{0:x2}", x);
}
return hashString;
}
public static System.Security.Cryptography.SHA256 CreateHashAlgorithm()
{
if (CryptoConfig.AllowOnlyFipsAlgorithms)
{
return new SHA256CryptoServiceProvider();
}
return new SHA256Managed();
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace Teknik.Utilities
@ -21,7 +22,7 @@ namespace Teknik.Utilities
// Guid.NewGuid and System.Random are not particularly random. By using a
// cryptographically-secure random number generator, the caller is always
// protected, regardless of use.
using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider())
using (var rng = RandomNumberGenerator.Create())
{
var result = new StringBuilder();
var buf = new byte[128];