Step by step Guide

Sample flow of adding sensitivity.io API

Note

You can provide both License and Settings as either path to those files or string content, depending on how your application implements storage of such resources.

Warning

If you want to run sample code or integrate sensitivity.io inside your projects, you have to use a valid License and valid Settings resources, both in JSON format.

1. Credentials

Access to the api.sensitivity.io portal is allowed through valid credentials. More info can be found at https://developers.sensitivity.io/api

  • Account ID - required
  • Project ID - required
  • Authentication Key - required
  • Application/Installatio ID - optional

2. Resources

  • License - on of the following

    • Full path to file

    OR

    • Content as string that will be injected in the engine
  • Settings - on of the following

    • Full path to file

    OR

    • Content as string that will be injected in the engine
  • File to scan (you can also itterate on folders, but that has to happen inside your application)

3. Scan data

3.1 Step 1 - Variables

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
const bool kEnableOnline = true;
const String kAccountId = "92683310********";
const String kProjectId = "2c******";
const String kAuthenticationKey = "52ae895c286d44d3****************";
const String kApplicationId = ""; // fill if known
const bool kEnableTestThreatHandler = true;
const bool kStopAtFirstThreat = false;
const bool kMaskMatchedText = true;
const String kLicenseFile = "C:/cososys/sensitivityio_sample_license.json";
const String kSettingsFile = "C:/cososys/sensitivityio_sds_sample_settings.json";
const String kFileToScan = "C:/cososys/samples/sensitivityio_sds_sample_threats.txt";
const String kStringToScan = "SSN US: 215-11-2198 - email@sensitivity.io - My VISA: 4111-1111-1111-1111";

3.2 Step 2 - Load License

  1. If you already have the License file available
1
2
Console.WriteLine("License...");
LicenseLoader.GetInstance().LoadLicenseFromFile(kLicenseFile);
  1. If you retrieve the License from api.sensitivity.io automatically
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Console.WriteLine("Application Id...");

HttpRetriever.SetAccountId(kAccountId);
HttpRetriever.SetProjectId(kProjectId);
HttpRetriever.SetAuthenticationKey(kAuthenticationKey);
HttpRetriever.SetApplicationId(kApplicationId);

if (HttpRetriever.GetApplicationId() == String.Empty) {
    ApplicationIdRetriever.GetInstance().RetrieveApplicationId();
    Console.WriteLine("Retrieved application Id: {0}", HttpRetriever.GetApplicationId());
}

Console.WriteLine("License...");
LicenseRetriever theLicenseRetriever = LicenseRetriever.GetInstance();
theLicenseRetriever.SetDestinationFile(kLicenseFile);
theLicenseRetriever.RetrieveToFileAndNotifyLoader();

3.3 Step 3 - Load Settings

  1. If you already have the Settings file
1
2
Console.WriteLine("Settings...");
scannerSettingsLoader.LoadSettingsFromFile(kSettingsFile);
  1. If you retrieve the Settings from api.sensitivity.io automatically
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Console.WriteLine("Settings...");
using (ScannerSettingsRetriever scannerSettingsRetriever = new ScannerSettingsRetriever()) {
    scannerSettingsRetriever.SetDestinationFile(kSettingsFile);
    scannerSettingsRetriever.SetSettingsLoader(scannerSettingsLoader);
    try {
        scannerSettingsRetriever.RetrieveToFileAndNotifyLoader();
    }
    finally {
        scannerSettingsRetriever.SetSettingsLoader(null);
    }
}

3.4 Step 4 - Scan data

  1. Scanning a file, by specifying the full path of the scan file to the ScanFile() function
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using (Scanner scanner = new Scanner()) {
    scannerSettingsLoader.RegisterScanner(scanner);
    try {
        if (kEnableTestThreatHandler) {
            TestThreatHandler testThreatHandler = new TestThreatHandler(kStopAtFirstThreat, kMaskMatchedText);
            scanner.ScanFile(kFileToScan, testThreatHandler);
        }
        else {
            List<ThreatInfo> threatInfos = scanner.ScanFile(kFileToScan, kStopAtFirstThreat);
            try {
                Console.WriteLine("Found {0} threats", threatInfos.Count);
                for (int idx = 0; idx <  threatInfos.Count; ++idx) {
                    ThreatInfoPrinter.Print(threatInfos[idx], idx, kMaskMatchedText);
                }
            }
            finally {
                for (int idx = 0; idx <  threatInfos.Count; ++idx) {
                    Debug.Assert(threatInfos[idx] != null);
                    ((IDisposable)threatInfos[idx]).Dispose();
                    threatInfos[idx] = null;
                }
                GC.KeepAlive(threatInfos);
            }
        }
    }
    finally {
        scannerSettingsLoader.UnregisterScanner(scanner);
    }
}
  1. Scanning a string, by specifying the string to the ScanString() function
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using (Scanner scanner = new Scanner()) {
    scannerSettingsLoader.RegisterScanner(scanner);
    try {
        if (kEnableTestThreatHandler) {
            TestThreatHandler testThreatHandler = new TestThreatHandler(kStopAtFirstThreat, kMaskMatchedText);
            scanner.ScanString(kStringToScan, testThreatHandler);
        }
        else {
            List<ThreatInfo> threatInfos = scanner.ScanFile(kStringToScan, kStopAtFirstThreat);
            try {
                Console.WriteLine("Found {0} threats", threatInfos.Count);
                for (int idx = 0; idx <  threatInfos.Count; ++idx) {
                    ThreatInfoPrinter.Print(threatInfos[idx], idx, kMaskMatchedText);
                }
            }
            finally {
                for (int idx = 0; idx <  threatInfos.Count; ++idx) {
                    Debug.Assert(threatInfos[idx] != null);
                    ((IDisposable)threatInfos[idx]).Dispose();
                    threatInfos[idx] = null;
                }
                GC.KeepAlive(threatInfos);
            }
        }
    }
    finally {
        scannerSettingsLoader.UnregisterScanner(scanner);
    }
}