Skip to content
Open
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
22 changes: 8 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
jdk: [1.8, 9, 11, 15]
jdk: [8]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.jdk }}
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
distribution: liberica
- name: Maven Build
run: mvn -V -B -DskipTests=true install
run: mvn -V -B -Dgpg.skip -DskipTests=true install
shell: bash
- name: Maven Test
run: mvn -B verify
# - name: Maven Code Coverage
# if: ${{ github.ref == 'refs/heads/main' && matrix.jdk == '1.8' && matrix.os == 'ubuntu-latest' }}
# run: mvn -B jacoco:report coveralls:report -DrepoToken=${{ secrets.COVERALLS_TOKEN }}
run: mvn -V -B -Dgpg.skip verify
shell: bash
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![CI](https://github.com/eXist-db/expath-crypto-module/workflows/CI/badge.svg)](https://github.com/eXist-db/expath-crypto-module/actions?query=workflow%3ACI)

# eXist-db implementation for EXPath Cryptographic Module
# Implementation of EXPath Cryptographic Module for eXist-db and Elemental

This is an eXist-db implementation of the [EXPath HTTP Crypto Module specification](http://expath.org/spec/crypto).
This is an implementation of the [EXPath HTTP Crypto Module specification](http://expath.org/spec/crypto).
## Building from source

Requires:
Expand All @@ -15,7 +15,7 @@ $ cd expath-crypto-module
$ mvn clean package
```

This will create a "expath-crypto-module-<version>.xar" file in the target folder. The .xar file can be uploaded to any eXist-db version > 5.3.0 via the Dashboard.
This will create a "expath-crypto-module-<version>.xar" file in the target folder. The .xar file can be uploaded to any eXist-db or Elemental version >= 6.0.0 via the Dashboard.

### Currently implemented functions

Expand Down
81 changes: 23 additions & 58 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@
<parent>
<groupId>org.exist-db</groupId>
<artifactId>exist-apps-parent</artifactId>
<version>1.11.0</version>
<version>2.0.0</version>
<relativePath/>
</parent>

<groupId>org.exist-db.xquery.extensions.expath</groupId>
<artifactId>expath-crypto-module</artifactId>
<version>6.0.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>eXist-db EXPath Cryptographic library</name>
<description>eXist-db wrapper for EXPath Cryptographic Java library</description>
<url>http://expath.org/spec/crypto</url>
<url>https://expath.org/spec/crypto</url>
<inceptionYear>2016</inceptionYear>

<licenses>
Expand Down Expand Up @@ -92,8 +94,9 @@

<properties>
<package.title>EXPath Cryptographic Module Implementation</package.title>
<crypto.java.lib.version>1.8.0</crypto.java.lib.version>
<exist.version>5.3.0</exist.version>
<crypto.java.lib.version>1.9.0</crypto.java.lib.version>
<existdb.version>6.0.0</existdb.version>
<elemental.version>6.4.0</elemental.version>
<crypto.module.ns>http://expath.org/ns/crypto</crypto.module.ns>
<crypto.module.java.class>org.expath.exist.crypto.ExistExpathCryptoModule</crypto.module.java.class>
<package-abbrev>crypto</package-abbrev>
Expand All @@ -109,7 +112,7 @@
<dependency>
<groupId>org.exist-db</groupId>
<artifactId>exist-core</artifactId>
<version>${exist.version}</version>
<version>${existdb.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -121,7 +124,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<version>1.7.33</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -139,7 +142,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.10.0</version>
<version>2.11.0</version>
<scope>provided</scope>
</dependency>

Expand All @@ -152,6 +155,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
Expand All @@ -167,7 +176,6 @@
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>4.1</version>
<configuration>
<failIfMissing>true</failIfMissing>
<aggregate>true</aggregate>
Expand Down Expand Up @@ -209,49 +217,15 @@
<includes>
<include>pom.xml</include>
<include>src/test/java/xquery/crypto/CryptoIT.java</include>
<!-- include>src/test/java/ro/kuberam/libs/java/crypto/TestUtils.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HashBinaryTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HashBinaryWithWrongAlgorithmTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HashLargeBinaryTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HashLargeStringTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HashStringTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HashStringWithWrongAlgorithmTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HMACBinaryTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HMACLargeBinaryTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HMACLargeStringTest.java</include>
<include>src/test/java/ro/kuberam/libs/java/crypto/digest/HMACStringTest.java</include -->
</includes>
</licenseSet>
</licenseSets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Tag>${build-tag}</Build-Tag>
<Git-Commit>${build-commit}</Git-Commit>
<Git-Commit-Abbrev>${build-commit-abbrev}</Git-Commit-Abbrev>
<Build-Version>${build-version}</Build-Version>
<Build-Timestamp>${build-tstamp}</Build-Timestamp>
<Source-Repository>${project.scm.connection}</Source-Repository>
<Description>${project.description}</Description>
<Implementation-URL>${project.url}</Implementation-URL>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<version>3.5.3</version>
<executions>
<execution>
<goals>
Expand All @@ -264,7 +238,7 @@
<plugin>
<groupId>com.ruleoftech</groupId>
<artifactId>markdown-page-generator-plugin</artifactId>
<version>2.3.0</version>
<version>2.4.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
Expand Down Expand Up @@ -314,26 +288,17 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<useAgent>true</useAgent>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId> <!-- avoid a bug with GPG plugin hanging http://jira.codehaus.org/browse/MGPG-9 -->
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>
<groupId>de.jutzig</groupId>
<artifactId>github-release-plugin</artifactId>
<version>1.4.0</version>
<version>1.6.0</version>
<executions>
<execution>
<id>github-upload</id>
Expand All @@ -343,14 +308,14 @@
</goals>
<inherited>false</inherited>
<configuration>
<description>eXist implementation for EXPath Cryptographic Module</description>
<releaseName>v6.0.0</releaseName>
<description>Implementation of EXPath Cryptographic Module</description>
<releaseName>EXPath Crypto Module ${project.version}</releaseName>
<tag>${project.version}</tag>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}*.xar</include>
<include>${package-final-name}.xar</include>
</includes>
</fileSet>
</fileSets>
Expand All @@ -361,4 +326,4 @@
</plugins>
</build>

</project>
</project>
17 changes: 13 additions & 4 deletions src/main/java/org/expath/exist/crypto/digest/HashFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ public class HashFunction extends BasicFunction {
"The cryptographic hashing algorithm.");

public static final FunctionSignature FS_HASH[] = functionSignatures(FS_HASH_NAME,
"resulting hash value, as string.", returnsOptMany(Type.BYTE),
arities(arity(FS_HASH_PARAM_DATA, FS_HASH_PARAM_ALGORITHM),
arity(FS_HASH_PARAM_DATA, FS_HASH_PARAM_ALGORITHM, param("encoding", Type.STRING,
"The encoding of the output. The legal values are \"hex\" and \"base64\". The default value is \"base64\"."))));
"resulting hash value, as string.", returnsOpt(Type.STRING),
arities(
arity(
FS_HASH_PARAM_DATA,
FS_HASH_PARAM_ALGORITHM
),
arity(
FS_HASH_PARAM_DATA,
FS_HASH_PARAM_ALGORITHM,
optParam("encoding", Type.STRING, "The encoding of the output. The legal values are \"hex\" and \"base64\". The default value is \"base64\".")
)
)
);

public HashFunction(final XQueryContext context, final FunctionSignature signature) {
super(context, signature);
Expand Down
38 changes: 23 additions & 15 deletions src/main/java/org/expath/exist/crypto/digest/HmacFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
*/
package org.expath.exist.crypto.digest;

import static org.exist.xquery.FunctionDSL.arities;
import static org.exist.xquery.FunctionDSL.arity;
import static org.exist.xquery.FunctionDSL.optManyParam;
import static org.exist.xquery.FunctionDSL.param;
import static org.exist.xquery.FunctionDSL.returnsOptMany;
import static org.exist.xquery.FunctionDSL.*;
import static org.expath.exist.crypto.ExistExpathCryptoModule.functionSignatures;

import java.io.IOException;
Expand Down Expand Up @@ -60,10 +56,21 @@ public class HmacFunction extends BasicFunction {
"The cryptographic hashing algorithm.");

public final static FunctionSignature FS_HMAC[] = functionSignatures(FS_HMAC_NAME, "Hashes the input message.",
returnsOptMany(Type.BYTE),
arities(arity(FS_HMAC_PARAM_DATA, FS_HMAC_PARAM_KEY, FS_HMAC_PARAM_ALGORITHM),
arity(FS_HMAC_PARAM_DATA, FS_HMAC_PARAM_KEY, FS_HMAC_PARAM_ALGORITHM, param("encoding", Type.STRING,
"The encoding of the output. The legal values are \"hex\" and \"base64\". The result is generated accordingly as xs:base64Binary string or xs:hexBinary string."))));
returnsOpt(Type.STRING),
arities(
arity(
FS_HMAC_PARAM_DATA,
FS_HMAC_PARAM_KEY,
FS_HMAC_PARAM_ALGORITHM
),
arity(
FS_HMAC_PARAM_DATA,
FS_HMAC_PARAM_KEY,
FS_HMAC_PARAM_ALGORITHM,
param("encoding", Type.STRING, "The encoding of the output. The legal values are \"hex\" and \"base64\". The result is generated accordingly as xs:base64Binary string or xs:hexBinary string.")
)
)
);

public HmacFunction(final XQueryContext context, final FunctionSignature signature) {
super(context, signature);
Expand All @@ -87,24 +94,25 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
final String algorithm = args[2].getStringValue();
LOG.debug("algorithm = {}", algorithm);

final String encoding;
final String resultString;
if (argsLength == 3) {
encoding = "base64";
final byte[] resultBytes;
if (data.isLeft()) {
try (final InputStream is = data.left().get()) {
resultBytes = Hmac.hmac(is, secretKey, algorithm);
resultString = Hmac.hmac(is, secretKey, algorithm, encoding);
}
dataStreamClosed = true;
} else {
resultBytes = Hmac.hmac(data.right().get(), secretKey, algorithm);
resultString = Hmac.hmac(data.right().get(), secretKey, algorithm, encoding);
}

result = Conversion.byteArrayToIntegerSequence(resultBytes);
result = new StringValue(resultString);
} else if (argsLength == 4) {
final String encoding = args[3].getStringValue().isEmpty() ? "base64" : args[3].getStringValue();
encoding = args[3].getStringValue().isEmpty() ? "base64" : args[3].getStringValue();
LOG.debug("encoding = {}", encoding);

final String resultString;

if (data.isLeft()) {
try (final InputStream is = data.left().get()) {
resultString = Hmac.hmac(is, secretKey, algorithm, encoding);
Expand Down
Loading
Loading