diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Certificate.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Certificate.java index 5816109a..05875d5c 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Certificate.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Certificate.java @@ -167,9 +167,6 @@ public class Certificate extends AcmeResource { Session session = login.getSession(); URL resUrl = session.resourceUrl(Resource.REVOKE_CERT); - if (resUrl == null) { - throw new AcmeException("Server does not allow certificate revocation"); - } try (Connection conn = session.connect()) { JSONBuilder claims = new JSONBuilder(); @@ -204,9 +201,6 @@ public class Certificate extends AcmeResource { LOG.debug("revoke using the domain key pair"); URL resUrl = session.resourceUrl(Resource.REVOKE_CERT); - if (resUrl == null) { - throw new AcmeException("Server does not allow certificate revocation"); - } try (Connection conn = session.connect()) { JSONBuilder claims = new JSONBuilder(); 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 6e0bf638..fcb090d9 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 @@ -128,7 +128,7 @@ public class Challenge extends AcmeJsonResource { } String loc = json.get(KEY_URL).asString(); - if (loc != null && !loc.equals(getLocation().toString())) { + if (!loc.equals(getLocation().toString())) { throw new AcmeProtocolException("challenge has changed its location"); } diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/toolbox/AcmeUtils.java b/acme4j-client/src/main/java/org/shredzone/acme4j/toolbox/AcmeUtils.java index f705f5aa..1c6d54a0 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/toolbox/AcmeUtils.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/toolbox/AcmeUtils.java @@ -13,8 +13,9 @@ */ package org.shredzone.acme4j.toolbox; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.io.Writer; import java.net.IDN; import java.net.URI; @@ -99,9 +100,9 @@ public final class AcmeUtils { public static byte[] sha256hash(String z) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); - md.update(z.getBytes("UTF-8")); + md.update(z.getBytes(UTF_8)); return md.digest(); - } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { + } catch (NoSuchAlgorithmException ex) { throw new AcmeProtocolException("Could not compute hash", ex); } } diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/toolbox/JSON.java b/acme4j-client/src/main/java/org/shredzone/acme4j/toolbox/JSON.java index 237e79a9..4742f5f8 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/toolbox/JSON.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/toolbox/JSON.java @@ -13,6 +13,7 @@ */ package org.shredzone.acme4j.toolbox; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp; @@ -27,7 +28,6 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; import java.util.Collections; @@ -96,7 +96,7 @@ public final class JSON implements Serializable { * @return {@link JSON} of the read content. */ public static JSON parse(InputStream in) throws IOException { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, UTF_8))) { String json = reader.lines().map(String::trim).collect(joining()); return parse(json); } @@ -347,7 +347,7 @@ public final class JSON implements Serializable { required(); try { byte[] raw = AcmeUtils.base64UrlDecode(val.toString()); - return new JSON(path, JsonUtil.parseJson(new String(raw, StandardCharsets.UTF_8))); + return new JSON(path, JsonUtil.parseJson(new String(raw, UTF_8))); } catch (IllegalArgumentException | JoseException ex) { throw new AcmeProtocolException(path + ": expected an encoded object", ex); } @@ -494,7 +494,7 @@ public final class JSON implements Serializable { @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof Value)) { + if (!(obj instanceof Value)) { return false; } return Objects.equals(val, ((Value) obj).val); diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/TestUtils.java b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/TestUtils.java index 3ff0a718..67cac425 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/TestUtils.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/toolbox/TestUtils.java @@ -13,6 +13,7 @@ */ package org.shredzone.acme4j.toolbox; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.unmodifiableList; import static java.util.stream.Collectors.toList; @@ -319,7 +320,7 @@ public final class TestUtils { final JsonWebKey jwk = JsonWebKey.Factory.newJwk(keyPair.getPublic()); Map params = new TreeMap<>(jwk.toParams(OutputControlLevel.PUBLIC_ONLY)); MessageDigest md = MessageDigest.getInstance("SHA-256"); - md.update(JsonUtil.toJson(params).getBytes("UTF-8")); + md.update(JsonUtil.toJson(params).getBytes(UTF_8)); byte[] thumbprint = md.digest(); System.out.println("N = " + params.get("n")); diff --git a/acme4j-utils/src/main/java/org/shredzone/acme4j/util/CSRBuilder.java b/acme4j-utils/src/main/java/org/shredzone/acme4j/util/CSRBuilder.java index d53bf0d7..74968244 100644 --- a/acme4j-utils/src/main/java/org/shredzone/acme4j/util/CSRBuilder.java +++ b/acme4j-utils/src/main/java/org/shredzone/acme4j/util/CSRBuilder.java @@ -13,6 +13,7 @@ */ package org.shredzone.acme4j.util; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.joining; import static org.shredzone.acme4j.toolbox.AcmeUtils.toAce; @@ -311,7 +312,7 @@ public class CSRBuilder { * is closed after use. */ public void write(OutputStream out) throws IOException { - write(new OutputStreamWriter(out, "utf-8")); + write(new OutputStreamWriter(out, UTF_8)); } @Override