Skip to content

Commit f280e51

Browse files
authored
TIKA-2856 - follow on from TIKA-1997 (#2960)
1 parent e537ce0 commit f280e51

4 files changed

Lines changed: 13 additions & 19 deletions

File tree

tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -909,26 +909,15 @@
909909
<magic priority="50">
910910
<!-- PEM encoded -->
911911
<match value="-----BEGIN PKCS7" type="string" offset="0"/>
912-
<!-- DER encoded, sequence+length, object=pkcs7-signedData -->
913-
<match value="0x3080" offset="0">
914-
<match value="0x06092a864886f70d0107FFa0" type="string"
915-
mask="0xFFFFFFFFFFFFFFFFFFFF00FF" offset="2"/>
916-
</match>
917-
<match value="0x3081" offset="0">
918-
<match value="0x06092a864886f70d0107FFa0" type="string"
919-
mask="0xFFFFFFFFFFFFFFFFFFFF00FF" offset="3"/>
920-
</match>
921-
<match value="0x3082" offset="0">
922-
<match value="0x06092a864886f70d0107FFa0" type="string"
923-
mask="0xFFFFFFFFFFFFFFFFFFFF00FF" offset="4"/>
924-
</match>
925-
<match value="0x3083" offset="0">
926-
<match value="0x06092a864886f70d0107FFa0" type="string"
927-
mask="0xFFFFFFFFFFFFFFFFFFFF00FF" offset="5"/>
928-
</match>
929-
<match value="0x3084" offset="0">
912+
<!-- DER encoded: SEQUENCE then a CMS ContentInfo whose contentType is in the pkcs7 arc
913+
1.2.840.113549.1.7.x (signedData .2, envelopedData .3, digestedData .5, encryptedData .6,
914+
... last OID byte masked) followed by the [0] content tag (a0). offset 2:6 spans the DER
915+
SEQUENCE length forms (short-form + 80/81/82/83/84), so small short-form containers such
916+
as a bare digestedData are matched too. This is the coarse family label; Pkcs7Parser
917+
refines the exact smime-type. -->
918+
<match value="0x30" offset="0">
930919
<match value="0x06092a864886f70d0107FFa0" type="string"
931-
mask="0xFFFFFFFFFFFFFFFFFFFF00FF" offset="6"/>
920+
mask="0xFFFFFFFFFFFFFFFFFFFF00FF" offset="2:6"/>
932921
</match>
933922
</magic>
934923
</mime-type>

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-crypto-module/src/test/java/org/apache/tika/parser/crypto/Pkcs7DetectionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ public void testContentOnlyDetection() throws Exception {
5050
// existing masked CMS magic detects signed/enveloped coarsely as pkcs7-signature by content
5151
assertEquals("application/pkcs7-signature", detect("testPKCS7_signed_data_def.p7m"));
5252
assertEquals("application/pkcs7-signature", detect("testPKCS7_enveloped_def.p7m"));
53+
// TIKA-2856: a short-form-length digestedData is now caught coarsely (routes to Pkcs7Parser)
54+
assertEquals("application/pkcs7-signature", detect("testPKCS7_digested.p7"));
5355
}
5456
}

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-crypto-module/src/test/java/org/apache/tika/parser/crypto/Pkcs7ParserTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public void testSubtypeRefinement() throws Exception {
5757
parsedType("testPKCS7_compressed_def_long.p7z"));
5858
assertEquals("application/pkcs7-mime; smime-type=compressed-data",
5959
parsedType("testPKCS7_compressed_ind.p7z"));
60+
// TIKA-2856: digestedData refined at parse time (coarse magic now routes it here)
61+
assertEquals("application/pkcs7-mime; smime-type=digested-data",
62+
parsedType("testPKCS7_digested.p7"));
6063
}
6164

6265
/** Detached signatures are labelled pkcs7-signature and no longer throw. */

0 commit comments

Comments
 (0)