/** * Loads a key pair from specified file. If the file does not exist, * a new key pair is generated and saved. * * @return {@link KeyPair}. */ private KeyPair loadOrCreateKeyPair(File file) throws IOException { if (file.exists()) { try (FileReader fr = new FileReader(file)) { return KeyPairUtils.readKeyPair(fr); } } else { KeyPair domainKeyPair = KeyPairUtils.createKeyPair(KEY_SIZE); try (FileWriter fw = new FileWriter(file)) { KeyPairUtils.writeKeyPair(domainKeyPair, fw); } return domainKeyPair; } }
private CompletableFuture<Redirect> process(Map<String, String> props, RouterRequest request, String organization) { log.info("read in properties from database"); String domain = request.domain; String accountKeyPairString = props.get(InstallSslCertPlugin.ACCOUNT_KEYPAIR_KEY); String email = props.get(EMAIL); try { KeyPair accountKeyPair = KeyPairUtils.readKeyPair(new StringReader(accountKeyPairString)); log.info("deserialized keypair"); return acmeClient.openAccount(email, accountKeyPair) .thenCompose((url) -> saveUrlAndProcessOrder(url, accountKeyPair, email, domain, organization)); } catch (IOException e) { throw new RuntimeException(e); } }
private KeyPair loadOrCreateKeyPair(File file) throws IOException { if (file.exists()) { messages.add("loading keypair", LOG); try (FileReader fr = new FileReader(file)) { return KeyPairUtils.readKeyPair(fr); } } else { return createKeyPair(file); } }
/** * Loads a domain key pair from {@value #DOMAIN_KEY_FILE}. If the file does not exist, * a new key pair is generated and saved. * * @return Domain {@link KeyPair}. */ private KeyPair loadOrCreateDomainKeyPair() throws IOException { if (DOMAIN_KEY_FILE.exists()) { try (FileReader fr = new FileReader(DOMAIN_KEY_FILE)) { return KeyPairUtils.readKeyPair(fr); } } else { KeyPair domainKeyPair = KeyPairUtils.createKeyPair(KEY_SIZE); try (FileWriter fw = new FileWriter(DOMAIN_KEY_FILE)) { KeyPairUtils.writeKeyPair(domainKeyPair, fw); } return domainKeyPair; } }
/** * Loads a key pair from specified file. If the file does not exist, * a new key pair is generated and saved. * * @return {@link KeyPair}. */ private KeyPair loadOrCreateKeyPair(File file) throws IOException { if (file.exists()) { try (FileReader fr = new FileReader(file)) { return KeyPairUtils.readKeyPair(fr); } } else { KeyPair domainKeyPair = KeyPairUtils.createKeyPair(KEY_SIZE); try (FileWriter fw = new FileWriter(file)) { KeyPairUtils.writeKeyPair(domainKeyPair, fw); } return domainKeyPair; } }
/** * Loads a user key pair from {@value #USER_KEY_FILE}. If the file does not exist, * a new key pair is generated and saved. * <p> * Keep this key pair in a safe place! In a production environment, you will not be * able to access your account again if you should lose the key pair. * * @return User's {@link KeyPair}. */ private KeyPair loadOrCreateUserKeyPair() throws IOException { if (USER_KEY_FILE.exists()) { // If there is a key file, read it try (FileReader fr = new FileReader(USER_KEY_FILE)) { return KeyPairUtils.readKeyPair(fr); } } else { // If there is none, create a new key pair and save it KeyPair userKeyPair = KeyPairUtils.createKeyPair(KEY_SIZE); try (FileWriter fw = new FileWriter(USER_KEY_FILE)) { KeyPairUtils.writeKeyPair(userKeyPair, fw); } return userKeyPair; } }