/** * Imports a certificate. * * @param file file * @param clientId client id * @throws Exception if an error occurs */ @Command(description = "Imports a certificate") public void importCertificate( @Param(name = "file", description = "Certificate file (PEM)") String file, @Param(name = "clientId", description = "Member identifier") ClientId clientId) throws Exception { Map<String, Object> logData = new LinkedHashMap<>(); logData.put(CERT_FILE_NAME_PARAM, file); logData.put(CLIENT_IDENTIFIER_PARAM, clientId); try { byte[] certBytes = fileToBytes(file); ImportCertResponse response = SignerClient.execute( new ImportCert(certBytes, CertificateInfo.STATUS_REGISTERED, clientId)); logData.put(KEY_ID_PARAM, response.getKeyId()); AuditLogger.log(IMPORT_A_CERTIFICATE_FROM_THE_FILE, XROAD_USER, logData); System.out.println(response.getKeyId()); } catch (Exception e) { AuditLogger.log(IMPORT_A_CERTIFICATE_FROM_THE_FILE, XROAD_USER, e.getMessage(), logData); System.out.println("ERROR: " + e); } }
/** * Imports the given byte array as a new certificate with the provided initial status and owner * client ID. * * @param certBytes byte content of the new certificate * @param initialStatus initial status of the certificate * @param clientId client ID of the certificate owner * @return key ID of the new certificate as a String * @throws Exception if any errors occur */ public static String importCert(byte[] certBytes, String initialStatus, ClientId clientId) throws Exception { LOG.trace("Importing cert from file with length of '{}' bytes", certBytes.length); ImportCertResponse response = execute(new ImportCert(certBytes, initialStatus, clientId)); LOG.trace("Cert imported successfully, keyId received: {}", response.getKeyId()); return response.getKeyId(); }