示例#1
0
  /**
   * Benchmark signing.
   *
   * @param keyId key id
   * @throws Exception if an error occurs
   */
  @Command(description = "Benchmark signing")
  public void signBenchmark(@Param(name = "keyId", description = "Key ID") String keyId)
      throws Exception {
    String algorithm = "SHA512withRSA";
    String data = "Hello world!";
    byte[] digest =
        calculateDigest(getDigestAlgorithmId(algorithm), data.getBytes(StandardCharsets.UTF_8));

    long startTime = System.currentTimeMillis();
    for (int i = 0; i < BENCHMARK_ITERATIONS; i++) {
      SignerClient.execute(new Sign(keyId, algorithm, digest));
    }

    long duration = System.currentTimeMillis() - startTime;
    System.out.println(
        "Signed " + BENCHMARK_ITERATIONS + " times in " + duration + " milliseconds");
  }
示例#2
0
  /**
   * Initialize software token
   *
   * @throws Exception if an error occurs
   */
  @Command(description = "Initialize software token")
  public void initSoftwareToken() throws Exception {
    char[] pin = System.console().readPassword("PIN: ");
    char[] pin2 = System.console().readPassword("retype PIN: ");

    if (!Arrays.equals(pin, pin2)) {
      System.out.println("ERROR: PINs do not match");
      return;
    }

    try {
      SignerClient.execute(new InitSoftwareToken(pin));

      AuditLogger.log(INITIALIZE_THE_SOFTWARE_TOKEN_EVENT, XROAD_USER, null);
    } catch (Exception e) {
      AuditLogger.log(INITIALIZE_THE_SOFTWARE_TOKEN_EVENT, XROAD_USER, e.getMessage(), null);

      throw e;
    }
  }
示例#3
0
  /**
   * Log in token.
   *
   * @param tokenId token id
   * @throws Exception if an error occurs
   */
  @Command(description = "Log in token", abbrev = "li")
  public void loginToken(@Param(name = "tokenId", description = "Token ID") String tokenId)
      throws Exception {
    char[] pin = System.console().readPassword("PIN: ");

    Map<String, Object> logData = new LinkedHashMap<>();
    logData.put(TOKEN_ID_PARAM, tokenId);

    try {
      PasswordStore.storePassword(tokenId, pin);
      SignerClient.execute(new ActivateToken(tokenId, true));

      AuditLogger.log(LOG_INTO_THE_TOKEN, XROAD_USER, logData);
    } catch (Exception e) {
      AuditLogger.log(LOG_INTO_THE_TOKEN, XROAD_USER, e.getMessage(), logData);

      throw e;
    }
  }