/** * 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 KeyPair createKeyPair(File file) throws IOException { messages.add("creating keypair", LOG); KeyPair keyPair = KeyPairUtils.createKeyPair(2048); try (FileWriter fw = new FileWriter(file)) { KeyPairUtils.writeKeyPair(keyPair, fw); } return keyPair; }
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); } }
public CompletableFuture<Redirect> postStartSslInstall(String email) { log.info("create key pair"); KeyPair accountKeyPair = KeyPairUtils.createKeyPair(2048); log.info("done creating key pair"); try (StringWriter writer = new StringWriter()) { KeyPairUtils.writeKeyPair(accountKeyPair, writer); log.info("done marshalling keypair to string"); Map<String, String> properties = new HashMap<>(); properties.put(InstallSslCertPlugin.ACCOUNT_KEYPAIR_KEY, writer.toString()); properties.put(EMAIL, email); return this.storage.save(InstallSslCertPlugin.PLUGIN_PROPERTIES_KEY, properties) .thenApply( (v) -> { log.info("done saving, redirecting to step2"); return Actions.redirect(InstallSslCertRouteId.STEP2); }); } catch(IOException e) { return CompletableFuture.failedFuture(e); } }
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); } }
/** * 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 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; } }
/** * 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; } }