diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java index b2724a77..89185af4 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Authorization.java @@ -18,6 +18,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Date; import java.util.List; import org.shredzone.acme4j.challenge.Challenge; @@ -33,7 +34,7 @@ public class Authorization implements Serializable { private URI location; private String domain; private Status status; - private String expires; + private Date expires; private List challenges; private List> combinations; @@ -96,14 +97,14 @@ public class Authorization implements Serializable { /** * Gets the expiry date of the authorization, if set by the server. */ - public String getExpires() { + public Date getExpires() { return expires; } /** * Sets the expiry date of the authorization. */ - public void setExpires(String expires) { + public void setExpires(Date expires) { this.expires = expires; } diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java b/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java index fb7a8ad4..72620df6 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java @@ -15,6 +15,7 @@ package org.shredzone.acme4j.challenge; import java.io.Serializable; import java.net.URI; +import java.util.Date; import java.util.Map; import org.shredzone.acme4j.Status; @@ -45,7 +46,7 @@ public interface Challenge extends Serializable { /** * Returns the validation date, if returned by the server. */ - String getValidated(); + Date getValidated(); /** * Sets the challenge state by reading the given JSON map. diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/GenericChallenge.java b/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/GenericChallenge.java index 9b1b614f..dd8b4871 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/GenericChallenge.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/GenericChallenge.java @@ -22,6 +22,7 @@ import java.net.URISyntaxException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -31,6 +32,7 @@ import org.jose4j.jwk.JsonWebKey.OutputControlLevel; import org.jose4j.lang.JoseException; import org.shredzone.acme4j.Status; import org.shredzone.acme4j.util.ClaimBuilder; +import org.shredzone.acme4j.util.TimestampParser; /** * A generic implementation of {@link Challenge}. It can be used as a base class for @@ -78,8 +80,13 @@ public class GenericChallenge implements Challenge { } @Override - public String getValidated() { - return get(KEY_VALIDATED); + public Date getValidated() { + String valStr = get(KEY_VALIDATED); + if (valStr != null) { + return TimestampParser.parse(valStr); + } else { + return null; + } } @Override diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/impl/AbstractAcmeClient.java b/acme4j-client/src/main/java/org/shredzone/acme4j/impl/AbstractAcmeClient.java index e1680a6a..65366982 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/impl/AbstractAcmeClient.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/impl/AbstractAcmeClient.java @@ -34,6 +34,7 @@ import org.shredzone.acme4j.connector.Session; import org.shredzone.acme4j.exception.AcmeConflictException; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.util.ClaimBuilder; +import org.shredzone.acme4j.util.TimestampParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -412,7 +413,11 @@ public abstract class AbstractAcmeClient implements AcmeClient { @SuppressWarnings("unchecked") private void unmarshalAuthorization(Map json, Authorization auth) { auth.setStatus(Status.parse((String) json.get("status"), Status.PENDING)); - auth.setExpires((String) json.get("expires")); + + String expires = (String) json.get("expires"); + if (expires != null) { + auth.setExpires(TimestampParser.parse(expires)); + } Map identifier = (Map) json.get("identifier"); if (identifier != null) { diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java index e61b166e..73ed36d3 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/AuthorizationTest.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -71,6 +72,8 @@ public class AuthorizationTest { */ @Test public void testGetterAndSetter() { + Date expiry = new Date(); + Authorization auth = new Authorization(); assertThat(auth.getDomain(), is(nullValue())); @@ -81,13 +84,13 @@ public class AuthorizationTest { auth.setDomain("example.com"); auth.setStatus(Status.INVALID); - auth.setExpires("2015-12-12T17:19:36.336785823Z"); + auth.setExpires(expiry); auth.setChallenges(authorization.getChallenges()); auth.setCombinations(authorization.getCombinations()); assertThat(auth.getDomain(), is("example.com")); assertThat(auth.getStatus(), is(Status.INVALID)); - assertThat(auth.getExpires(), is("2015-12-12T17:19:36.336785823Z")); + assertThat(auth.getExpires(), is(expiry)); assertThat(auth.getChallenges(), is(sameInstance(authorization.getChallenges()))); assertThat(auth.getCombinations(), is(sameInstance(authorization.getCombinations()))); } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/GenericChallengeTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/GenericChallengeTest.java index f8c8bf61..4a013f59 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/GenericChallengeTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/GenericChallengeTest.java @@ -35,6 +35,7 @@ import org.junit.Test; import org.shredzone.acme4j.Status; import org.shredzone.acme4j.util.ClaimBuilder; import org.shredzone.acme4j.util.TestUtils; +import org.shredzone.acme4j.util.TimestampParser; /** * Unit tests for {@link GenericChallenge}. @@ -63,7 +64,7 @@ public class GenericChallengeTest { assertThat(challenge.getType(), is("generic-01")); assertThat(challenge.getStatus(), is(Status.VALID)); assertThat(challenge.getLocation(), is(new URI("http://example.com/challenge/123"))); - assertThat(challenge.getValidated(), is("2015-12-12T17:19:36.336785823Z")); + assertThat(challenge.getValidated(), is(TimestampParser.parse("2015-12-12T17:19:36.336785823Z"))); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/impl/AbstractAcmeClientTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/impl/AbstractAcmeClientTest.java index f1efce84..697898a4 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/impl/AbstractAcmeClientTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/impl/AbstractAcmeClientTest.java @@ -42,6 +42,7 @@ import org.shredzone.acme4j.connector.Session; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.util.ClaimBuilder; import org.shredzone.acme4j.util.TestUtils; +import org.shredzone.acme4j.util.TimestampParser; /** * Unit tests for {@link AbstractAcmeClient}. @@ -275,7 +276,7 @@ public class AbstractAcmeClientTest { assertThat(auth.getDomain(), is("example.org")); assertThat(auth.getStatus(), is(Status.VALID)); - assertThat(auth.getExpires(), is("2015-03-01")); + assertThat(auth.getExpires(), is(TimestampParser.parse("2016-01-02T17:12:40Z"))); assertThat(auth.getLocation(), is(locationUri)); assertThat(auth.getChallenges(), containsInAnyOrder( diff --git a/acme4j-client/src/test/resources/json.properties b/acme4j-client/src/test/resources/json.properties index 8fb7287c..9f435b39 100644 --- a/acme4j-client/src/test/resources/json.properties +++ b/acme4j-client/src/test/resources/json.properties @@ -58,7 +58,7 @@ newAuthorizationResponse = \ updateAuthorizationResponse = \ {\ "status": "valid",\ - "expires": "2015-03-01",\ + "expires": "2016-01-02T17:12:40Z",\ "identifier": {\ "type": "dns",\ "value": "example.org"\