Skip to content

Commit

Permalink
Correctly handling PDF files with public key encryption in attachment…
Browse files Browse the repository at this point in the history
… processor
  • Loading branch information
masseyke committed Oct 27, 2023
1 parent 74da807 commit 3060d83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ static String parse(final byte content[], final Metadata metadata, final int lim
} else {
throw new AssertionError(cause);
}
} catch (LinkageError e) {
if (e.getMessage().contains("bouncycastle")) {
/*
* Elasticsearch does not ship with bouncycastle. It is only used for public-key-encrypted PDFs, which this module does
* not support anyway.
*/
throw new RuntimeException("document is encrypted", e);
}
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,25 @@ public void testVisioIsExcluded() throws Exception {
assertThat(attachmentData.get("content_length"), is(0L));
}

public void testEncryptedPdf() throws Exception {
public void testEncryptedWithPasswordPdf() throws Exception {
/*
* This tests that a PDF that has been encrypted with a password fails in the way expected
*/
ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> parseDocument("encrypted.pdf", processor));
assertThat(e.getDetailedMessage(), containsString("document is encrypted"));
}

public void testEncryptedWithKeyPdf() throws Exception {
/*
* This tests that a PDF that has been encrypted with a public key fails in the way expected
*/
ElasticsearchParseException e = expectThrows(
ElasticsearchParseException.class,
() -> parseDocument("encrypted-with-key.pdf", processor)
);
assertThat(e.getDetailedMessage(), containsString("document is encrypted"));
}

public void testHtmlDocument() throws Exception {
Map<String, Object> attachmentData = parseDocument("htmlWithEmptyDateMeta.html", processor);

Expand Down
Binary file not shown.

0 comments on commit 3060d83

Please sign in to comment.