Exemplo n.º 1
0
  /**
   * Sign a file.
   *
   * @param keyId the key id
   * @param fileName the file name
   * @throws Exception if an error occurs
   */
  @Command(description = "Sign a file")
  public void signFile(
      @Param(name = "keyId", description = "Key ID") String keyId,
      @Param(name = "fileName", description = "File name") String fileName)
      throws Exception {
    String algorithm = "SHA512withRSA";
    byte[] digest = calculateDigest(getDigestAlgorithmId(algorithm), fileToBytes(fileName));

    SignResponse response = SignerClient.execute(new Sign(keyId, algorithm, digest));
    System.out.println("Signature: " + Arrays.toString(response.getSignature()));
  }
Exemplo n.º 2
0
 /**
  * Sign some data
  *
  * @param keyId the key id
  * @param data the data
  * @throws Exception if an error occurs
  */
 @Command(description = "Sign some data")
 public void sign(
     @Param(name = "keyId", description = "Key ID") String keyId,
     @Param(name = "data", description = "Data to sign (<data1> <data2> ...)") String... data)
     throws Exception {
   String algorithm = "SHA512withRSA";
   for (String d : data) {
     byte[] digest =
         calculateDigest(getDigestAlgorithmId(algorithm), d.getBytes(StandardCharsets.UTF_8));
     SignResponse response = SignerClient.execute(new Sign(keyId, algorithm, digest));
     System.out.println("Signature: " + Arrays.toString(response.getSignature()));
   }
 }
Exemplo n.º 3
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;
    }
  }