Skip to content

Commit

Permalink
Added module for p7m validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Nov 2, 2023
1 parent fe8fece commit d500ce4
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.2.0] - 2023-11-02

### Added

- [val-p7m] module for p7m validation

### Changed

- [playground-quarkus] changed docker base image to 21.0.1_12-jre-ubi9-minimal
Expand Down
3 changes: 2 additions & 1 deletion fj-doc-playground-quarkus/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ COPY --chown=185:0 target/quarkus-app/quarkus/ /deployments/quarkus/

USER root

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

CMD java -Dfile.encoding="UTF-8" -jar /deployments/quarkus-run.jar
60 changes: 60 additions & 0 deletions fj-doc-val-p7m/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>fj-doc-val-p7m</artifactId>

<parent>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc</artifactId>
<version>3.1.10-SNAPSHOT</version>
</parent>

<name>fj-doc-val-p7m</name>
<description>Module for validating P7M via Bouncy Castle</description>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<bouncy-castle-version>1.76</bouncy-castle-version>
</properties>

<build>

</build>

<dependencies>

<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-core</artifactId>
</dependency>

<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc-val-core</artifactId>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>${bouncy-castle-version}</version>
</dependency>

</dependencies>

<organization>
<url>https://www.fugerit.org</url>
<name>Fugerit</name>
</organization>

<url>https://www.fugerit.org/perm/venus/</url>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.fugerit.java.doc.val.p7m;

import java.io.InputStream;

import org.bouncycastle.cms.CMSSignedData;
import org.fugerit.java.doc.val.core.DocTypeValidationResult;
import org.fugerit.java.doc.val.core.DocTypeValidator;
import org.fugerit.java.doc.val.core.basic.AbstractDocTypeValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class P7MValidator extends AbstractDocTypeValidator {

private static final Logger logger = LoggerFactory.getLogger( P7MValidator.class );

public static final String EXTENSION = "P7M";

public static final String MIME_TYPE = "application/pkcs7-mime";

public static final DocTypeValidator DEFAULT = new P7MValidator();

public P7MValidator() {
super( MIME_TYPE, EXTENSION );
}

@Override
public DocTypeValidationResult validate(InputStream is) {
DocTypeValidationResult result = DocTypeValidationResult.newFail();
try {
new CMSSignedData( is );
result = DocTypeValidationResult.newOk();
} catch (Exception e) {
logger.warn( "Failed check on p7m : {}", e.toString() );
}
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package test.org.fugerit.java.doc.val.p7m;

import java.io.InputStream;

import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.doc.val.core.DocValidatorFacade;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestDocValidatorFacade {

private static final Logger logger = LoggerFactory.getLogger( TestDocValidatorFacade.class );

private static final String BASE_PATH = "sample";

protected boolean worker( DocValidatorFacade facade, String fileName, boolean result ) {
return SafeFunction.get( () -> {
String path = BASE_PATH+"/"+fileName;
logger.info( "test path {}, expected result {}", path, result );
try ( InputStream is = ClassHelper.loadFromDefaultClassLoader( path ) ) {
boolean check = facade.check(fileName, is);
Assert.assertEquals( "File check failed", result, check );
return ( result == check );
}
} );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package test.org.fugerit.java.doc.val.p7m;

import org.fugerit.java.doc.val.core.DocValidatorFacade;
import org.fugerit.java.doc.val.p7m.P7MValidator;
import org.junit.Assert;
import org.junit.Test;

public class TestP7MValidator extends TestDocValidatorFacade {

private static final DocValidatorFacade FACADE = DocValidatorFacade.newFacadeStrict(
P7MValidator.DEFAULT
);

@Test
public void testP7MAsP7M() {
boolean ok = this.worker(FACADE, "pdf_as_pdf.p7m", true );
Assert.assertTrue( ok );
}

@Test
public void testPNGAsP7M() {
boolean ok = this.worker(FACADE, "png_as_p7m.p7m", false );
Assert.assertTrue( ok );
}

}
13 changes: 13 additions & 0 deletions fj-doc-val-p7m/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions fj-doc-val-pdfbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<artifactId>pdfbox</artifactId>
<version>${pdfbox-version}</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>1.76</version>
</dependency>

</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion fj-doc-val/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
This module offer validation utilities to check content of files and streams based on type.

*Status* :
Offer basic support for validating jpg, png, tiff and pdf
Offer basic support for validating jpg, png, tiff, pdf and p7m

*Since* : fj-doc 0.8

Expand Down
5 changes: 5 additions & 0 deletions fj-doc-val/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc-val-poi</artifactId>
</dependency>

<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc-val-p7m</artifactId>
</dependency>

</dependencies>

Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<module>fj-doc-val-core</module>
<module>fj-doc-val-pdfbox</module>
<module>fj-doc-val-poi</module>
<module>fj-doc-val-p7m</module>
<module>fj-doc-val</module>
<module>fj-doc-tool</module>
<module>fj-doc-sample</module>
Expand Down Expand Up @@ -199,6 +200,12 @@
<version>${fj-doc-version}</version>
</dependency>

<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc-val-p7m</artifactId>
<version>${fj-doc-version}</version>
</dependency>

<dependency>
<groupId>org.fugerit.java</groupId>
<artifactId>fj-doc-sample</artifactId>
Expand Down

0 comments on commit d500ce4

Please sign in to comment.