Beispiel #1
0
  /**
   * Show certificate.
   *
   * @param certId certificate id
   * @throws Exception if an error occurs
   */
  @Command(description = "Show certificate")
  public void showCertificate(@Param(name = "certId", description = "Certificate ID") String certId)
      throws Exception {
    List<TokenInfo> tokens = SignerClient.execute(new ListTokens());
    for (TokenInfo token : tokens) {
      for (KeyInfo key : token.getKeyInfo()) {
        for (CertificateInfo cert : key.getCerts()) {
          if (certId.equals(cert.getId())) {
            X509Certificate x509 = readCertificate(cert.getCertificateBytes());
            System.out.println(x509);
            return;
          }
        }
      }
    }

    System.out.println("Certificate " + certId + " not found");
  }
Beispiel #2
0
  /**
   * Generate key on token.
   *
   * @param tokenId token id
   * @throws Exception if an error occurs
   */
  @Command(description = "Generate key on token")
  public void generateKey(@Param(name = "tokenId", description = "Token ID") String tokenId)
      throws Exception {
    Map<String, Object> logData = new LinkedHashMap<>();
    logData.put(TOKEN_ID_PARAM, tokenId);

    KeyInfo response;

    try {
      response = SignerClient.execute(new GenerateKey(tokenId));

      logData.put(KEY_ID_PARAM, response.getId());
      AuditLogger.log(GENERATE_A_KEY_ON_THE_TOKEN_EVENT, XROAD_USER, logData);
    } catch (Exception e) {
      AuditLogger.log(GENERATE_A_KEY_ON_THE_TOKEN_EVENT, XROAD_USER, e.getMessage(), logData);

      throw e;
    }

    System.out.println(response.getId());
  }