Fix IKeyManager
Now correctly delete key folder while avoiding issues
This commit is contained in:
@@ -110,7 +110,7 @@ namespace Akari.Prototype.Server.Services
|
||||
|
||||
public bool Remove(string applicationName)
|
||||
{
|
||||
if (!_applications.ContainsKey(applicationName))
|
||||
if (!_applications.TryGetValue(applicationName, out var application))
|
||||
{
|
||||
_logger.LogDebug($"Can't remove non existing application: {applicationName}");
|
||||
|
||||
@@ -118,9 +118,9 @@ namespace Akari.Prototype.Server.Services
|
||||
}
|
||||
|
||||
// Clear keys
|
||||
_keyManager.Clear(applicationName);
|
||||
_keyManager.Clear(application);
|
||||
|
||||
_applications.Remove(applicationName);
|
||||
_applications.Remove(application.Name);
|
||||
|
||||
SaveApplications();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
using Akari.Prototype.Server.Models;
|
||||
|
||||
namespace Akari.Prototype.Server.Services
|
||||
{
|
||||
@@ -10,7 +11,7 @@ namespace Akari.Prototype.Server.Services
|
||||
{
|
||||
public bool AddFingerprint(string applicationName, string fingerprintName, AesGcm fingerprintKey);
|
||||
|
||||
public void Clear(string applicationName);
|
||||
public void Clear(Application application);
|
||||
|
||||
public bool Create(string applicationName);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
using Akari.Prototype.Server.Models;
|
||||
using Akari.Prototype.Server.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -58,12 +59,19 @@ namespace Akari.Prototype.Server.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Clear(string applicationName)
|
||||
public void Clear(Application application)
|
||||
{
|
||||
_logger.LogDebug($"Deleted keys for {applicationName}");
|
||||
// Do it safely to avoid deleting unwanted files
|
||||
File.Delete(GetMasterKeyPath(application.Name));
|
||||
|
||||
_logger.LogDebug($"Going to delete {GetKeyDirectoryPath(applicationName)}");
|
||||
//Directory.Delete(GetKeyDirectoryPath(applicationName));
|
||||
foreach (var fingerprint in application.Fingerprints)
|
||||
{
|
||||
File.Delete(GetKeyPath(application.Name, fingerprint));
|
||||
}
|
||||
|
||||
Directory.Delete(GetKeyDirectoryPath(application.Name), recursive: false);
|
||||
|
||||
_logger.LogDebug($"Deleted keys for {application.Name}");
|
||||
}
|
||||
|
||||
public bool Create(string applicationName)
|
||||
|
||||
Reference in New Issue
Block a user