Пример #1
0
  /** create required security levels list for countermeasures */
  public int[] createReqLvlList(int[] viSecClass, boolean bNoLimit) {
    int[] viMGLvlReq = new int[_vsCode.length];
    int[] viSCLvlReq = new int[_vsGoals.length];

    if (bNoLimit) {
      System.arraycopy(_viMGLvlsMax, 0, viMGLvlReq, 0, _vsCode.length);
    } else {
      for (int i = 0; i < _vsCode.length; i++) {
        for (int j = 0; j < _vsGoals.length; j++) {
          viSCLvlReq[j] =
              (Integer)
                  ee.ioc.cs.vsle.api.ProgramContext.queryTable(
                      _sDependTableID,
                      _vsCode[i],
                      Character.toString((_vsGoals[j]).charAt(0)),
                      viSecClass[j]);
        }
        Arrays.sort(viSCLvlReq);
        viMGLvlReq[i] = viSCLvlReq[viSCLvlReq.length - 1];
        if (viMGLvlReq[i] < _viMGLvlsSit[i])
          viMGLvlReq[i] =
              _viMGLvlsSit[i]; // required security levels must always be at least the current level
      }
    }
    return viMGLvlReq;
  }
Пример #2
0
  /* lossesList contains couples (Effect, Losses) */
  public double[][] createLossesList(boolean bMonotonous, boolean bTheoretical) {
    System.out.println("Creating losses list (Security Class -> Losses)... ");

    Hashtable<Double, Double> htLossesList = new Hashtable<Double, Double>();
    Hashtable<Integer, Double> htLossesLookup = new Hashtable<Integer, Double>();
    Hashtable<Integer, Double> htEffectLookup = new Hashtable<Integer, Double>();

    double[][] mdLossesList;
    double dLosses;

    // for every SecClass combination, calculate Losses, ReqLvls and Effectiveness
    for (int i = 0; i < _iNrComb; i++) {
      dLosses = 0;

      int[] viSecClass = intToSecClass(i);

      for (int j = 0; j < _viLvlsNbr.length; j++) {
        dLosses +=
            (Double)
                ee.ioc.cs.vsle.api.ProgramContext.queryTable(
                    _sLossesTableID, Character.toString((_vsGoals[j]).charAt(0)), viSecClass[j]);
      }
      int[] reqLvlList = createReqLvlList(viSecClass, false);
      double dEffect = Optimizer.calcEffect(reqLvlList);

      // in case of duplicates use average value for losses
      if (!htLossesList.containsKey(dEffect)) htLossesList.put(dEffect, dLosses);
      else htLossesList.put(dEffect, (dLosses + htLossesList.get(dEffect)) / 2);

      // create a lookup table for (secClass - losses) couples
      htLossesLookup.put(i, dLosses);

      // create a lookup table for (secClass - effect) couples
      htEffectLookup.put(i, dEffect);
    }
    // if asked to, create a monotonously decreasing version of the losses information do
    if (bMonotonous) {
      mdLossesList = new double[_iNewNbrComb][2];

      int[] viSecClass = new int[_vsGoals.length];
      Arrays.fill(viSecClass, 0);
      double dLossesRef, dMaxDiff, dTmpDiff;
      int iIndex;

      for (int i = 0; i < _iNewNbrComb; i++) {
        mdLossesList[i][0] = htEffectLookup.get(secClassToInt(viSecClass));
        mdLossesList[i][1] = htLossesLookup.get(secClassToInt(viSecClass));

        dLossesRef = htLossesLookup.get(secClassToInt(viSecClass));
        iIndex = 0;
        dMaxDiff = 0;
        dTmpDiff = 0;

        for (int j = 0; j < _vsGoals.length; j++) {
          if ((viSecClass[j] + 1) < _viLvlsNbr[j]) {
            viSecClass[j] += 1;
            dTmpDiff = dLossesRef - htLossesLookup.get(secClassToInt(viSecClass));
            viSecClass[j] -= 1;
          }
          if (dTmpDiff > dMaxDiff) {
            iIndex = j;
            dMaxDiff = dTmpDiff;
          }
        }
        viSecClass[iIndex] += 1;
      }
    }
    // else, sort the Hashtable htLossesList with regard to the effectiveness values
    else {
      Vector<Double> vec = new Vector<Double>(htLossesList.keySet());
      Collections.sort(vec);
      Iterator<Double> it = vec.iterator();

      mdLossesList = new double[htLossesList.size()][2];

      int iI = 0;
      while (it.hasNext()) {
        double dOrdered = it.next();
        mdLossesList[iI][0] = dOrdered;
        mdLossesList[iI][1] = htLossesList.get(dOrdered);
        iI++;
      }
    }
    // if asked to add the theoretical point (Effect=1 - losses=0) do the following
    if (bTheoretical) {
      double[][] mdLossesListTemp = new double[mdLossesList.length + 1][2];
      for (int i = 0; i < mdLossesList.length; i++) {
        mdLossesListTemp[i][0] = mdLossesList[i][0];
        mdLossesListTemp[i][1] = mdLossesList[i][1];
      }
      mdLossesListTemp[mdLossesListTemp.length - 1][0] = 1;
      mdLossesListTemp[mdLossesListTemp.length - 1][1] = 0;

      mdLossesList = new double[mdLossesListTemp.length][2];
      for (int i = 0; i < mdLossesList.length; i++) {
        mdLossesList[i][0] = mdLossesListTemp[i][0];
        mdLossesList[i][1] = mdLossesListTemp[i][1];
      }
    }

    System.out.println(Arrays.deepToString(mdLossesList));
    System.out.println("... done");
    return mdLossesList;
  }