-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
38 changes: 38 additions & 0 deletions
38
fj-doc-val-p7m/src/main/java/org/fugerit/java/doc/val/p7m/P7MValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
fj-doc-val-p7m/src/test/java/test/org/fugerit/java/doc/val/p7m/TestDocValidatorFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} ); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
fj-doc-val-p7m/src/test/java/test/org/fugerit/java/doc/val/p7m/TestP7MValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters