Java Code Examples for org.shredzone.acme4j.Authorization#findChallenge()

The following examples show how to use org.shredzone.acme4j.Authorization#findChallenge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChallengeManager.java    From acme_client with MIT License 5 votes vote down vote up
public ChallengeManager(Authorization authorization, String type, Login login) throws AcmeException {
    this.challenge = authorization.findChallenge(type);
    if (this.challenge == null) throw new AcmeException();
    try {
        challenge.rebind(login);
    } catch (Exception ex) {
        LOG.warn("Can not rebind challenge: " + challenge.getLocation() + " to login: " +
                login.getAccountLocation().toString(), ex);
    }
}
 
Example 2
Source File: LetsEncryptReloadLifecycle.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
private Challenge httpChallenge(final Authorization auth) throws AcmeException {
    final Http01Challenge challenge = auth.findChallenge(Http01Challenge.TYPE);
    if (challenge == null) {
        throw new AcmeException("Challenge is null");
    }

    challengeUpdater.accept("/.well-known/acme-challenge/" + challenge.getToken(), challenge.getAuthorization());
    return challenge;
}
 
Example 3
Source File: AcmeClient.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: AcmeClient.java    From r2cloud with Apache License 2.0 4 votes vote down vote up
private void authorize(Registration reg, String domain) throws AcmeException, IOException {
	messages.add("authorizing domain: " + domain, LOG);
	Authorization auth = reg.authorizeDomain(domain);
	messages.add("find http challenge", LOG);
	Http01Challenge challenge1 = auth.findChallenge(Http01Challenge.TYPE);
	if (challenge1 == null) {
		throw new AcmeException("Found no " + Http01Challenge.TYPE + " challenge, don't know what to do...");
	}
	messages.add("saving challenge request", LOG);
	try (FileOutputStream fos = new FileOutputStream(new File(challengePath, challenge1.getToken()))) {
		fos.write(challenge1.getAuthorization().getBytes(StandardCharsets.UTF_8));
	}

	Challenge challenge = challenge1;
	if (challenge.getStatus() == Status.VALID) {
		messages.add("challenge already successeded", LOG);
		return;
	}
	messages.add("trigger challenge", LOG);
	challenge.trigger();

	// Poll for the challenge to complete.
	long retryTimeout = INITIAL_RETRY;
	while (challenge.getStatus() != Status.VALID && !Thread.currentThread().isInterrupted()) {
		// Did the authorization fail?
		if (challenge.getStatus() == Status.INVALID) {
			messages.add("Authorization failed: " + challenge.getError().getDetail());
			throw new AcmeException("Challenge failed...");
		}

		try {
			Thread.sleep(retryTimeout);
		} catch (InterruptedException ex) {
			Thread.currentThread().interrupt();
			break;
		}

		try {
			messages.add("update challenge", LOG);
			challenge.update();
		} catch (AcmeRetryAfterException e) {
			retryTimeout = e.getRetryAfter().toEpochMilli() - System.currentTimeMillis();
			messages.add("not ready. retry after: " + retryTimeout + " millis", LOG);
		}
	}

	// All reattempts are used up and there is still no valid authorization?
	if (challenge.getStatus() != Status.VALID) {
		throw new AcmeException("Failed to pass the challenge for domain " + domain + ", ... Giving up.");
	}
}
 
Example 5
Source File: ChallengeManager.java    From acme_client with MIT License 4 votes vote down vote up
public ChallengeManager(Authorization authorization, String type) throws AcmeException {
    this.challenge = authorization.findChallenge(type);
    if (this.challenge == null) throw new AcmeException("CA didn't provide any challenge for type: "+type);
}
 
Example 6
Source File: CertGenerator.java    From spring-boot-starter-acme with Apache License 2.0 3 votes vote down vote up
/**
 * Prepares a HTTP challenge.
 * <p>
 * The verification of this challenge expects a file with a certain content to be
 * reachable at a given path under the domain to be tested.
 * </p>
 *
 * @param aAuthorization
 *            {@link Authorization} to find the challenge in
 * @param aDomainName
 *            Domain name to be authorized
 * @return {@link Challenge} to verify
 */
private Challenge httpChallenge(Authorization aAuthorization, String aDomainName) throws AcmeException {
  // Find a single http-01 challenge
  Http01Challenge challenge = aAuthorization.findChallenge(Http01Challenge.TYPE);
  
  if (challenge == null) {
    throw new AcmeException("Found no " + Http01Challenge.TYPE + " challenge, don't know what to do...");
  }
  
  challengeStore.put(challenge.getToken(), challenge.getAuthorization());

  return challenge;
}