Skip to content

Commit

Permalink
Fix wrong status for verification and download challenges commands fo…
Browse files Browse the repository at this point in the history
…r not authorized domains
  • Loading branch information
porunov committed Apr 20, 2017
1 parent 206a222 commit 39a59d8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -131,6 +132,19 @@ void writeChallengeByAuthorization(AuthorizationManager authorizationManagement)
}
}

HashSet<String> getDomains(List<Authorization> authorizationList){
HashSet<String> domains;
if(getParameters().getDomains() == null){
domains = new HashSet<>();
for (Authorization authorization : authorizationList) {
domains.add(authorization.getDomain());
}
}else {
domains = new HashSet<>(getParameters().getDomains());
}
return domains;
}

String getChallengeType() {
String challengeType = null;
if (getParameters().getChallengeType().equalsIgnoreCase(Parameters.CHALLENGE_HTTP01)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public DownloadChallengesCommand(Parameters parameters) throws AccountKeyNotFoun

@Override
public void commandExecution() {
HashSet<String> succeedDomains = new HashSet<>();
HashSet<String> failedDomains = new HashSet<>();

List<Authorization> authorizationList = getNotExpiredAuthorizations();
if (authorizationList == null) {
LOG.error("Cannot read file: " +
Expand All @@ -31,27 +28,34 @@ public void commandExecution() {
return;
}

HashSet<String> domains = getDomains(authorizationList);
HashSet<String> authorizedDomains = new HashSet<>();

for (Authorization authorization : authorizationList) {
if (getParameters().getDomains() == null || getParameters().getDomains().contains(authorization.getDomain())) {
authorizedDomains.add(authorization.getDomain());
if (domains.contains(authorization.getDomain())) {
try {
writeChallengeByAuthorization(new AuthorizationManager(authorization));
if (!succeedDomains.contains(authorization.getDomain()))
succeedDomains.add(authorization.getDomain());
domains.remove(authorization.getDomain());
} catch (Exception e) {
LOG.warn("Cannot get challenge for authorization: " + authorization.getLocation()
+ "\nDomain: " + authorization.getDomain(), e);
if (!failedDomains.contains(authorization.getDomain()))
failedDomains.add(authorization.getDomain());
}
}
}

for(String domain : domains){
if(!authorizedDomains.contains(domain)){
LOG.error("Domain " + domain + " is not authorized. Please, authorize it first.");
}else {
LOG.error("Domain " + domain + " is not verified. Please, check warnings.");
}
}

error = error || !writeAuthorizationList(authorizationList);

failedDomains.removeAll(succeedDomains);

if (failedDomains.size() > 0) {
JsonElement failedDomainsJsonElement = getGson().toJsonTree(failedDomains,
if (domains.size() > 0) {
JsonElement failedDomainsJsonElement = getGson().toJsonTree(domains,
new TypeToken<HashSet<String>>() {}.getType());
result.add("failed_domains", failedDomainsJsonElement);
error=true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public VerifyDomainsCommand(Parameters parameters) throws AccountKeyNotFoundExce

@Override
public void commandExecution() {
HashSet<String> verifiedDomains = new HashSet<>();
HashSet<String> failedDomains = new HashSet<>();

List<Authorization> authorizationList = getNotExpiredAuthorizations();
if (authorizationList == null) {
LOG.error("Cannot read file: " +
Expand All @@ -33,30 +30,35 @@ public void commandExecution() {
return;
}

HashSet<String> domains = getDomains(authorizationList);
HashSet<String> authorizedDomains = new HashSet<>();

for (Authorization authorization : authorizationList) {
if (getParameters().getDomains() == null || getParameters().getDomains().contains(authorization.getDomain())) {
authorizedDomains.add(authorization.getDomain());
if (domains.contains(authorization.getDomain())) {
try {
new ChallengeManager(authorization, getChallengeType()).validateChallenge(60000);
if (!verifiedDomains.contains(authorization.getDomain()))
verifiedDomains.add(authorization.getDomain());
domains.remove(authorization.getDomain());
} catch (TimeoutException ex) {
LOG.warn("Authorization " + authorization.getLocation() + " haven't been verified. Time out exception", ex);
if (!failedDomains.contains(authorization.getDomain()))
failedDomains.add(authorization.getDomain());
} catch (AcmeException ex) {
LOG.warn("Authorization " + authorization.getLocation() + " haven't been verified.", ex);
if (!failedDomains.contains(authorization.getDomain()))
failedDomains.add(authorization.getDomain());
}
}
}

error = error || !writeAuthorizationList(authorizationList);
for(String domain : domains){
if(!authorizedDomains.contains(domain)){
LOG.error("Domain " + domain + " is not authorized. Please, authorize it first.");
}else {
LOG.error("Domain " + domain + " is not verified. Please, check warnings.");
}
}

failedDomains.removeAll(verifiedDomains);
error = error || !writeAuthorizationList(authorizationList);

if (failedDomains.size() > 0) {
JsonElement failedDomainsJsonElement = getGson().toJsonTree(failedDomains, new TypeToken<HashSet<String>>() {
if (domains.size() > 0) {
JsonElement failedDomainsJsonElement = getGson().toJsonTree(domains, new TypeToken<HashSet<String>>() {
}.getType());
result.add("failed_domains", failedDomainsJsonElement);
error=true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.1.0
version=Porunov Java ACME Client (PJAC) v2.1.1 rev51

0 comments on commit 39a59d8

Please sign in to comment.