示例#1
0
 private void jj_add_error_token(int kind, int pos) {
   if (pos >= 100) return;
   if (pos == jj_endpos + 1) {
     jj_lasttokens[jj_endpos++] = kind;
   } else if (jj_endpos != 0) {
     jj_expentry = new int[jj_endpos];
     for (int i = 0; i < jj_endpos; i++) {
       jj_expentry[i] = jj_lasttokens[i];
     }
     boolean exists = false;
     for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements(); ) {
       int[] oldentry = (int[]) (e.nextElement());
       if (oldentry.length == jj_expentry.length) {
         exists = true;
         for (int i = 0; i < jj_expentry.length; i++) {
           if (oldentry[i] != jj_expentry[i]) {
             exists = false;
             break;
           }
         }
         if (exists) break;
       }
     }
     if (!exists) jj_expentries.addElement(jj_expentry);
     if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
   }
 }
示例#2
0
 public static void printSystemProperties() {
   java.util.Enumeration e = System.getProperties().propertyNames();
   while (e.hasMoreElements()) {
     String prop = (String) e.nextElement();
     String out = prop;
     out += " = ";
     out += System.getProperty(prop);
     out += "\n";
     System.out.println(out);
   }
 }
示例#3
0
  public static void main(String args[]) {

    try {

      if (args.length < 2) {
        System.out.println(
            "Usage: FipsTest <dbdir> <fipsmode enter: "
                + "enable OR disable OR chkfips > <password file>");
        return;
      }
      String dbdir = args[0];
      String fipsmode = args[1];

      String password = "";

      if (args.length == 3) {
        password = args[2];
        System.out.println("The password file " + password);
      }

      CryptoManager.InitializationValues vals = new CryptoManager.InitializationValues(dbdir);

      System.out.println("output of Initilization values ");
      System.out.println("Manufacturer ID: " + vals.getManufacturerID());
      System.out.println("Library: " + vals.getLibraryDescription());
      System.out.println("Internal Slot: " + vals.getInternalSlotDescription());
      System.out.println("Internal Token: " + vals.getInternalTokenDescription());
      System.out.println("Key Storage Slot: " + vals.getFIPSKeyStorageSlotDescription());
      System.out.println("Key Storage Token: " + vals.getInternalKeyStorageTokenDescription());
      System.out.println("FIPS Slot: " + vals.getFIPSSlotDescription());
      System.out.println("FIPS Key Storage: " + vals.getFIPSKeyStorageSlotDescription());

      if (fipsmode.equalsIgnoreCase("enable")) {
        vals.fipsMode = CryptoManager.InitializationValues.FIPSMode.ENABLED;
      } else if (fipsmode.equalsIgnoreCase("disable")) {
        vals.fipsMode = CryptoManager.InitializationValues.FIPSMode.DISABLED;
      } else {
        vals.fipsMode = CryptoManager.InitializationValues.FIPSMode.UNCHANGED;
      }

      CryptoManager.initialize(vals);

      CryptoManager cm = CryptoManager.getInstance();

      if (cm.FIPSEnabled() == true) {
        System.out.println("\n\t\tFIPS enabled\n");
      } else {
        System.out.println("\n\t\tFIPS not enabled\n");
      }

      java.util.Enumeration items;
      items = cm.getModules();
      System.out.println("\nListing of Modules:");
      while (items.hasMoreElements()) {
        System.out.println("\t" + ((PK11Module) items.nextElement()).getName());
      }
      CryptoToken tok;
      String tokenName;

      items = cm.getAllTokens();
      System.out.println("\nAll Tokens:");
      while (items.hasMoreElements()) {
        tok = (CryptoToken) items.nextElement();

        System.out.print("\t" + tok.getName());
        if (tok.needsLogin() == true) {
          System.out.println("\t - Needs login.\n");
        } else {
          System.out.println("\t - Does not need login.\n");
        }
      }

      items = cm.getExternalTokens();
      System.out.println("\nExternal Tokens:");
      while (items.hasMoreElements()) {
        System.out.println("\t" + ((CryptoToken) items.nextElement()).getName());
      }

      /* find the Internal Key Storage token */
      if (cm.FIPSEnabled() == true) {
        tokenName = vals.getFIPSSlotDescription();
      } else {
        tokenName = vals.getInternalKeyStorageTokenDescription();
      }

      /* truncate to 32 bytes and remove trailing white space*/
      tokenName = tokenName.substring(0, 32);
      tokenName = tokenName.trim();
      System.out.println("\nFinding the Internal Key Storage token: " + tokenName);
      tok = cm.getTokenByName(tokenName);

      if (((PK11Token) tok).isInternalKeyStorageToken()
          && tok.equals(cm.getInternalKeyStorageToken())) {
        System.out.println(
            "Good, " + tok.getName() + ", knows it is " + "the internal Key Storage Token");
      } else {
        System.out.println(
            "ERROR: " + tok.getName() + ", doesn't know" + " it is the internal key storage token");
      }

      if (!password.equals("")) {
        System.out.println("logging in to the Token: " + tok.getName());
        PasswordCallback cb = new FilePasswordCallback(password);
        tok.login(cb);
        System.out.println("logged in to the Token: " + tok.getName());
      }

      /* find the Internal Crypto token */
      if (cm.FIPSEnabled() == true) {
        tokenName = vals.getFIPSSlotDescription();
      } else {
        tokenName = vals.getInternalTokenDescription();
      }

      /* truncate to 32 bytes and remove trailing white space*/
      tokenName = tokenName.substring(0, 32);
      tokenName = tokenName.trim();
      System.out.println("\nFinding the Internal Crypto token: " + tokenName);
      tok = cm.getTokenByName(tokenName);

      if (((PK11Token) tok).isInternalCryptoToken() && tok.equals(cm.getInternalCryptoToken())) {
        System.out.println("Good, " + tok.getName() + ", knows it is the internal Crypto token");
      } else {
        System.out.println(
            "ERROR: " + tok.getName() + ", doesn't know that it is the internal Crypto token");
      }

      System.exit(0);

    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
  /**
   * Method for reading in data file, in a given format. Namely:
   *
   * <pre>
   * 881003,0.0000,14.1944,13.9444,14.0832,2200050,0
   * 881004,0.0000,14.1668,14.0556,14.1668,1490850,0
   * ...
   * 990108,35.8125,36.7500,35.5625,35.8125,4381200,0
   * 990111,35.8125,35.8750,34.8750,35.1250,3920800,0
   * 990112,34.8750,34.8750,34.0000,34.0625,3577500,0
   * </pre>
   *
   * <p>Where the fields represent, one believes, the following:
   *
   * <ol>
   *   <li>The date in 'YYMMDD' format
   *   <li>Open
   *   <li>High
   *   <li>Low
   *   <li>Last
   *   <li>Volume
   *   <li>Open Interest
   * </ol>
   *
   * One will probably make use of the closing price, but this can be redefined via the class
   * variable <code>DATUMFIELD</code>. Note that since the read in data are then used to compute the
   * return, this would be a good place to trap for zero values in the data, which will cause all
   * sorts of problems.
   *
   * @param dirName the directory in which to search for the data file.
   * @param filename the data filename itself.
   * @exception DemoException thrown if there was a problem with the data file.
   */
  private void readRatesFile(String dirName, String filename) throws DemoException {
    java.io.File ratesFile = new File(filename);
    java.io.BufferedReader in;
    try {
      InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(filename);

      //    if( ! ratesFile.canRead() ) {
      //      throw new DemoException("Cannot read the file "+ratesFile.toString());
      //    }

      in = new BufferedReader(new InputStreamReader(inputStream));
    } catch (Exception fnfex) {
      throw new DemoException(fnfex.toString());
    }
    //
    // Proceed to read all the lines of data into a Vector object.
    int iLine = 0, initNlines = 100, nLines = 0;

    String aLine;
    java.util.Vector allLines = new Vector(initNlines);
    try {
      while ((aLine = in.readLine()) != null) {
        iLine++;
        //
        // Note, I'm not entirely sure whether the object passed in is copied
        // by value, or just its reference.
        allLines.addElement(aLine);
      }
    } catch (IOException ioex) {
      throw new DemoException("Problem reading data from the file " + ioex.toString());
    }
    nLines = iLine;
    //
    // Now create an array to store the rates data.
    this.pathValue = new double[nLines];
    this.pathDate = new int[nLines];
    nAcceptedPathValue = 0;
    iLine = 0;
    for (java.util.Enumeration enum1 = allLines.elements(); enum1.hasMoreElements(); ) {
      aLine = (String) enum1.nextElement();
      String[] field = Utilities.splitString(",", aLine);
      int aDate = Integer.parseInt("19" + field[0]);
      //
      // static double Double.parseDouble() method is a feature of JDK1.2!
      double aPathValue = Double.valueOf(field[DATUMFIELD]).doubleValue();
      if ((aDate <= MINIMUMDATE) || (Math.abs(aPathValue) < EPSILON)) {
        dbgPrintln("Skipped erroneous data in " + filename + " indexed by date=" + field[0] + ".");
      } else {
        pathDate[iLine] = aDate;
        pathValue[iLine] = aPathValue;
        iLine++;
      }
    }
    //
    // Record the actual number of accepted data points.
    nAcceptedPathValue = iLine;
    //
    // Now to fill in the structures from the 'PathId' class.
    set_name(ratesFile.getName());
    set_startDate(pathDate[0]);
    set_endDate(pathDate[nAcceptedPathValue - 1]);
    set_dTime((double) (1.0 / 365.0));
  }