mirror of https://github.com/shred/acme4j
Add SpotBugs and fix reported issues
parent
69a23e7bf6
commit
09abb23599
|
@ -168,13 +168,14 @@ public class Session {
|
||||||
private void readDirectory() throws AcmeException {
|
private void readDirectory() throws AcmeException {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
if (directoryJson != null && directoryCacheExpiry.isAfter(now)) {
|
if (directoryCacheExpiry != null && directoryCacheExpiry.isAfter(now)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
directoryJson = provider().directory(this, getServerUri());
|
|
||||||
directoryCacheExpiry = now.plus(Duration.ofHours(1));
|
directoryCacheExpiry = now.plus(Duration.ofHours(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON directoryJson = provider().directory(this, getServerUri());
|
||||||
|
|
||||||
JSON meta = directoryJson.get("meta").asObject();
|
JSON meta = directoryJson.get("meta").asObject();
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
metadata.set(new Metadata(meta));
|
metadata.set(new Metadata(meta));
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package org.shredzone.acme4j.provider.pebble;
|
package org.shredzone.acme4j.provider.pebble;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
|
@ -52,10 +53,9 @@ public class PebbleHttpConnector extends HttpConnector {
|
||||||
*/
|
*/
|
||||||
protected synchronized SSLSocketFactory createSocketFactory() throws IOException {
|
protected synchronized SSLSocketFactory createSocketFactory() throws IOException {
|
||||||
if (sslSocketFactory == null) {
|
if (sslSocketFactory == null) {
|
||||||
try {
|
try (InputStream in = getClass().getResourceAsStream("/org/shredzone/acme4j/provider/pebble/pebble.truststore")) {
|
||||||
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
keystore.load(getClass().getResourceAsStream("/org/shredzone/acme4j/provider/pebble/pebble.truststore"),
|
keystore.load(in, "acme4j".toCharArray());
|
||||||
"acme4j".toCharArray());
|
|
||||||
|
|
||||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||||
tmf.init(keystore);
|
tmf.init(keystore);
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.net.IDN;
|
import java.net.IDN;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
@ -58,7 +59,8 @@ public final class AcmeUtils {
|
||||||
private static final Pattern CONTENT_TYPE_PATTERN = Pattern.compile(
|
private static final Pattern CONTENT_TYPE_PATTERN = Pattern.compile(
|
||||||
"([^;]+)(?:;.*?charset=(\"?)([a-z0-9_-]+)(\\2))?.*", Pattern.CASE_INSENSITIVE);
|
"([^;]+)(?:;.*?charset=(\"?)([a-z0-9_-]+)(\\2))?.*", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
private static final Base64.Encoder PEM_ENCODER = Base64.getMimeEncoder(64, "\n".getBytes());
|
private static final Base64.Encoder PEM_ENCODER = Base64.getMimeEncoder(64,
|
||||||
|
"\n".getBytes(StandardCharsets.US_ASCII));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration of PEM labels.
|
* Enumeration of PEM labels.
|
||||||
|
@ -305,7 +307,7 @@ public final class AcmeUtils {
|
||||||
*/
|
*/
|
||||||
public static void writeToPem(byte[] encoded, PemLabel label, Writer out) throws IOException {
|
public static void writeToPem(byte[] encoded, PemLabel label, Writer out) throws IOException {
|
||||||
out.append("-----BEGIN ").append(label.toString()).append("-----\n");
|
out.append("-----BEGIN ").append(label.toString()).append("-----\n");
|
||||||
out.append(new String(PEM_ENCODER.encode(encoded)));
|
out.append(new String(PEM_ENCODER.encode(encoded), StandardCharsets.US_ASCII));
|
||||||
out.append("\n-----END ").append(label.toString()).append("-----\n");
|
out.append("\n-----END ").append(label.toString()).append("-----\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<!-- I prefer readability over maintainability in the examples... -->
|
<!-- I prefer readability over maintainability in the examples... -->
|
||||||
<sonar.skip>true</sonar.skip>
|
<sonar.skip>true</sonar.skip>
|
||||||
|
<spotbugs.skip>true</spotbugs.skip>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -16,6 +16,7 @@ package org.shredzone.acme4j.util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.bouncycastle.openssl.PEMParser;
|
import org.bouncycastle.openssl.PEMParser;
|
||||||
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||||
|
@ -40,7 +41,7 @@ public final class CertificateUtils {
|
||||||
* @return CSR that was read
|
* @return CSR that was read
|
||||||
*/
|
*/
|
||||||
public static PKCS10CertificationRequest readCSR(InputStream in) throws IOException {
|
public static PKCS10CertificationRequest readCSR(InputStream in) throws IOException {
|
||||||
try (PEMParser pemParser = new PEMParser(new InputStreamReader(in))) {
|
try (PEMParser pemParser = new PEMParser(new InputStreamReader(in, StandardCharsets.US_ASCII))) {
|
||||||
Object parsedObj = pemParser.readObject();
|
Object parsedObj = pemParser.readObject();
|
||||||
if (!(parsedObj instanceof PKCS10CertificationRequest)) {
|
if (!(parsedObj instanceof PKCS10CertificationRequest)) {
|
||||||
throw new IOException("Not a PKCS10 CSR");
|
throw new IOException("Not a PKCS10 CSR");
|
||||||
|
|
17
pom.xml
17
pom.xml
|
@ -79,6 +79,18 @@
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.spotbugs</groupId>
|
||||||
|
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
@ -188,6 +200,11 @@
|
||||||
<locale>en</locale>
|
<locale>en</locale>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.spotbugs</groupId>
|
||||||
|
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</reporting>
|
</reporting>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
Loading…
Reference in New Issue