private Http01Challenge httpChallenge(Authorization auth) throws AcmeException { // Find a single http-01 challenge Http01Challenge challenge = auth.findChallenge(Http01Challenge.TYPE); if (challenge == null) { throw new AcmeException("Found no " + Http01Challenge.TYPE + " challenge, don't know what to do..."); } // Output the challenge, wait for acknowledge... log.debug("http://{}/.well-known/acme-challenge/{}", auth.getIdentifier().getDomain(), challenge.getToken()); log.debug("Content: {}", challenge.getAuthorization()); return challenge; }
/** * Returns the domain name if this is a DNS identifier. * * @return Domain name. Unicode domains are ASCII encoded. * @throws AcmeProtocolException * if this is not a DNS identifier. */ public String getDomain() { if (!TYPE_DNS.equals(type)) { throw new AcmeProtocolException("expected 'dns' identifier, but found '" + type + "'"); } return value; }
/** * Returns the {@link URL} of a document that gives instructions on the actions to * be taken by a human. */ public URL getInstance() { URI instance = getProblem().getInstance(); if (instance == null) { throw new AcmeProtocolException("Instance URL required, but missing."); } try { return instance.toURL(); } catch (MalformedURLException ex) { throw new AcmeProtocolException("Bad instance URL: " + instance.toString(), ex); } }
/** * Lazily downloads the certificate. Throws a runtime {@link AcmeLazyLoadingException} * if the download failed. */ private void lazyDownload() { try { download(); } catch (AcmeException ex) { throw new AcmeLazyLoadingException(this, ex); } }
@Override public void handleRetryAfter(String message) throws AcmeException { assertConnectionIsOpen(); Optional<Instant> retryAfter = getRetryAfterHeader(); if (retryAfter.isPresent()) { throw new AcmeRetryAfterException(message, retryAfter.get()); } }
throw new AcmeException("No challenge found"); while (challenge.getStatus() != Status.VALID && attempts-- > 0) { if (challenge.getStatus() == Status.INVALID) { throw new AcmeException("Challenge failed... Giving up."); throw new AcmeException("Failed to pass the challenge for domain " + auth.getIdentifier().getDomain() + ", ... Giving up.");
/** * Returns the domain name if this is a DNS identifier. * * @return Domain name. Unicode domains are ASCII encoded. * @throws AcmeProtocolException * if this is not a DNS identifier. */ public String getDomain() { if (!TYPE_DNS.equals(type)) { throw new AcmeProtocolException("expected 'dns' identifier, but found '" + type + "'"); } return value; }
/** * Returns the {@link URL} of a document that gives instructions on the actions to * be taken by a human. */ public URL getInstance() { URI instance = getProblem().getInstance(); if (instance == null) { throw new AcmeProtocolException("Instance URL required, but missing."); } try { return instance.toURL(); } catch (MalformedURLException ex) { throw new AcmeProtocolException("Bad instance URL: " + instance.toString(), ex); } }
/** * Lazily downloads the certificate. Throws a runtime {@link AcmeLazyLoadingException} * if the download failed. */ private void lazyDownload() { try { download(); } catch (AcmeException ex) { throw new AcmeLazyLoadingException(this, ex); } }
while (order.getStatus() != Status.VALID && attempts-- > 0) { if (order.getStatus() == Status.INVALID) { throw new AcmeException("Order failed... Giving up.");
/** * Returns the value as boolean. */ public boolean asBoolean() { required(); try { return (Boolean) val; } catch (ClassCastException ex) { throw new AcmeProtocolException(path + ": bad boolean " + val, ex); } }
/** * Presents the instructions for preparing the challenge validation, and waits for * dismissal. If the user cancelled the dialog, an exception is thrown. * * @param message * Instructions to be shown in the dialog */ public void acceptChallenge(String message) throws AcmeException { int option = JOptionPane.showConfirmDialog(null, message, "Prepare Challenge", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.CANCEL_OPTION) { throw new AcmeException("User cancelled the challenge"); } }
/** * Checks if the value is present. An {@link AcmeProtocolException} is thrown if * the value is {@code null}. */ private void required() { if (!isPresent()) { throw new AcmeProtocolException(path + ": required, but not set"); } }
/** * Presents the user a link to the Terms of Service, and asks for confirmation. If the * user denies confirmation, an exception is thrown. * * @param agreement * {@link URI} of the Terms of Service */ public void acceptAgreement(URI agreement) throws AcmeException { int option = JOptionPane.showConfirmDialog(null, "Do you accept the Terms of Service?\n\n" + agreement, "Accept ToS", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.NO_OPTION) { throw new AcmeException("User did not accept Terms of Service"); } }
/** * Returns the value as boolean. */ public boolean asBoolean() { required(); try { return (Boolean) val; } catch (ClassCastException ex) { throw new AcmeProtocolException(path + ": bad boolean " + val, ex); } }
/** * Checks if the value is present. An {@link AcmeProtocolException} is thrown if * the value is {@code null}. */ private void required() { if (!isPresent()) { throw new AcmeProtocolException(path + ": required, but not set"); } }
/** * Fetches the next batch of URLs. Handles exceptions. Does nothing if there is no * URL of the next batch. */ private void fetch() { if (nextUrl == null) { return; } try { readAndQueue(); } catch (AcmeException ex) { throw new AcmeProtocolException("failed to read next set of " + field, ex); } }
/** * Fetches the next batch of URLs. Handles exceptions. Does nothing if there is no * URL of the next batch. */ private void fetch() { if (nextUrl == null) { return; } try { readAndQueue(); } catch (AcmeException ex) { throw new AcmeProtocolException("failed to read next set of " + field, ex); } }
/** * Returns the value as int. */ public int asInt() { required(); try { return ((Number) val).intValue(); } catch (ClassCastException ex) { throw new AcmeProtocolException(path + ": bad number " + val, ex); } }
/** * Returns the value as JSON object. */ public JSON asObject() { required(); try { return new JSON(path, (Map<String, Object>) val); } catch (ClassCastException ex) { throw new AcmeProtocolException(path + ": expected an object", ex); } }