.addEmail(contact) .create(session); log.info("Registered a new user, URL: {}", account.getLocation());
public CompletableFuture<URL> openAccount(String email, KeyPair accountKeyPair) { try { log.info("open account"); Session session = new Session("acme://letsencrypt.org/staging"); Account account = new AccountBuilder() .addContact("mailto:"+email) .agreeToTermsOfService() .useKeyPair(accountKeyPair) .create(session); URL location = account.getLocation(); log.info("account location="+location); return CompletableFuture.completedFuture(location); } catch (AcmeException e) { throw new RuntimeException(e); } } //TODO: Put the remote request INTO a different pool to not hold up the webserver main
/** * Commits the changes and updates the account. */ public void commit() throws AcmeException { LOG.debug("modify/commit"); try (Connection conn = getSession().connect()) { JSONBuilder claims = new JSONBuilder(); if (!editContacts.isEmpty()) { claims.put(KEY_CONTACT, editContacts); } conn.sendSignedRequest(getLocation(), claims, getLogin()); JSON json = conn.readJsonResponse(); if (json != null) { setJSON(json); } } } }
/** * Commits the changes and updates the account. */ public void commit() throws AcmeException { LOG.debug("modify/commit"); try (Connection conn = getSession().connect()) { JSONBuilder claims = new JSONBuilder(); if (!editContacts.isEmpty()) { claims.put(KEY_CONTACT, editContacts); } conn.sendSignedRequest(getLocation(), claims, getLogin()); JSON json = conn.readJsonResponse(); if (json != null) { setJSON(json); } } } }
private void login() { KeyPair accountKeyPair = RSATools.createKeyPair(RSACrypt.RSA_CRYPT.loadKeysPemFromString(config.getAccountKeypairPem())); LOGGER.info("Registering account"); try { account = new AccountBuilder() // .addContact("mailto:" + config.getContactEmail()) // .agreeToTermsOfService() // .useKeyPair(accountKeyPair) // .create(session); } catch (AcmeException e) { LOGGER.error("Problem logging in", e); throw new LetsencryptException("Problem logging in", e); } URL accountLocationUrl = account.getLocation(); session.login(accountLocationUrl, accountKeyPair); // Get the location LOGGER.info("AcmeClient location: {}", accountLocationUrl); }
/** * Permanently deactivates an account. Related certificates may still be valid after * account deactivation, and need to be revoked separately if neccessary. * <p> * A deactivated account cannot be reactivated! */ public void deactivate() throws AcmeException { LOG.debug("deactivate"); try (Connection conn = getSession().connect()) { JSONBuilder claims = new JSONBuilder(); claims.put(KEY_STATUS, "deactivated"); conn.sendSignedRequest(getLocation(), claims, getLogin()); JSON json = conn.readJsonResponse(); if (json != null) { setJSON(json); } } }
/** * Permanently deactivates an account. Related certificates may still be valid after * account deactivation, and need to be revoked separately if neccessary. * <p> * A deactivated account cannot be reactivated! */ public void deactivate() throws AcmeException { LOG.debug("deactivate"); try (Connection conn = getSession().connect()) { JSONBuilder claims = new JSONBuilder(); claims.put(KEY_STATUS, "deactivated"); conn.sendSignedRequest(getLocation(), claims, getLogin()); JSON json = conn.readJsonResponse(); if (json != null) { setJSON(json); } } }
/** * Finds your {@link Account} at the ACME server. It will be found by your user's * public key. If your key is not known to the server yet, a new account will be * created. * <p> * This is a simple way of finding your {@link Account}. A better way is to get the * URL and KeyIdentifier of your new account with {@link Account#getLocation()} * {@link Session#getKeyIdentifier()} and store it somewhere. If you need to get * access to your account later, reconnect to it via * {@link Account#bind(Session, URI)} by using the stored location. * * @param session * {@link Session} to bind with * @return {@link Login} that is connected to your account */ private Account findOrRegisterAccount(Session session, KeyPair accountKey) throws AcmeException { // Ask the user to accept the TOS, if server provides us with a link. URI tos = session.getMetadata().getTermsOfService(); if (tos != null) { acceptAgreement(tos); } Account account = new AccountBuilder() .agreeToTermsOfService() .useKeyPair(accountKey) .create(session); LOG.info("Registered a new user, URL: {}", account.getLocation()); return account; }
payloadClaim.put("account", getLocation()); payloadClaim.putKey("oldKey", getLogin().getKeyPair().getPublic());
payloadClaim.put("account", getLocation()); payloadClaim.putKey("oldKey", getLogin().getKeyPair().getPublic());