Skip to content

Commit d500ce4

Browse files
committed
Added module for p7m validation
1 parent fe8fece commit d500ce4

File tree

13 files changed

+194
-2
lines changed

13 files changed

+194
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [3.2.0] - 2023-11-02
11+
12+
### Added
13+
14+
- [val-p7m] module for p7m validation
15+
1016
### Changed
1117

1218
- [playground-quarkus] changed docker base image to 21.0.1_12-jre-ubi9-minimal

fj-doc-playground-quarkus/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ COPY --chown=185:0 target/quarkus-app/quarkus/ /deployments/quarkus/
2525

2626
USER root
2727

28-
RUN echo "securerandom.source=file:/dev/./urandom" >> /opt/java/openjdk/lib/security/java.security
28+
# disabled for now
29+
#RUN echo "securerandom.source=file:/dev/./urandom" >> /opt/java/openjdk/lib/security/java.security
2930

3031
CMD java -Dfile.encoding="UTF-8" -jar /deployments/quarkus-run.jar

fj-doc-val-p7m/pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<artifactId>fj-doc-val-p7m</artifactId>
6+
7+
<parent>
8+
<groupId>org.fugerit.java</groupId>
9+
<artifactId>fj-doc</artifactId>
10+
<version>3.1.10-SNAPSHOT</version>
11+
</parent>
12+
13+
<name>fj-doc-val-p7m</name>
14+
<description>Module for validating P7M via Bouncy Castle</description>
15+
16+
<licenses>
17+
<license>
18+
<name>Apache License, Version 2.0</name>
19+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
<distribution>repo</distribution>
21+
</license>
22+
</licenses>
23+
24+
<properties>
25+
<bouncy-castle-version>1.76</bouncy-castle-version>
26+
</properties>
27+
28+
<build>
29+
30+
</build>
31+
32+
<dependencies>
33+
34+
<dependency>
35+
<groupId>org.fugerit.java</groupId>
36+
<artifactId>fj-core</artifactId>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.fugerit.java</groupId>
41+
<artifactId>fj-doc-val-core</artifactId>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>org.bouncycastle</groupId>
46+
<artifactId>bcpkix-jdk18on</artifactId>
47+
<version>${bouncy-castle-version}</version>
48+
</dependency>
49+
50+
</dependencies>
51+
52+
<organization>
53+
<url>https://www.fugerit.org</url>
54+
<name>Fugerit</name>
55+
</organization>
56+
57+
<url>https://www.fugerit.org/perm/venus/</url>
58+
59+
60+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.fugerit.java.doc.val.p7m;
2+
3+
import java.io.InputStream;
4+
5+
import org.bouncycastle.cms.CMSSignedData;
6+
import org.fugerit.java.doc.val.core.DocTypeValidationResult;
7+
import org.fugerit.java.doc.val.core.DocTypeValidator;
8+
import org.fugerit.java.doc.val.core.basic.AbstractDocTypeValidator;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
public class P7MValidator extends AbstractDocTypeValidator {
13+
14+
private static final Logger logger = LoggerFactory.getLogger( P7MValidator.class );
15+
16+
public static final String EXTENSION = "P7M";
17+
18+
public static final String MIME_TYPE = "application/pkcs7-mime";
19+
20+
public static final DocTypeValidator DEFAULT = new P7MValidator();
21+
22+
public P7MValidator() {
23+
super( MIME_TYPE, EXTENSION );
24+
}
25+
26+
@Override
27+
public DocTypeValidationResult validate(InputStream is) {
28+
DocTypeValidationResult result = DocTypeValidationResult.newFail();
29+
try {
30+
new CMSSignedData( is );
31+
result = DocTypeValidationResult.newOk();
32+
} catch (Exception e) {
33+
logger.warn( "Failed check on p7m : {}", e.toString() );
34+
}
35+
return result;
36+
}
37+
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package test.org.fugerit.java.doc.val.p7m;
2+
3+
import java.io.InputStream;
4+
5+
import org.fugerit.java.core.function.SafeFunction;
6+
import org.fugerit.java.core.lang.helpers.ClassHelper;
7+
import org.fugerit.java.doc.val.core.DocValidatorFacade;
8+
import org.junit.Assert;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
public class TestDocValidatorFacade {
13+
14+
private static final Logger logger = LoggerFactory.getLogger( TestDocValidatorFacade.class );
15+
16+
private static final String BASE_PATH = "sample";
17+
18+
protected boolean worker( DocValidatorFacade facade, String fileName, boolean result ) {
19+
return SafeFunction.get( () -> {
20+
String path = BASE_PATH+"/"+fileName;
21+
logger.info( "test path {}, expected result {}", path, result );
22+
try ( InputStream is = ClassHelper.loadFromDefaultClassLoader( path ) ) {
23+
boolean check = facade.check(fileName, is);
24+
Assert.assertEquals( "File check failed", result, check );
25+
return ( result == check );
26+
}
27+
} );
28+
}
29+
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package test.org.fugerit.java.doc.val.p7m;
2+
3+
import org.fugerit.java.doc.val.core.DocValidatorFacade;
4+
import org.fugerit.java.doc.val.p7m.P7MValidator;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
public class TestP7MValidator extends TestDocValidatorFacade {
9+
10+
private static final DocValidatorFacade FACADE = DocValidatorFacade.newFacadeStrict(
11+
P7MValidator.DEFAULT
12+
);
13+
14+
@Test
15+
public void testP7MAsP7M() {
16+
boolean ok = this.worker(FACADE, "pdf_as_pdf.p7m", true );
17+
Assert.assertTrue( ok );
18+
}
19+
20+
@Test
21+
public void testPNGAsP7M() {
22+
boolean ok = this.worker(FACADE, "png_as_p7m.p7m", false );
23+
Assert.assertTrue( ok );
24+
}
25+
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="INFO">
10+
<AppenderRef ref="Console"/>
11+
</Root>
12+
</Loggers>
13+
</Configuration>
185 KB
Binary file not shown.
2.55 KB
Binary file not shown.

fj-doc-val-pdfbox/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
<artifactId>pdfbox</artifactId>
4747
<version>${pdfbox-version}</version>
4848
</dependency>
49+
50+
<dependency>
51+
<groupId>org.bouncycastle</groupId>
52+
<artifactId>bcpkix-jdk18on</artifactId>
53+
<version>1.76</version>
54+
</dependency>
4955

5056
</dependencies>
5157

0 commit comments

Comments
 (0)