Class RiskCalculation

java.lang.Object
be.kuleuven.cs.distrinet.sparta.core.analysis.RiskCalculation

public class RiskCalculation extends Object
RiskAssessment class containing a number of static risk calculation methods to assist in performing a threat's risk calculation.
  • Method Details

    • calculateVulnerability

      public static double calculateVulnerability(double[] vulnerability)
      Calculate the vulnerability from a (binary) vector of attack success/failures
      Parameters:
      vulnerability - binary victor indicating an attacks success or failure
      Returns:
      Single vulnerability number
    • calculateVulnerabilityConfidenceInterval

      public static double[] calculateVulnerabilityConfidenceInterval(double[] vulnerability)
      Calculate the Clopper-Pearson vulnerability confidence interval
      Parameters:
      vulnerability - binary vector indicating an attacks success or failure
      Returns:
      double[] containing {lower, expected, upper}
    • calculateBoundaries

      public static double[] calculateBoundaries(double[] tef)
      Parameters:
      tef - frequency array
      Returns:
      double[] containing {min, average, max}
    • calculateTefArray

      public static double[] calculateTefArray(ThreatType tt, AttackerProfile attackerType, int samples)
      Calculate the threat event frequency. This depends on the contact frequency and the probability of action. The contact frequency depends on the AttackerType. The probability of action depends on the AttackerType These values could be scaled according to the ThreatType, for example an attacker may be more likely to attempt an denial of service. This is currently not implemented.
      Parameters:
      tt - - the threat type
      attackerType - - the attacker profile
      samples - - the number of samples to use
      Returns:
      the threat event frequency array
    • calculateVulnerabilityArray

      public static double[] calculateVulnerabilityArray(DFDElement threatenedElement, DataFlow flow, ThreatType tt, List<RoleBinding> countermeasureBindings, AttackerProfile attacker, int samples)
      Calculate the vulnerability for flow, threattype, countermeasures and attacker profile
      Parameters:
      threatenedElement - - the threatened DFDElement
      flow - - the data flow (for the context in which the threat applies)
      tt - - the threat type
      countermeasureBindings - - list of bound countermeasures
      attacker - - the attacker profile
      samples - - the number of samples to use
      Returns:
      binary vulnerability array double[SAMPLES]
    • mitigations

      public static List<Mitigation> mitigations(DataFlow flow, ThreatType tt, List<RoleBinding> countermeasureBindings)
      The countermeasures that reduce the vulnerability of a threat, each with the role binding it applies through: those subjected to a bound role that mitigates(be.kuleuven.cs.distrinet.sparta.spartamodel.CounterMeasure, be.kuleuven.cs.distrinet.sparta.spartamodel.ThreatType) the threat type and are in scope of the flow. This is the single definition of the selection used by the vulnerability calculation; it does not depend on the attacker (an insider attacker ignores them, see calculateVulnerabilityArray(be.kuleuven.cs.distrinet.sparta.spartamodel.DFDElement, be.kuleuven.cs.distrinet.sparta.spartamodel.DataFlow, be.kuleuven.cs.distrinet.sparta.spartamodel.ThreatType, java.util.List<be.kuleuven.cs.distrinet.sparta.spartamodel.RoleBinding>, be.kuleuven.cs.distrinet.sparta.spartamodel.AttackerProfile, int)).
      Parameters:
      flow - - the data flow the threat applies to (may be null)
      tt - - the threat type
      countermeasureBindings - - the role bindings on the threatened element
      Returns:
      the mitigations, in binding order
    • mitigates

      public static boolean mitigates(CounterMeasure cm, ThreatType tt)
      Whether a countermeasure mitigates the given threat type: either it references the type (or a composite containing it) through mitigates, or one of its mitigatedThreatTypeIDs is the id of the type or one of its super types.
      Parameters:
      cm - - the countermeasure
      tt - - the (leaf) threat type
      Returns:
      true if cm mitigates tt
    • isInScope

      public static boolean isInScope(CounterMeasure cm, DataFlow flow)
      Whether a countermeasure applies in the context of the given data flow: it has no scope, or the flow is bound to one of the roles in its scope.
      Parameters:
      cm - - the countermeasure
      flow - - the data flow the threat applies to (may be null)
      Returns:
      true if cm applies to flow
    • calculateLefArray

      public static double[][] calculateLefArray(double[] tefSamples, double[] vulnerabilityConfidenceInterval, int samples)
      Calculate the loss event frequency (LEF = TEF x vulnerability) per sample, for each bound of the vulnerability interval: result[i][s] = tefSamples[s] * vulnerabilityConfidenceInterval[i], so result[0], result[1] and result[2] are the LEF samples at the lower, expected and upper vulnerability.

      Not used by SpartaRiskModel, which multiplies the TEF interval (calculateBoundaries(double[])) by the vulnerability interval directly. Reducing result[0], result[1] and result[2] with min, average and max respectively gives that same interval (the vulnerability bounds are non-negative constants); this method additionally keeps the full LEF sample distribution, e.g. for percentiles or histograms.

      Parameters:
      tefSamples - - the threat event frequency samples
      vulnerabilityConfidenceInterval - - the vulnerability {lower, expected, upper}
      samples - - the number of samples; must equal tefSamples.length
      Returns:
      double[3][samples]: the LEF samples at the lower, expected and upper vulnerability (not a confidence interval)
    • aggregateMatrix

      public static double[] aggregateMatrix(double[][][][] matrix)
      This method reduces an four dimensional matrix (with the fourth dimension containing [lower,expected,upper], to a three value array containing the sum of, respectively, the lower, expected, and upper values.
      Parameters:
      matrix -
      Returns:
    • aggregateAvgMatrix

      public static double[] aggregateAvgMatrix(double[][][][] matrix, double[][][] applicabilityMatrix)
      This method reduces an four dimensional matrix (with the fourth dimension containing [lower,expected,upper], to a three value array containing the average of, respectively, the lower, expected, and upper values. To prevent averaging with 0 values for entries for which there is actually NA, the applicabilityMatrix for the same index. This means that only entries matrix[i][j][k] are averaged for which applicabilityMatrix[i][j][k]!=0
      Parameters:
      matrix -
      applicabilityMatrix -
      Returns:
    • getSamplesFromNullableNeutral

      public static double[] getSamplesFromNullableNeutral(Estimate estimate, int n)
      Get n samples from an estimate distribution. In case of null, samples are all 1.
      Parameters:
      estimate - the estimate for which samples have to be calculated
      n - the number of samples
      Returns:
      the samples themselves
    • getSamplesFromNullableZero

      public static double[] getSamplesFromNullableZero(Estimate estimate, int n)
      Get n samples from an estimate distribution. In case of null, samples are all 0.
      Parameters:
      estimate - the estimate for which samples have to be calculated
      n - the number of samples
      Returns:
      the samples themselves
    • identity

      public static double[] identity(int n)
      Get n identity samples (all 1).
      Parameters:
      n - the number of samples
      Returns:
      the samples themselves