From 535543e7b16a06ab0b2e59db8f4a736bf5913216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Sun, 13 Dec 2015 14:25:06 +0100 Subject: [PATCH] Check content-type header --- .../shredzone/acme4j/connector/Connection.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/connector/Connection.java b/acme4j-client/src/main/java/org/shredzone/acme4j/connector/Connection.java index 5eec9be6..bd80ebcf 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/connector/Connection.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/connector/Connection.java @@ -184,6 +184,12 @@ public class Connection implements AutoCloseable { throw new IllegalStateException("Not connected"); } + String contentType = conn.getHeaderField("Content-Type"); + if (!("application/json".equals(contentType) + || "application/problem+json".equals(contentType))) { + throw new AcmeException("Unexpected content type: " + contentType); + } + StringBuilder sb = new StringBuilder(); Map result = null; @@ -215,6 +221,11 @@ public class Connection implements AutoCloseable { throw new IllegalStateException("Not connected"); } + String contentType = conn.getHeaderField("Content-Type"); + if (!("application/pkix-cert".equals(contentType))) { + throw new AcmeException("Unexpected content type: " + contentType); + } + try (InputStream in = conn.getInputStream()) { CertificateFactory cf = CertificateFactory.getInstance("X.509"); return (X509Certificate) cf.generateCertificate(in); @@ -231,6 +242,11 @@ public class Connection implements AutoCloseable { * @return Map of {@link Resource} and the respective {@link URI} to invoke */ public Map readDirectory() throws AcmeException { + String contentType = conn.getHeaderField("Content-Type"); + if (!("application/json".equals(contentType))) { + throw new AcmeException("Unexpected content type: " + contentType); + } + EnumMap resourceMap = new EnumMap<>(Resource.class); StringBuilder sb = new StringBuilder();