allow again the push
This commit is contained in:
parent
38bb7e40ef
commit
a78847dbc9
5 changed files with 94 additions and 7 deletions
|
|
@ -18,6 +18,8 @@ namespace Isn
|
|||
source = Program.Settings.Sources.First(s=>s.Value.Alias==source).Key;
|
||||
if (source==null) throw new InvalidOperationException("source is invalid");
|
||||
|
||||
var resolvedApiKey = string.IsNullOrWhiteSpace(apikey) ? ResolveSourceApiKey(source) : apikey;
|
||||
|
||||
var resources = SourceHelpers.GetServerResources(source);
|
||||
if (resources.Resources == null)
|
||||
throw new InvalidOperationException("source gave no resource");
|
||||
|
|
@ -38,7 +40,7 @@ namespace Isn
|
|||
try
|
||||
{
|
||||
Console.WriteLine("Connecting to "+ pubRes.Id);
|
||||
return client.UploadFilesToServer(new Uri(pubRes.Id), fi, apikey);
|
||||
return client.UploadFilesToServer(new Uri(pubRes.Id), fi, resolvedApiKey);
|
||||
}
|
||||
catch (HttpRequestException hrex)
|
||||
{
|
||||
|
|
@ -64,5 +66,25 @@ namespace Isn
|
|||
return report;
|
||||
}
|
||||
}
|
||||
|
||||
private static string ResolveSourceApiKey(string source)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(source))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Program.Settings.Sources.Values.Any(s => s.Alias == source))
|
||||
{
|
||||
source = Program.Settings.Sources.First(s => s.Value.Alias == source).Key;
|
||||
}
|
||||
|
||||
if (Program.Settings.Sources.TryGetValue(source, out var sourceSettings))
|
||||
{
|
||||
return sourceSettings.GetClearApiKey();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ namespace isnd.Controllers
|
|||
var files = new List<string>();
|
||||
ViewData["files"] = files;
|
||||
|
||||
var clearkey = ApiKeyProtector.UnprotectWithFallback(protector, apiKey);
|
||||
var clearkey = ApiKeyProtector.TryUnprotectKey(protector, apiKey);
|
||||
var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey);
|
||||
if (apikey == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,24 +9,56 @@ namespace isnd.Helpers
|
|||
{
|
||||
private const byte LegacyDelta = 145;
|
||||
|
||||
public static string UnprotectWithFallback(IDataProtector protector, string protectedValue)
|
||||
public static string TryUnprotectKey(IDataProtector protector, string protectedValue)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(protectedValue))
|
||||
{
|
||||
return protectedValue;
|
||||
}
|
||||
|
||||
if (TryUnprotect(protector, protectedValue, out var unprotected))
|
||||
{
|
||||
return unprotected;
|
||||
}
|
||||
|
||||
if (TryUnprotectLegacy(protectedValue, out unprotected))
|
||||
{
|
||||
return unprotected;
|
||||
}
|
||||
|
||||
return protectedValue;
|
||||
}
|
||||
|
||||
private static bool TryUnprotect(IDataProtector protector, string protectedValue, out string unprotected)
|
||||
{
|
||||
try
|
||||
{
|
||||
return protector.Unprotect(protectedValue);
|
||||
unprotected = protector.Unprotect(protectedValue);
|
||||
return true;
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
return UnprotectLegacy(protectedValue);
|
||||
unprotected = null;
|
||||
return false;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return UnprotectLegacy(protectedValue);
|
||||
unprotected = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryUnprotectLegacy(string protectedValue, out string unprotected)
|
||||
{
|
||||
try
|
||||
{
|
||||
unprotected = UnprotectLegacy(protectedValue);
|
||||
return true;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
unprotected = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue