Skip to content
Open
Changes from all commits
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
11 changes: 8 additions & 3 deletions LWCredentialProvider/UsbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
// namespace LWCredentialProvider
// {
public class USBManager
{
private static readonly Regex DateRegex = new Regex(@"^\d{8}-\d{6}$", RegexOptions.Compiled);
private static readonly Regex HashRegex = new Regex(@"^[0-9A-F]{10}$", RegexOptions.Compiled);
private static readonly Regex GuidRegex = new Regex(@"^[0-9A-F]{1,32}$", RegexOptions.Compiled);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool DeviceIoControl(
SafeFileHandle hDevice,
Expand Down Expand Up @@ -138,20 +143,20 @@ public static bool CheckUSBKey(string usbKey)


// Validate date format
if (!System.Text.RegularExpressions.Regex.IsMatch(date, @"^\d{8}-\d{6}$"))
if (!DateRegex.IsMatch(date))
return false;

Console.WriteLine($"hash: {hash}");


// Validate hash format
if (!System.Text.RegularExpressions.Regex.IsMatch(hash, @"^[0-9A-F]{10}$"))
if (!HashRegex.IsMatch(hash))
return false;

Console.WriteLine($"guid: {guid}");

// Validate GUID format
if (!System.Text.RegularExpressions.Regex.IsMatch(guid, @"^[0-9A-F]{1,32}$"))
if (!GuidRegex.IsMatch(guid))
return false;


Expand Down