Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
updates:
- package-ecosystem: maven
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
groups:
java-dependencies:
patterns:
- "*"

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
github-actions:
patterns:
- "*"
6 changes: 2 additions & 4 deletions .github/workflows/netlicensing-client-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ jobs:
strategy:
fail-fast: false
matrix:
java-version: [11, 17]
java-version: [17]
include:
- java-version: 11
jdk-suffix:
- java-version: 17
jdk-suffix: -jdk17
jdk-suffix:

steps:
- name: Install required tooling
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/netlicesning-client-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ jobs:
strategy:
fail-fast: false
matrix:
java-version: [11, 17]
java-version: [17]
include:
- java-version: 11
jdk-suffix: ""
- java-version: 17
jdk-suffix: -jdk17
jdk-suffix: ""


steps:
Expand Down
2 changes: 1 addition & 1 deletion NetLicensingClient-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<version>3.5.4</version>
<configuration>
<!-- Do not execute unit tests on build.
Unit tests in this project are used
Expand Down
44 changes: 44 additions & 0 deletions NetLicensingClient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,50 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>xmldsig-coverage</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
<goal>check</goal>
</goals>
<configuration>
<includes>
<include>com/labs64/netlicensing/util/XMLDSigValidatorCustom.class</include>
</includes>
<rules>
<rule>
<element>CLASS</element>
<includes>
<include>com.labs64.netlicensing.util.XMLDSigValidatorCustom</include>
</includes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>1.0</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>1.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.security.Key;

import javax.annotation.Nonnull;
import javax.xml.crypto.KeySelector;
import javax.xml.crypto.dsig.XMLSignature;
import javax.xml.crypto.dsig.XMLSignatureException;
Expand All @@ -11,12 +10,12 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.helger.commons.ValueEnforcer;
import com.helger.base.enforce.ValueEnforcer;
import com.helger.xmldsig.XMLDSigSetup;
import com.helger.xmldsig.XMLDSigValidationResult;
import com.helger.xmldsig.XMLDSigValidator;

public class XMLDSigValidatorCustom {
public final class XMLDSigValidatorCustom {

private XMLDSigValidatorCustom() {
}
Expand All @@ -26,7 +25,7 @@ private XMLDSigValidatorCustom() {
* @param aDoc document to be verified
* @return true if Document contains XML signature
*/
public static boolean containsSignature(@Nonnull final Document aDoc) {
public static boolean containsSignature(final Document aDoc) {
return XMLDSigValidator.containsSignature(aDoc);
}

Expand All @@ -36,7 +35,7 @@ public static boolean containsSignature(@Nonnull final Document aDoc) {
* @return XMLDSig validation result
* @throws XMLSignatureException
*/
public static XMLDSigValidationResult validateSignature(@Nonnull final Document aDoc)
public static XMLDSigValidationResult validateSignature(final Document aDoc)
throws XMLSignatureException {
return validateSignature(aDoc, null);
}
Expand All @@ -47,7 +46,7 @@ public static XMLDSigValidationResult validateSignature(@Nonnull final Document
* @return XMLDSig validation result
* @throws XMLSignatureException
*/
public static XMLDSigValidationResult validateSignature(@Nonnull final Document aDoc, final Key aKey)
public static XMLDSigValidationResult validateSignature(final Document aDoc, final Key aKey)
throws XMLSignatureException {
ValueEnforcer.notNull(aDoc, "Document");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
package com.labs64.netlicensing.util;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
import java.security.PublicKey;

import javax.xml.crypto.dsig.XMLSignature;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public final class XMLDSigValidatorCustomTest {
Expand All @@ -44,10 +48,32 @@ private static Document loadXmlDocument(final String fileName) throws Exception
return aDoc;
}

@Test
public void testUtilityClassConstructor() throws Exception {
final Constructor<XMLDSigValidatorCustom> constructor = XMLDSigValidatorCustom.class.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
}

@Test
public void testNullDocument() {
assertThrows(NullPointerException.class, () -> XMLDSigValidatorCustom.validateSignature(null));
}

@Test
public void testNotSignedXml() throws Exception {
final Document aDoc = loadXmlDocument("xmldsig/xml-not-signed.xml");
assertFalse(XMLDSigValidatorCustom.containsSignature(aDoc));
assertThrows(IllegalArgumentException.class, () -> XMLDSigValidatorCustom.validateSignature(aDoc));
}

@Test
public void testMultipleSignaturesAreRejected() throws Exception {
final Document aDoc = loadXmlDocument("xmldsig/xml-signed-inline-01.xml");
final Element signature = (Element) aDoc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0);
aDoc.getDocumentElement().appendChild(signature.cloneNode(true));

assertThrows(IllegalArgumentException.class, () -> XMLDSigValidatorCustom.validateSignature(aDoc));
}

@Test
Expand Down
45 changes: 32 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,28 @@
<project.title>${project.name}</project.title>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<java.version>11</java.version>
<java.version>17</java.version>
<maven.version>3.6.0</maven.version>

<repo.releases.url>OVERRIDE_REPO_URL</repo.releases.url>
<repo.snapshots.url>OVERRIDE_REPO_URL</repo.snapshots.url>

<!-- dependency.version>0.0.0</dependency.version -->
<commons-lang3.version>3.18.0</commons-lang3.version> <!-- https://commons.apache.org/ -->
<commons-collections4.version>4.4</commons-collections4.version>
<commons-io.version>2.15.1</commons-io.version>
<commons-cli.version>1.6.0</commons-cli.version>
<commons-text.version>1.11.0</commons-text.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<jersey.version>3.1.5</jersey.version> <!-- https://projects.eclipse.org/projects/ee4j.jersey -->
<jaxb-api.version>4.0.0</jaxb-api.version> <!-- https://jakarta.ee/specifications/xml-binding/4.0/ -->
<jaxb-impl.version>4.0.3</jaxb-impl.version> <!-- https://projects.eclipse.org/projects/ee4j.jaxb-impl -->
<ph-xmldsig.version>5.0.2</ph-xmldsig.version>
<slf4j.version>2.0.13</slf4j.version>
<commons-lang3.version>3.21.0</commons-lang3.version> <!-- https://commons.apache.org/ -->
<commons-collections4.version>4.6.0</commons-collections4.version>
<commons-io.version>2.22.0</commons-io.version>
<commons-cli.version>1.11.0</commons-cli.version>
<commons-text.version>1.15.0</commons-text.version>
<junit-jupiter.version>6.1.3</junit-jupiter.version>
<jersey.version>4.0.3</jersey.version> <!-- https://projects.eclipse.org/projects/ee4j.jersey -->
<jaxb-api.version>4.0.5</jaxb-api.version> <!-- https://jakarta.ee/specifications/xml-binding/4.0/ -->
<jaxb-impl.version>4.0.9</jaxb-impl.version> <!-- https://projects.eclipse.org/projects/ee4j.jaxb-impl -->
<ph-xmldsig.version>6.1.0</ph-xmldsig.version>
<!-- ph-xmldsig 6.1.0 manages Bouncy Castle 1.82. Override it because the
security fixes required by this client are only complete in 1.86. -->
<bouncycastle.version>1.86</bouncycastle.version>
<slf4j.version>2.0.20</slf4j.version>
<jacoco-maven-plugin.version>0.8.14</jacoco-maven-plugin.version>

<!-- plugin.version>0.0.0</plugin.version -->
<maven-enforcer-plugin.version>3.0.0</maven-enforcer-plugin.version>
Expand Down Expand Up @@ -164,7 +168,7 @@
<!--https://stackoverflow.com/questions/15886209/maven-is-not-working-in-java-8-when-javadoc-tags-are-incomplete-->
<configuration>
<doclint>none</doclint>
<source>11</source>
<source>${java.version}</source>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -351,6 +355,11 @@
<artifactId>maven-scm-plugin</artifactId>
<version>${maven-scm-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>

Expand Down Expand Up @@ -449,6 +458,16 @@
<artifactId>ph-xmldsig</artifactId>
<version>${ph-xmldsig.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<!-- com.helger.ph-xmldsig is using slf4j, use NOP provider for testing / demo -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down