Skip to content

Commit

Permalink
Remove Telemetry (#550)
Browse files Browse the repository at this point in the history
* Remove Telemetry

* Remove Cached Docs build

* Delete PRIVACY.md
  • Loading branch information
gfs committed Oct 1, 2020
1 parent 85d1d50 commit ba88391
Show file tree
Hide file tree
Showing 166 changed files with 92 additions and 62,606 deletions.
28 changes: 1 addition & 27 deletions Benchmarks/LiteDbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class LiteDbManager

private static readonly ConcurrentBag<ILiteCollection<WriteObject>> WriteObjectCollections = new ConcurrentBag<ILiteCollection<WriteObject>>();

private static Settings settings { get; set; } = new Settings() { SchemaVersion = SCHEMA_VERSION, ShardingFactor = 1, TelemetryEnabled = true };
private static Settings settings { get; set; } = new Settings() { SchemaVersion = SCHEMA_VERSION, ShardingFactor = 1 };

public static ConcurrentQueue<WriteObject> WriteQueue { get; private set; } = new ConcurrentQueue<WriteObject>();

Expand Down Expand Up @@ -435,32 +435,6 @@ public static void DeleteRun(string runId)
Results?.DeleteMany(x => x.RunId == runId);
}

public static bool GetOptOut()
{
//var settings = db.GetCollection<Setting>("Settings");
//var optout = settings.FindOne(x => x.Name == "TelemetryOptOut");
//return bool.Parse(optout.Value);
return false;
}

public static void SetOptOut(bool OptOut)
{
//var settings = db.GetCollection<Setting>("Settings");

//settings.Upsert(new Setting() { Name = "TelemetryOptOut", Value = OptOut.ToString() });
}

//public static void WriteFileMonitor(FileMonitorObject obj, string runId)
//{
// var fme = db.GetCollection<FileMonitorEvent>();

// fme.Insert(new FileMonitorEvent()
// {
// RunId = runId,
// FMO = obj
// });
//}

public static AsaRun? GetRun(string RunId)
{
var runs = db?.GetCollection<AsaRun>("Runs");
Expand Down
25 changes: 1 addition & 24 deletions Benchmarks/SystemSqliteDatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public static bool Setup(string filename, DBSettings? dbSettingsIn = null)

dbSettings.ShardingFactor = settings.ShardingFactor;

AsaTelemetry.SetEnabled(settings.TelemetryEnabled);
}
else
{
Expand Down Expand Up @@ -202,7 +201,6 @@ public static bool Setup(string filename, DBSettings? dbSettingsIn = null)
{
SchemaVersion = SCHEMA_VERSION,
ShardingFactor = dbSettings.ShardingFactor,
TelemetryEnabled = true
});

Connections.AsParallel().ForAll(cxn =>
Expand Down Expand Up @@ -618,7 +616,6 @@ public static void InsertRun(AsaRun run)
{
Log.Warning(e.StackTrace);
Log.Warning(e.Message);
AsaTelemetry.TrackTrace(Microsoft.ApplicationInsights.DataContracts.SeverityLevel.Error, e);
}
}
else
Expand Down Expand Up @@ -765,27 +762,7 @@ public static void DeleteRun(string runid)
truncateCollectTable.ExecuteNonQuery();
});
}

public static bool GetTelemetryEnabled()
{
var settings = GetSettings();
if (settings != null)
{
return settings.TelemetryEnabled;
}
return true;
}

public static void SetTelemetryEnabled(bool Enabled)
{
var settings = GetSettings();
if (settings != null)
{
settings.TelemetryEnabled = Enabled;
SetSettings(settings);
}
}


public static void WriteFileMonitor(FileMonitorObject fmo, string RunId)
{
if (fmo == null)
Expand Down
7 changes: 0 additions & 7 deletions Cli/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ public IActionResult Collect()
return View();
}

public ActionResult ChangeTelemetryState(bool EnableTelemetry)
{
AsaTelemetry.SetEnabled(EnableTelemetry);

return Json(true);
}

public ActionResult StartMonitoring(string RunId, string Directory)
{
if (RunId != null)
Expand Down
68 changes: 0 additions & 68 deletions Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ private static int RunGuiCommand(GuiCommandOptions opts)
#else
Logger.Setup(opts.Debug, opts.Verbose, opts.Quiet);
#endif
AsaTelemetry.Setup();

var server = WebHost.CreateDefaultBuilder(Array.Empty<string>())
.UseStartup<Startup>()
Expand Down Expand Up @@ -166,7 +165,6 @@ private static void SleepAndOpenBrowser(int sleep)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "<Pending>")]
private static int RunConfigCommand(ConfigCommandOptions opts)
{
AsaTelemetry.Setup();

if (opts.ResetDatabase)
{
Expand All @@ -176,8 +174,6 @@ private static int RunConfigCommand(ConfigCommandOptions opts)
}
else
{
CheckFirstRun();

SetupDatabase(opts);

if (opts.ListRuns)
Expand Down Expand Up @@ -242,9 +238,6 @@ private static int RunConfigCommand(ConfigCommandOptions opts)
}
}

AsaTelemetry.SetEnabled(opts.TelemetryOptOut);
Log.Information(Strings.Get("TelemetryOptOut"), opts.TelemetryOptOut ? "Opted out" : "Opted in");

if (opts.DeleteRunId != null)
{
DatabaseManager.DeleteRun(opts.DeleteRunId);
Expand All @@ -271,9 +264,6 @@ private static int RunExportCollectCommand(ExportCollectCommandOptions opts)
return 0;
}

CheckFirstRun();
AsaTelemetry.Setup();

if (opts.ExportSingleRun)
{
if (opts.SecondRunId is null)
Expand Down Expand Up @@ -312,11 +302,6 @@ private static int RunExportCollectCommand(ExportCollectCommandOptions opts)

Log.Information(Strings.Get("Comparing"), opts.FirstRunId, opts.SecondRunId);

Dictionary<string, string> StartEvent = new Dictionary<string, string>();
StartEvent.Add("OutputPathSet", (opts.OutputPath != null).ToString(CultureInfo.InvariantCulture));

AsaTelemetry.TrackEvent("{0} Export Compare", StartEvent);

CompareCommandOptions options = new CompareCommandOptions(opts.FirstRunId, opts.SecondRunId)
{
DatabaseFilename = opts.DatabaseFilename,
Expand Down Expand Up @@ -458,17 +443,6 @@ public static void WriteScanJson(int ResultType, string BaseId, string CompareId

}

private static void CheckFirstRun()
{
if (DatabaseManager.FirstRun)
{
string exeStr = $"config --telemetry-opt-out";
Log.Information(Strings.Get("ApplicationHasTelemetry"));
Log.Information(Strings.Get("ApplicationHasTelemetry2"), "https://github.com/Microsoft/AttackSurfaceAnalyzer/blob/master/PRIVACY.md");
Log.Information(Strings.Get("ApplicationHasTelemetry3"), exeStr);
}
}

private static int RunExportMonitorCommand(ExportMonitorCommandOptions opts)
{
#if DEBUG
Expand All @@ -483,9 +457,6 @@ private static int RunExportMonitorCommand(ExportMonitorCommandOptions opts)
return 0;
}

CheckFirstRun();
AsaTelemetry.Setup();

if (opts.RunId is null)
{
List<string> runIds = DatabaseManager.GetLatestRunIds(1, RUN_TYPE.MONITOR);
Expand All @@ -503,11 +474,6 @@ private static int RunExportMonitorCommand(ExportMonitorCommandOptions opts)

Log.Information("{0} {1}", Strings.Get("Exporting"), opts.RunId);

Dictionary<string, string> StartEvent = new Dictionary<string, string>();
StartEvent.Add("OutputPathSet", (opts.OutputPath != null).ToString(CultureInfo.InvariantCulture));

AsaTelemetry.TrackEvent("Begin Export Monitor", StartEvent);

WriteMonitorJson(opts.RunId, (int)RESULT_TYPE.FILE, opts.OutputPath ?? "monitor.json");

return 0;
Expand Down Expand Up @@ -548,15 +514,6 @@ private static int RunMonitorCommand(MonitorCommandOptions opts)
#endif
AdminOrQuit();

AsaTelemetry.Setup();

Dictionary<string, string> StartEvent = new Dictionary<string, string>();
StartEvent.Add("Files", opts.EnableFileSystemMonitor.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("Admin", AsaHelpers.IsAdmin().ToString(CultureInfo.InvariantCulture));
AsaTelemetry.TrackEvent("Begin monitoring", StartEvent);

CheckFirstRun();

if (opts.RunId is string)
{
opts.RunId = opts.RunId.Trim();
Expand Down Expand Up @@ -793,7 +750,6 @@ public static ConcurrentDictionary<(RESULT_TYPE, CHANGE_TYPE), List<CompareResul
}

DatabaseManager.Commit();
AsaTelemetry.TrackEvent("End Command", EndEvent);
return c.Results;
}

Expand Down Expand Up @@ -862,7 +818,6 @@ public static void AdminOrQuit()
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Acceptable tradeoff with telemetry (to identify issues) to lessen severity of individual collector crashes.")]
public static int RunCollectCommand(CollectCommandOptions opts)
{
if (opts == null) { return -1; }
Expand All @@ -874,25 +829,8 @@ public static int RunCollectCommand(CollectCommandOptions opts)

collectors.Clear();

AsaTelemetry.Setup();

Dictionary<string, string> StartEvent = new Dictionary<string, string>();
StartEvent.Add("Files", opts.EnableAllCollectors ? "True" : opts.EnableFileSystemCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("Ports", opts.EnableNetworkPortCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("Users", opts.EnableUserCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("Certificates", opts.EnableCertificateCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("Registry", opts.EnableRegistryCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("Service", opts.EnableServiceCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("Firewall", opts.EnableFirewallCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("ComObject", opts.EnableComObjectCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("EventLog", opts.EnableEventLogCollector.ToString(CultureInfo.InvariantCulture));
StartEvent.Add("Admin", AsaHelpers.IsAdmin().ToString(CultureInfo.InvariantCulture));
AsaTelemetry.TrackEvent("Run Command", StartEvent);

AdminOrQuit();

CheckFirstRun();

int returnValue = (int)ASA_ERROR.NONE;
opts.RunId = opts.RunId?.Trim() ?? DateTime.Now.ToString("o", CultureInfo.InvariantCulture);

Expand Down Expand Up @@ -1033,15 +971,9 @@ public static int RunCollectCommand(CollectCommandOptions opts)
catch (Exception e)
{
Log.Error(Strings.Get("Err_CollectingFrom"), c.GetType().Name, e.Message, e.StackTrace);
Dictionary<string, string> ExceptionEvent = new Dictionary<string, string>();
ExceptionEvent.Add("Exception Type", e.GetType().ToString());
ExceptionEvent.Add("Stack Trace", e.StackTrace ?? string.Empty);
ExceptionEvent.Add("Message", e.Message);
AsaTelemetry.TrackEvent("CollectorCrashRogueException", ExceptionEvent);
returnValue = 1;
}
}
AsaTelemetry.TrackEvent("End Command", EndEvent);

DatabaseManager.Commit();
return returnValue;
Expand Down
4 changes: 0 additions & 4 deletions Cli/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public void ConfigureServices(IServiceCollection services)
}
});

services.AddApplicationInsightsTelemetry();

services.AddControllersWithViews();


}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
14 changes: 0 additions & 14 deletions Cli/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@
<a asp-area="" asp-controller="Home" asp-action="Collect" class="btn btn-primary btn-square" id="indexGetStartedButton">Get Started</a>
</div>
</div>
@{
if (AsaTelemetry.Enabled)
{
<label for="TelemetryOpt">
<input type="checkbox" id="TelemetryOpt" checked /> @Strings.Get("UsageData") <a href="https://github.com/Microsoft/AttackSurfaceAnalyzer/blob/master/PRIVACY.md" target="_blank">Privacy</a>
</label>
}
else
{
<label for="TelemetryOpt">
<input type="checkbox" id="TelemetryOpt" /> @Strings.Get("UsageData") <a href="https://github.com/Microsoft/AttackSurfaceAnalyzer/blob/master/PRIVACY.md" target="_blank">Privacy</a>
</label>
}
}
<br />
<div class="spacer"></div>
<div id="moreInfo">
Expand Down
10 changes: 1 addition & 9 deletions Cli/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
@using Microsoft.ApplicationInsights.Extensibility;
@using AttackSurfaceAnalyzer.Utils;
@using AttackSurfaceAnalyzer.Utils;
@using System.Runtime.InteropServices;

<!DOCTYPE html>
Expand All @@ -15,12 +13,6 @@
<link rel="stylesheet" href="~/css/bootstrap.min.css">
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="localizations" href="~/American-English.json" type="application/vnd.oftn.l10n+json" />
@{
if (AsaTelemetry.Enabled)
{
Html.Raw(snippet.FullScript);
}
}

<script src="~/lib/jquery-3.4.1.min.js"></script>
<script src="~/lib/fontawesome.js"></script>
Expand Down
7 changes: 0 additions & 7 deletions Cli/wwwroot/js/Index.js

This file was deleted.

0 comments on commit ba88391

Please sign in to comment.