Skip to content

Commit 73844e2

Browse files
authored
Merge pull request #360 from trellis-ldp/trellis-359
Remove support for Digest/Want-Digest
2 parents 6c9c59a + 53d7484 commit 73844e2

File tree

32 files changed

+40
-852
lines changed

32 files changed

+40
-852
lines changed

components/app/src/main/java/org/trellisldp/app/config/CORSConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public class CORSConfiguration {
3232
"GET", "HEAD", "OPTIONS", "POST");
3333

3434
private List<String> allowHeaders = asList("Content-Type", "Link", "Accept",
35-
"Accept-Datetime", "Prefer", "Want-Digest", "Slug", "Digest", "Origin");
35+
"Accept-Datetime", "Prefer", "Slug", "Origin");
3636

3737
private List<String> exposeHeaders = asList("Content-Type", "Link",
3838
"Memento-Datetime", "Preference-Applied", "Location",
39-
"Accept-Patch", "Accept-Post", "Digest", "Accept-Ranges", "ETag", "Vary");
39+
"Accept-Patch", "Accept-Post", "Accept-Ranges", "ETag", "Vary");
4040

4141
private boolean allowCredentials = true;
4242

components/app/src/test/java/org/trellisldp/app/config/TrellisConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void testConfigurationCORS1() throws Exception {
143143

144144
assertTrue(config.getCors().getEnabled(), "CORS not enabled!");
145145
assertTrue(config.getCors().getAllowOrigin().contains("*"), "'*' not in CORS allow-origin!");
146-
assertTrue(config.getCors().getAllowHeaders().contains("Want-Digest"), "want-digest not in CORS allow-headers");
146+
assertTrue(config.getCors().getAllowHeaders().contains("Link"), "Link not in CORS allow-headers");
147147
assertTrue(config.getCors().getAllowMethods().contains("PUT"), "PUT not in CORS allow-methods!");
148148
assertTrue(config.getCors().getExposeHeaders().contains("Memento-Datetime"),
149149
"memento-datetime missing from CORS expose-headers!");

components/app/src/test/resources/config1.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ cors:
7777
- "PATCH"
7878
allowHeaders:
7979
- "Content-Type"
80-
- "Want-Digest"
8180
- "Link"
8281
exposeHeaders:
8382
- "Link"

components/file/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dependencies {
1212
api("org.glassfish.hk2.external:javax.inject:$javaxInjectVersion")
1313
api project(':trellis-api')
1414

15-
implementation("commons-codec:commons-codec:$commonsCodecVersion")
1615
implementation("commons-io:commons-io:$commonsIoVersion")
1716
implementation("org.apache.commons:commons-rdf-jena:$commonsRdfVersion") {
1817
exclude group: 'org.apache.jena', module: 'jena-osgi'

components/file/src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
requires transitive org.trellisldp.api;
1818
requires transitive org.trellisldp.vocabulary;
1919

20-
requires org.apache.commons.codec;
2120
requires org.apache.commons.io;
2221
requires org.apache.commons.rdf.api;
2322
requires org.apache.commons.rdf.jena;

components/file/src/main/java/org/trellisldp/file/FileBinaryService.java

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,19 @@
1616
import static java.nio.file.Files.copy;
1717
import static java.nio.file.Files.delete;
1818
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
19-
import static java.util.Arrays.asList;
2019
import static java.util.Objects.requireNonNull;
2120
import static java.util.Optional.of;
2221
import static java.util.ServiceLoader.load;
2322
import static java.util.concurrent.CompletableFuture.supplyAsync;
24-
import static java.util.stream.Collectors.toSet;
25-
import static org.apache.commons.codec.digest.DigestUtils.updateDigest;
26-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.MD2;
27-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.MD5;
28-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA3_256;
29-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA3_384;
30-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA3_512;
31-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA_1;
32-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA_256;
33-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA_384;
34-
import static org.apache.commons.codec.digest.MessageDigestAlgorithms.SHA_512;
3523
import static org.slf4j.LoggerFactory.getLogger;
3624

3725
import java.io.File;
38-
import java.io.FileInputStream;
3926
import java.io.IOException;
4027
import java.io.InputStream;
4128
import java.io.UncheckedIOException;
4229
import java.net.URI;
43-
import java.security.MessageDigest;
4430
import java.util.Iterator;
4531
import java.util.ServiceLoader;
46-
import java.util.Set;
4732
import java.util.concurrent.CompletionStage;
4833
import java.util.function.Supplier;
4934

@@ -61,24 +46,6 @@
6146

6247
/**
6348
* A {@link BinaryService} implementation that stores LDP-NR resources as files on a local filesystem.
64-
*
65-
* <p>This service supports the following digest algorithms:
66-
* <ul>
67-
* <li>MD5</li>
68-
* <li>MD2</li>
69-
* <li>SHA</li>
70-
* <li>SHA-1</li>
71-
* <li>SHA-256</li>
72-
* <li>SHA-384</li>
73-
* <li>SHA-512</li>
74-
* </ul>
75-
*
76-
* <p>When running under JDK 9+, the following additional digest algorithms are supported:
77-
* <ul>
78-
* <li>SHA3-256</li>
79-
* <li>SHA3-384</li>
80-
* <li>SHA3-512</li>
81-
* </ul>
8249
*/
8350
public class FileBinaryService implements BinaryService {
8451

@@ -92,14 +59,9 @@ public class FileBinaryService implements BinaryService {
9259
public static final String CONFIG_FILE_BINARY_LENGTH = "trellis.file.binary.length";
9360

9461
private static final Logger LOGGER = getLogger(FileBinaryService.class);
95-
private static final String SHA = "SHA";
9662
private static final int DEFAULT_HIERARCHY = 3;
9763
private static final int DEFAULT_LENGTH = 2;
9864

99-
private static final Set<String> algorithms = asList(MD5, MD2, SHA, SHA_1, SHA_256, SHA_384, SHA_512,
100-
SHA3_256, SHA3_384, SHA3_512).stream()
101-
.collect(toSet());
102-
10365
private final String basePath;
10466
private final Supplier<String> idSupplier;
10567

@@ -176,16 +138,6 @@ public CompletionStage<Void> setContent(final BinaryMetadata metadata, final Inp
176138
});
177139
}
178140

179-
@Override
180-
public CompletionStage<MessageDigest> calculateDigest(final IRI identifier, final MessageDigest algorithm) {
181-
return supplyAsync(() -> computeDigest(identifier, algorithm));
182-
}
183-
184-
@Override
185-
public Set<String> supportedAlgorithms() {
186-
return algorithms;
187-
}
188-
189141
@Override
190142
public String generateIdentifier() {
191143
return idSupplier.get();
@@ -198,14 +150,6 @@ private File getFileFromIdentifier(final IRI identifier) {
198150
.orElseThrow(() -> new IllegalArgumentException("Could not create File object from IRI: " + identifier));
199151
}
200152

201-
private MessageDigest computeDigest(final IRI identifier, final MessageDigest algorithm) {
202-
try (final InputStream input = new FileInputStream(getFileFromIdentifier(identifier))) {
203-
return updateDigest(algorithm, input);
204-
} catch (final IOException ex) {
205-
throw new UncheckedIOException("Error computing digest", ex);
206-
}
207-
}
208-
209153
private static String trimStart(final String str, final String trim) {
210154
if (str.startsWith(trim)) {
211155
return trimStart(str.substring(trim.length()), trim);

components/file/src/test/java/org/trellisldp/file/FileBinaryServiceTest.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@
1414
package org.trellisldp.file;
1515

1616
import static java.nio.charset.StandardCharsets.UTF_8;
17-
import static java.util.Base64.getEncoder;
18-
import static org.apache.commons.codec.digest.DigestUtils.getDigest;
1917
import static org.junit.jupiter.api.Assertions.*;
20-
import static org.junit.jupiter.api.condition.JRE.JAVA_8;
2118
import static org.mockito.Mockito.mock;
2219

2320
import java.io.ByteArrayInputStream;
2421
import java.io.File;
2522
import java.io.IOException;
2623
import java.io.InputStream;
2724
import java.math.BigInteger;
28-
import java.security.MessageDigest;
2925
import java.security.SecureRandom;
3026
import java.util.concurrent.CompletionException;
3127

@@ -36,7 +32,6 @@
3632
import org.junit.jupiter.api.AfterAll;
3733
import org.junit.jupiter.api.BeforeAll;
3834
import org.junit.jupiter.api.Test;
39-
import org.junit.jupiter.api.condition.DisabledOnJre;
4035
import org.trellisldp.api.Binary;
4136
import org.trellisldp.api.BinaryMetadata;
4237
import org.trellisldp.api.BinaryService;
@@ -65,15 +60,6 @@ public static void cleanUp() {
6560
System.clearProperty(FileBinaryService.CONFIG_FILE_BINARY_BASE_PATH);
6661
}
6762

68-
@Test
69-
public void testSupportedAlgorithms() {
70-
final BinaryService service = new FileBinaryService();
71-
assertTrue(service.supportedAlgorithms().contains("SHA"));
72-
assertTrue(service.supportedAlgorithms().contains("SHA-1"));
73-
assertTrue(service.supportedAlgorithms().contains("SHA-256"));
74-
assertTrue(service.supportedAlgorithms().contains("MD5"));
75-
}
76-
7763
@Test
7864
public void testFilePurge() {
7965
final BinaryService service = new FileBinaryService();
@@ -171,38 +157,6 @@ public void testGetFileSkipContentError() throws Exception {
171157
}).toCompletableFuture().join());
172158
}
173159

174-
@Test
175-
public void testBase64Digest() throws IOException {
176-
final BinaryService service = new FileBinaryService();
177-
assertEquals("oZ1Y1O/8vs39RH31fh9lrA==", service.calculateDigest(file, getDigest("MD5"))
178-
.thenApply(MessageDigest::digest).thenApply(getEncoder()::encodeToString)
179-
.toCompletableFuture().join(), "Bad MD5 digest!");
180-
assertEquals("QJuYLse9SK/As177lt+rSfixyH0=", service.calculateDigest(file, getDigest("SHA-1"))
181-
.thenApply(MessageDigest::digest).thenApply(getEncoder()::encodeToString)
182-
.toCompletableFuture().join(), "Bad SHA digest!");
183-
assertThrows(CompletionException.class, () ->
184-
service.calculateDigest(rdf.createIRI("file:///" + randomFilename()), getDigest("MD5"))
185-
.toCompletableFuture().join(), "Computing digest on invalid file should throw an exception!");
186-
}
187-
188-
@Test
189-
@DisabledOnJre(JAVA_8)
190-
public void testJdk9Digests() throws IOException {
191-
final BinaryService service = new FileBinaryService();
192-
assertEquals("FQgyH2yU2NhyMTZ7YDDKwV5vcWUBM1zq0uoIYUiHH+4=",
193-
service.calculateDigest(file, getDigest("SHA3-256")).thenApply(MessageDigest::digest)
194-
.thenApply(getEncoder()::encodeToString).toCompletableFuture().join(),
195-
"Bad SHA3-256 digest!");
196-
assertEquals("746UDLrFXM61gzI0FnoVT2S0Z7EmQUfhHnoSYwkR2MHzbBe6j9rMigQBfR8ApZUA",
197-
service.calculateDigest(file, getDigest("SHA3-384")).thenApply(MessageDigest::digest)
198-
.thenApply(getEncoder()::encodeToString).toCompletableFuture().join(),
199-
"Bad SHA3-384 digest!");
200-
assertEquals("Ecu/R0kV4eL0J/VOpyVA2Lz0T6qsJj9ioQ+QorJDztJeMj6uhf6zqyhZnu9zMYiwrkX8U4oWiZMDT/0fWjOyYg==",
201-
service.calculateDigest(file, getDigest("SHA3-512")).thenApply(MessageDigest::digest)
202-
.thenApply(getEncoder()::encodeToString).toCompletableFuture().join(),
203-
"Bad SHA3-512 digest!");
204-
}
205-
206160
@Test
207161
public void testBadIdentifier() {
208162
final BinaryService service = new FileBinaryService();

components/test/src/main/java/org/trellisldp/test/LdpBinaryTests.java

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
import static org.junit.jupiter.api.Assertions.*;
2424
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
2525
import static org.trellisldp.api.TrellisUtils.getInstance;
26-
import static org.trellisldp.http.core.HttpConstants.DIGEST;
2726
import static org.trellisldp.http.core.HttpConstants.SLUG;
28-
import static org.trellisldp.http.core.HttpConstants.WANT_DIGEST;
2927
import static org.trellisldp.http.core.RdfMediaType.APPLICATION_SPARQL_UPDATE;
3028
import static org.trellisldp.http.core.RdfMediaType.TEXT_TURTLE_TYPE;
3129
import static org.trellisldp.test.TestUtils.readEntityAsGraph;
@@ -127,23 +125,6 @@ default void testPostBinary() {
127125
}
128126
}
129127

130-
/**
131-
* Test creating a new binary via POST with a digest header.
132-
*/
133-
@Test
134-
@DisplayName("Test creating a new binary via POST with a digest header")
135-
default void testPostBinaryWithDigest() {
136-
// POST an LDP-NR
137-
try (final Response res = target().request().header(DIGEST, "md5=bUMuG430lSc5B2PWyoNIgA==")
138-
.header(SLUG, generateRandomValue(getClass().getSimpleName()))
139-
.post(entity(CONTENT, TEXT_PLAIN))) {
140-
assertAll("Check POSTing LDP-NR with digest", checkNonRdfResponse(res, null));
141-
final String resource = res.getLocation().toString();
142-
assertTrue(resource.startsWith(getBaseURL()), "Check the response location");
143-
assertTrue(resource.length() > getBaseURL().length(), "Check for a nested response location");
144-
}
145-
}
146-
147128
/**
148129
* Test modifying a binary's description via PATCH.
149130
*/
@@ -211,44 +192,4 @@ default void testBinaryIsInContainer() {
211192
rdf.createIRI(getResourceLocation())), "Check for an ldp:contains triple");
212193
}
213194
}
214-
215-
/**
216-
* Test that the SHA digest is generated.
217-
*/
218-
@Test
219-
@DisplayName("Test that the SHA digest is generated")
220-
default void testBinaryWantDigestSha() {
221-
// Test the SHA-1 algorithm
222-
try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "SHA,MD5").get()) {
223-
assertAll("Check binary with SHA-1 digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE));
224-
assertEquals("sha=Z5pg2cWB1IqkKKMjh57cQKAeKp0=", res.getHeaderString(DIGEST), "Check the SHA digest value");
225-
}
226-
}
227-
228-
/**
229-
* Test that the SHA-256 digest is generated.
230-
*/
231-
@Test
232-
@DisplayName("Test that the SHA-256 digest is generated")
233-
default void testBinaryWantDigestSha256() {
234-
// Test the SHA-256 algorithm
235-
try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "SHA-256").get()) {
236-
assertAll("Check binary with SHA-256 digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE));
237-
assertEquals("sha-256=wZXqBpAjgZLSoADF419CRpJCurDcagOwnb/8VAiiQXA=", res.getHeaderString(DIGEST),
238-
"Check the SHA-256 digest value");
239-
}
240-
}
241-
242-
/**
243-
* Test that an unknown digest is ignored.
244-
*/
245-
@Test
246-
@DisplayName("Test that an unknown digest is ignored")
247-
default void testBinaryWantDigestUnknown() {
248-
// Test an unknown digest algorithm
249-
try (final Response res = target(getResourceLocation()).request().header(WANT_DIGEST, "FOO").get()) {
250-
assertAll("Check binary with unknown digest", checkNonRdfResponse(res, TEXT_PLAIN_TYPE));
251-
assertNull(res.getHeaderString(DIGEST), "Check that no Digest header is present");
252-
}
253-
}
254195
}

core/api/src/main/java/org/trellisldp/api/BinaryService.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
package org.trellisldp.api;
1515

1616
import java.io.InputStream;
17-
import java.security.DigestInputStream;
18-
import java.security.MessageDigest;
19-
import java.util.Set;
2017
import java.util.concurrent.CompletionStage;
2118

2219
import org.apache.commons.rdf.api.IRI;
@@ -39,21 +36,6 @@ public interface BinaryService extends RetrievalService<Binary> {
3936
*/
4037
CompletionStage<Void> setContent(BinaryMetadata metadata, InputStream stream);
4138

42-
/**
43-
* Set the content for a binary object using a digest algorithm.
44-
*
45-
* @implSpec The default implementation will compute a digest while processing the {@code InputStream}.
46-
* @param metadata the binary metadata
47-
* @param stream the context
48-
* @param algorithm the digest algorithm
49-
* @return the new completion stage containing the server-computed digest.
50-
*/
51-
default CompletionStage<MessageDigest> setContent(final BinaryMetadata metadata, final InputStream stream,
52-
final MessageDigest algorithm) {
53-
final DigestInputStream input = new DigestInputStream(stream, algorithm);
54-
return setContent(metadata, input).thenApply(future -> input.getMessageDigest());
55-
}
56-
5739
/**
5840
* Purge the content from its corresponding datastore.
5941
*
@@ -65,24 +47,6 @@ default CompletionStage<MessageDigest> setContent(final BinaryMetadata metadata,
6547
*/
6648
CompletionStage<Void> purgeContent(IRI identifier);
6749

68-
/**
69-
* Calculate the digest for a binary object.
70-
*
71-
* @apiNote As per RFC 3230, the digest value is calculated over the entire resource,
72-
* not just the HTTP payload.
73-
* @param identifier the identifier
74-
* @param algorithm the algorithm
75-
* @return the new completion stage containing a computed digest for the binary resource
76-
*/
77-
CompletionStage<MessageDigest> calculateDigest(IRI identifier, MessageDigest algorithm);
78-
79-
/**
80-
* Get a list of supported algorithms.
81-
*
82-
* @return the supported digest algorithms
83-
*/
84-
Set<String> supportedAlgorithms();
85-
8650
/**
8751
* Get a new identifier.
8852
*

0 commit comments

Comments
 (0)