Salt length depended on fingerprint name length, which lead to weak salts in some cases It's now a fixed length (12 bytes)
95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using Akari.Prototype.Server.Cli.Commands;
|
|
using Akari.Prototype.Server.Options;
|
|
using Akari.Prototype.Server.Utils.Extensions;
|
|
using CliFx;
|
|
using Isopoh.Cryptography.Argon2;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Options;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Akari.Prototype.Server
|
|
{
|
|
public class Program
|
|
{
|
|
public static async Task<int> Main(string[] args)
|
|
{
|
|
if (args?.Length > 0)
|
|
{
|
|
return await CliMain();
|
|
|
|
}
|
|
|
|
await AspMain(null);
|
|
|
|
return 0;
|
|
}
|
|
|
|
private static async Task<int> CliMain()
|
|
{
|
|
var host = CreateCliHostBuilder(null).Build();
|
|
|
|
CheckHostOptions(host);
|
|
|
|
return await new CliApplicationBuilder()
|
|
.AddCommandsFromThisAssembly()
|
|
.UseTypeActivator(host.Services.GetService)
|
|
.Build()
|
|
.RunAsync();
|
|
}
|
|
|
|
public static async Task AspMain(string[] args)
|
|
{
|
|
var host = CreateWebHostBuilder(args).Build();
|
|
|
|
CheckHostOptions(host);
|
|
|
|
await host.RunAsync();
|
|
}
|
|
|
|
private static void CheckHostOptions(IHost host)
|
|
{
|
|
var services = host.Services;
|
|
var akariOptions = services.GetRequiredService<IOptions<AkariOptions>>().Value;
|
|
|
|
if (!Directory.Exists(akariOptions.DataPath))
|
|
{
|
|
Directory.CreateDirectory(akariOptions.DataPath);
|
|
}
|
|
}
|
|
|
|
public static IHostBuilder CreateCliHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureHostConfiguration(configuration =>
|
|
{
|
|
configuration.AddJsonFile(TcpProviderOptions.FilePath, true);
|
|
configuration.AddJsonFile(AkariOptions.FilePath, false);
|
|
})
|
|
.ConfigureServices((hostContext, services) =>
|
|
{
|
|
Startup.ConfigureStandardServices(hostContext.Configuration, services);
|
|
|
|
services.AddCommandsFromThisAssembly();
|
|
});
|
|
|
|
public static IHostBuilder CreateWebHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureHostConfiguration(configuration =>
|
|
{
|
|
configuration.AddJsonFile(TcpProviderOptions.FilePath, true);
|
|
configuration.AddJsonFile(AkariOptions.FilePath, false);
|
|
})
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
}
|
|
}
|