mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-08 20:56:04 +00:00
Code consistency fix, Replace Random to RandomNumberGenerator, Mutex dispose
This commit is contained in:
parent
d3135bef8e
commit
c1052e0147
|
@ -28,6 +28,7 @@ namespace WelsonJS.Launcher
|
||||||
Application.Run(new MainForm());
|
Application.Run(new MainForm());
|
||||||
|
|
||||||
mutex.ReleaseMutex();
|
mutex.ReleaseMutex();
|
||||||
|
mutex.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RunCommandPrompt(string workingDirectory, string entryFileName, string scriptName, bool isConsoleApplication = false, bool isInteractiveServiceAapplication = false)
|
public static void RunCommandPrompt(string workingDirectory, string entryFileName, string scriptName, bool isConsoleApplication = false, bool isInteractiveServiceAapplication = false)
|
||||||
|
|
|
@ -105,7 +105,7 @@ namespace WelsonJS.Launcher.Tools
|
||||||
const string devtoolsPrefix = "devtools/";
|
const string devtoolsPrefix = "devtools/";
|
||||||
if (path.StartsWith(devtoolsPrefix, StringComparison.OrdinalIgnoreCase))
|
if (path.StartsWith(devtoolsPrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
await ServeDevTools(context, path.Substring(devtoolsPrefix.Length - 1));
|
await ServeDevTools(context, path.Substring(devtoolsPrefix.Length));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ namespace WelsonJS.Launcher.Tools
|
||||||
const string tfaPrefix = "tfa/";
|
const string tfaPrefix = "tfa/";
|
||||||
if (path.StartsWith(tfaPrefix, StringComparison.OrdinalIgnoreCase))
|
if (path.StartsWith(tfaPrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
ServeTfaRequest(context, path.Substring(tfaPrefix.Length - 1));
|
ServeTfaRequest(context, path.Substring(tfaPrefix.Length));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ namespace WelsonJS.Launcher.Tools
|
||||||
{
|
{
|
||||||
using (HttpClient client = new HttpClient())
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
string url = "http://localhost:9222" + endpoint;
|
string url = "http://localhost:9222/" + endpoint;
|
||||||
string data = await client.GetStringAsync(url);
|
string data = await client.GetStringAsync(url);
|
||||||
|
|
||||||
ServeResource(context, data, "application/json");
|
ServeResource(context, data, "application/json");
|
||||||
|
@ -263,7 +263,7 @@ namespace WelsonJS.Launcher.Tools
|
||||||
{
|
{
|
||||||
Tfa _tfa = new Tfa();
|
Tfa _tfa = new Tfa();
|
||||||
|
|
||||||
if (endpoint.Equals("/pubkey"))
|
if (endpoint.Equals("pubkey"))
|
||||||
{
|
{
|
||||||
ServeResource(context, _tfa.GetPubKey(), "text/plain", 200);
|
ServeResource(context, _tfa.GetPubKey(), "text/plain", 200);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -32,13 +32,19 @@ namespace WelsonJS.Launcher.Tools
|
||||||
|
|
||||||
public string GetPubKey()
|
public string GetPubKey()
|
||||||
{
|
{
|
||||||
var rand = new Random();
|
using (var rng = RandomNumberGenerator.Create())
|
||||||
var key = new char[16];
|
|
||||||
for (int i = 0; i < 16; i++)
|
|
||||||
{
|
{
|
||||||
key[i] = Base32Chars[rand.Next(Base32Chars.Length)];
|
var key = new char[16];
|
||||||
|
var randomBytes = new byte[16];
|
||||||
|
rng.GetBytes(randomBytes);
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
key[i] = Base32Chars[randomBytes[i] % Base32Chars.Length];
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(" ", Enumerable.Range(0, 4).Select(i => new string(key, i * 4, 4)));
|
||||||
}
|
}
|
||||||
return string.Join(" ", Enumerable.Range(0, 4).Select(i => new string(key, i * 4, 4)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] DecodeBase32(string key)
|
private static byte[] DecodeBase32(string key)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user