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
36 changes: 0 additions & 36 deletions .classpath

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
target/
*.iml
.idea/
.classpath
.settings
.vscode

6 changes: 0 additions & 6 deletions .settings/org.eclipse.core.resources.prefs

This file was deleted.

5 changes: 0 additions & 5 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

4 changes: 0 additions & 4 deletions .settings/org.eclipse.m2e.core.prefs

This file was deleted.

17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# Warning: Current release of eXist crypto lib 5.3.0 has known fatal issues. See https://github.com/eXist-db/crypto-exist-java-lib/issues/33.
# eXist-db implementation for EXPath Cryptographic Module

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

Requires:
* Java 1.8 or newer
* Maven 3.6 or newer

```bash
$ git clone https://github.com/eXist-db/crypto-exist-java-lib
$ cd crypto-exist-java-lib
$ 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.

### Currently implemented functions

* crypto:hash()
Expand Down
74 changes: 47 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.exist-db.xquery.extensions.expath</groupId>
<artifactId>expath-crypto-module</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>

<name>eXist-db EXPath Cryptographic library</name>
<description>eXist-db wrapper for EXPath Cryptographic Java library</description>
Expand All @@ -27,15 +27,15 @@
</licenses>

<scm>
<url>https://github.com/exist-db/crypto-exist-java-lib.git</url>
<url>scm:git://github.com/exist-db/crypto-exist-java-lib.git</url>
<connection>scm:git:https://github.com/exist-db/crypto-exist-java-lib.git</connection>
<developerConnection>scm:git:https://github.com/exist-db/crypto-exist-java-lib.git</developerConnection>
<tag>HEAD</tag>
</scm>

<organization>
<name>Kuberam</name>
<url>http://kuberam.ro</url>
<name>exist-db Project</name>
<url>https://exist-db.org</url>
</organization>

<developers>
Expand All @@ -44,28 +44,37 @@
<name>Claudius Teodorescu</name>
<email>[email protected]</email>
</developer>
<developer>
<id>olaf</id>
<name>Olaf Schreck</name>
<email>[email protected]</email>
</developer>
</developers>

<contributors>
<contributor>
<name>Adam Retter</name>
<email>[email protected]</email>
</contributor>
<contributor>
<name>Juri Leino</name>
<email>[email protected]</email>
</contributor>
</contributors>

<properties>
<package.title>EXPath Cryptographic Module Implementation</package.title>
<crypto.java.lib.version>1.5</crypto.java.lib.version>
<exist.version>5.2.0</exist.version>
<crypto.java.lib.version>1.8.0</crypto.java.lib.version>
<exist.version>5.3.0</exist.version>
<crypto.module.ns>http://expath.org/ns/crypto</crypto.module.ns>
<package-abbrev>crypto</package-abbrev>
<package-name>${crypto.module.ns}</package-name>
</properties>

<dependencies>
<dependency>
<groupId>ro.kuberam.libs.java</groupId>
<artifactId>crypto</artifactId>
<groupId>org.expath.crypto</groupId>
<artifactId>crypto-java</artifactId>
<version>${crypto.java.lib.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -134,7 +143,7 @@
<version>2.3.0</version>
<executions>
<execution>
<phase>package</phase>
<phase>prepare-package</phase>
<goals>
<goal>generate</goal>
</goals>
Expand All @@ -144,26 +153,9 @@
<inputDirectory>${project.basedir}</inputDirectory>
<headerHtmlFile>${project.basedir}/build/header.html</headerHtmlFile>
<footerHtmlFile>${project.basedir}/build/footer.html</footerHtmlFile>
<defaultTitle>index.html</defaultTitle>
</configuration>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>rename-readme-file</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/html/README.html</sourceFile>
<destinationFile>${project.build.directory}/html/index.html</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>ro.kuberam.maven.plugins</groupId>
<artifactId>kuberam-expath-plugin</artifactId>
Expand Down Expand Up @@ -197,6 +189,34 @@
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>
<groupId>de.jutzig</groupId>
<artifactId>github-release-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>github-upload</id>
<phase>deploy</phase>
<goals>
<goal>release</goal>
</goals>
<inherited>false</inherited>
<configuration>
<description>eXist implementation for EXPath Cryptographic Module</description>
<releaseName>v6.0.0</releaseName>
<tag>${project.version}</tag>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}*.xar</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class EXpathCryptoException extends XPathException {
private static final long serialVersionUID = -6789727720893604433L;

public EXpathCryptoException(Expression expr, CryptoError cryptoError) {
super(expr, new ExpathCryptoErrorCode(cryptoError), ExpathCryptoErrorCode.getDescription(cryptoError));
super(expr, new ExpathCryptoErrorCode(cryptoError), cryptoError.getDescription());
}

public EXpathCryptoException(Expression expr, Exception exception) {
Expand Down
14 changes: 1 addition & 13 deletions src/main/java/org/expath/exist/crypto/ExpathCryptoErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,12 @@

import ro.kuberam.libs.java.crypto.CryptoError;

import java.lang.reflect.Field;

public class ExpathCryptoErrorCode extends ErrorCode {
public ExpathCryptoErrorCode(String code, String description) {
super(new QName(code, ExistExpathCryptoModule.NAMESPACE_URI, ExistExpathCryptoModule.PREFIX), description);
}

public ExpathCryptoErrorCode(CryptoError cryptoError) {
super(new QName(cryptoError.name(), ExistExpathCryptoModule.NAMESPACE_URI, ExistExpathCryptoModule.PREFIX), getDescription(cryptoError));
}

public static String getDescription(final CryptoError cryptoError) {
try {
final Field field = cryptoError.getClass().getDeclaredField("description");
field.setAccessible(true);
return (String) field.get(cryptoError);
} catch (final NoSuchFieldException | IllegalAccessException e) {
return "UNKNOWN";
}
super(new QName(cryptoError.getCode(), ExistExpathCryptoModule.NAMESPACE_URI, ExistExpathCryptoModule.PREFIX), cryptoError.getDescription());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -73,8 +72,12 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro

final int inputType = args[0].itemAt(0).getType();
final String hashAlgorithm = args[1].getStringValue();
final String encoding = Optional.ofNullable(args[2].getStringValue()).filter(str -> !str.isEmpty())
.orElse("base64");
final String encoding;
if (args.length == 2) {
encoding = "base64";
} else {
encoding = args[2].getStringValue().isEmpty() ? "base64" : args[2].getStringValue();
}
LOG.debug("encoding = {}", () -> encoding);

final Sequence result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -101,9 +100,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro

result = Conversion.byteArrayToIntegerSequence(resultBytes);
} else if (argsLength == 4) {

final String encoding = Optional.ofNullable(args[3].getStringValue()).filter(str -> !str.isEmpty())
.orElse("base64");
final String encoding = args[3].getStringValue().isEmpty() ? "base64" : args[3].getStringValue();
LOG.debug("encoding = {}", () -> encoding);

final String resultString;
Expand Down
Loading