public CompletableFuture<AcmeInfo> fetchRemoteInfo() { try { Session session = new Session(config.getProviderLocation()); Metadata metadata = session.getMetadata(); URI termsOfServiceUri = metadata.getTermsOfService(); URL website = metadata.getWebsite(); return CompletableFuture.completedFuture(new AcmeInfo(termsOfServiceUri, website)); } catch(AcmeException e) { throw new RuntimeException(e); } }
/** * Reads the provider's directory, then rebuild the resource map. The response is * cached. */ private void readDirectory() throws AcmeException { synchronized (this) { Instant now = Instant.now(); if (directoryCacheExpiry != null && directoryCacheExpiry.isAfter(now)) { return; } directoryCacheExpiry = now.plus(Duration.ofHours(1)); } JSON directoryJson = provider().directory(this, getServerUri()); Value meta = directoryJson.get("meta"); if (meta.isPresent()) { metadata.set(new Metadata(meta.asObject())); } else { metadata.set(new Metadata(JSON.empty())); } Map<Resource, URL> map = new EnumMap<>(Resource.class); for (Resource res : Resource.values()) { directoryJson.get(res.path()) .map(Value::asURL) .ifPresent(url -> map.put(res, url)); } resourceMap.set(map); }
/** * 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; }
if (recurrent && !session.getMetadata().isStarEnabled()) { throw new AcmeException("CA does not support short-term automatic renewals");
if (recurrent && !session.getMetadata().isStarEnabled()) { throw new AcmeException("CA does not support short-term automatic renewals");
/** * Cancels a recurrent order. * * @since 2.3 */ public void cancelRecurrent() throws AcmeException { if (!getSession().getMetadata().isStarEnabled()) { throw new AcmeException("CA does not support short-term automatic renewals"); } LOG.debug("cancel"); try (Connection conn = getSession().connect()) { JSONBuilder claims = new JSONBuilder(); claims.put("status", "canceled"); conn.sendSignedRequest(getLocation(), claims, getLogin()); JSON json = conn.readJsonResponse(); if (json != null) { setJSON(json); } } }
/** * Reads the provider's directory, then rebuild the resource map. The response is * cached. */ private void readDirectory() throws AcmeException { synchronized (this) { Instant now = Instant.now(); if (directoryCacheExpiry != null && directoryCacheExpiry.isAfter(now)) { return; } directoryCacheExpiry = now.plus(Duration.ofHours(1)); } JSON directoryJson = provider().directory(this, getServerUri()); Value meta = directoryJson.get("meta"); if (meta.isPresent()) { metadata.set(new Metadata(meta.asObject())); } else { metadata.set(new Metadata(JSON.empty())); } Map<Resource, URL> map = new EnumMap<>(Resource.class); for (Resource res : Resource.values()) { directoryJson.get(res.path()) .map(Value::asURL) .ifPresent(url -> map.put(res, url)); } resourceMap.set(map); }
/** * Cancels a recurrent order. * * @since 2.3 */ public void cancelRecurrent() throws AcmeException { if (!getSession().getMetadata().isStarEnabled()) { throw new AcmeException("CA does not support short-term automatic renewals"); } LOG.debug("cancel"); try (Connection conn = getSession().connect()) { JSONBuilder claims = new JSONBuilder(); claims.put("status", "canceled"); conn.sendSignedRequest(getLocation(), claims, getLogin()); JSON json = conn.readJsonResponse(); if (json != null) { setJSON(json); } } }