Skip to content

Commit

Permalink
Merge pull request #400 from cmu-sei/v8
Browse files Browse the repository at this point in the history
updates linux for ubuntu testing
  • Loading branch information
sei-dupdyke authored Aug 28, 2024
2 parents b329754 + ba98cf5 commit 4b34e5d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
32 changes: 18 additions & 14 deletions src/ghosts.client.linux/Comms/CheckId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ public string Id
{
if (DateTime.Now > _lastChecked.AddMinutes(5))
{
_log.Error("Skipping Check for ID from server, too many requests in a short amount of time...");
_log.Error(
"Skipping Check for ID from server, too many requests in a short amount of time...");
return string.Empty;
}

_lastChecked = DateTime.Now;
return Run();
}
Id = File.ReadAllText(IdFile);

_id = File.ReadAllText(IdFile);
return _id;
}
catch
catch (Exception ex)
{
_log.Error("No ID file");
_log.Error(ex, "Failed to read ID file.");
return string.Empty;
}
}
Expand All @@ -71,7 +73,7 @@ public string Id
/// <returns></returns>
private string Run()
{
// ignore all certs
// Ignore all certs
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

var s = string.Empty;
Expand All @@ -82,16 +84,17 @@ private string Run()
}

var machine = new ResultMachine();

try
{
//call home
// Call home
using (var client = WebClientBuilder.Build(machine))
{
try
{
using (var reader =
new StreamReader(client.OpenRead(Program.ConfigurationUrls.Id) ?? throw new InvalidOperationException("CheckID client is null")))
using (var reader = new StreamReader(client.OpenRead(Program.ConfigurationUrls.Id)
?? throw new InvalidOperationException(
"CheckID client is null")))
{
s = reader.ReadToEnd();
_log.Debug("ID Received");
Expand All @@ -103,14 +106,15 @@ private string Run()
{
_log.Debug($"API not reachable: {wex.Message}");
}
else if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound)
else if (wex.Response is HttpWebResponse response &&
response.StatusCode == HttpStatusCode.NotFound)
{
_log.Debug($"No ID returned! {wex.Message}");
}
}
catch (Exception e)
{
_log.Error($"General comms exception: {e.Message}");
_log.Error($"General communication exception: {e.Message}");
}
}
}
Expand All @@ -132,11 +136,11 @@ private string Run()
return string.Empty;
}

//save returned id
// Save returned ID
File.WriteAllText(IdFile, s);
return s;
}

public static void WriteId(string id)
{
if (!string.IsNullOrEmpty(id))
Expand All @@ -148,7 +152,7 @@ public static void WriteId(string id)
Directory.CreateDirectory(ApplicationDetails.InstanceFiles.Path);
}

//save returned id
// Save returned ID
File.WriteAllText(ApplicationDetails.InstanceFiles.Id, id);
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/ghosts.client.linux/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ private static void Run(IEnumerable<string> args)
return;
}

// if (Configuration.Sockets.IsEnabled)
// {
// _log.Trace("Sockets enabled. Connecting...");
// var c = new Connection(Configuration.Sockets);
//
// async void Start()
// {
// await c.Run();
// }
//
// var connectionThread = new Thread(Start) { IsBackground = true };
// connectionThread.Start();
// Queue = c.Queue;
// }
if (Configuration.Sockets.IsEnabled)
{
_log.Trace("Sockets enabled. Connecting...");
var c = new Connection(Configuration.Sockets);

async void Start()
{
await c.Run();
}

var connectionThread = new Thread(Start) { IsBackground = true };
connectionThread.Start();
Queue = c.Queue;
}

Program.CheckId = new CheckId();

Expand Down

0 comments on commit 4b34e5d

Please sign in to comment.