Skip to content

Commit

Permalink
Add DGC-Gen-Lib Features
Browse files Browse the repository at this point in the history
  • Loading branch information
f11h authored Jun 7, 2021
2 parents fa4b365 + 42a2afe commit edd8015
Show file tree
Hide file tree
Showing 27 changed files with 1,669 additions and 16 deletions.
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,44 @@ Include as Maven Dependency in pom.xml
</dependencies>
```

If you do not need the DCC Gateway Connector feature you can exclude some dependencies by adding an exclusions tag:

```xml

<dependencies>
<dependency>
<groupId>eu.europa.ec.dgc</groupId>
<artifactId>dgc-lib</artifactId>
<version>1.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>io.github.openfeign</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
...
</dependencies>
```

### Authenticating to GitHub Packages

**Attention:**
GitHub does not allow anonymous access to it's package registry. You need to authenticate in order to use the dgc-lib artefact provided by us.
Therefore you need to authenticate to [GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry)
GitHub does not allow anonymous access to it's package registry. You need to authenticate in order to use the dgc-lib
artefact provided by us. Therefore you need to authenticate
to [GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry)
The following steps need to be performed

- Create [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) with scopes:
- `read:packages` for downloading packages
- Copy/Augment `~/.m2/settings.xml` with the contents of `settings.xml` present in this repository (or in the DGC repository you are trying to build)
- Replace `${app.packages.username}` with your github username
- Replace `${app.packages.password}` with the generated PAT
- `read:packages` for downloading packages
- Copy/Augment `~/.m2/settings.xml` with the contents of `settings.xml` present in this repository (or in the DGC
repository you are trying to build)
- Replace `${app.packages.username}` with your github username
- Replace `${app.packages.password}` with the generated PAT

## Development

Expand Down
26 changes: 20 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<junit.version>5.7.1</junit.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<commonsio.version>2.8.0</commonsio.version>
<cbor.version>4.4.3</cbor.version>
<jackson.version>2.11.4</jackson.version>

<plugin.checkstyle.version>3.1.2</plugin.checkstyle.version>
<plugin.sonar.version>3.6.1.1688</plugin.sonar.version>
Expand Down Expand Up @@ -74,17 +76,19 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring.boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
<version>${spring.boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down Expand Up @@ -112,6 +116,21 @@
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bcpkix.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commonsio.version}</version>
</dependency>
<dependency>
<groupId>com.upokecenter</groupId>
<artifactId>cbor</artifactId>
<version>${cbor.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -125,11 +144,6 @@
<scope>test</scope>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commonsio.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static class Proxy {
/**
* Enable HTTP Proxy.
*/
private boolean enabled = false;
private boolean enabled;

/**
* Host Address of Proxy server (without protocol).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public KeyStore trustAnchorKeyStore() throws KeyStoreException, IOException,
}

private void loadKeyStore(KeyStore keyStore, String path, char[] password)
throws CertificateException, NoSuchAlgorithmException, IOException {
throws CertificateException, NoSuchAlgorithmException {

try (InputStream fileStream = new FileInputStream(ResourceUtils.getFile(path))) {

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/eu/europa/ec/dgc/generation/Base45Encoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eu.europa.ec.dgc.generation;

/**
* Base45 Encoder.
*/
public class Base45Encoder {
private static final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";

private Base45Encoder() {
}

/**
* Encode a byte array to Base45 String.
*
* @param bytes bytes to encode
* @return encoded string
*/
public static String encodeToString(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < bytes.length; i += 2) {
if (bytes.length - i > 1) {
int x = ((bytes[i] & 0xFF) << 8) + (bytes[i + 1] & 0xFF);
int e = x / (45 * 45);
int y = x % (45 * 45);
int d = y / 45;
int c = y % 45;
result.append(ALPHABET.charAt(c)).append(ALPHABET.charAt(d)).append(ALPHABET.charAt(e));
} else {
int x = bytes[i] & 0xFF;
int d = x / 45;
int c = x % 45;
result.append(ALPHABET.charAt(c)).append(ALPHABET.charAt(d));
}
}
return result.toString();
}
}
98 changes: 98 additions & 0 deletions src/main/java/eu/europa/ec/dgc/generation/CopyDigest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package eu.europa.ec.dgc.generation;

import java.io.ByteArrayOutputStream;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.util.Arrays;
import org.springframework.stereotype.Service;

@Service
public class CopyDigest implements Digest {

private final OpenByteArrayOutputStream binaryOut = new OpenByteArrayOutputStream();
private final SHA256Digest sha256Digest = new SHA256Digest();
private boolean wasReset = false;

public String getAlgorithmName() {
return "NULL";
}

public int getDigestSize() {
return 32;
}

/**
* Updates the Message Digest with one byte.
*
* @param in byte to update.
*/
public void update(byte in) {
if (wasReset) {
sha256Digest.update(in);
} else {
binaryOut.write(in);
}
}

/**
* Updates the Message Digest with a byte array.
*
* @param in byte array to insert
* @param offset Offset
* @param length length
*/
public void update(byte[] in, int offset, int length) {
if (wasReset) {
sha256Digest.update(in, offset, length);
} else {
binaryOut.write(in, offset, length);
}
}

/**
* close the digest, producing the final digest value. The doFinal
* call leaves the digest reset.
*
* @param out the array the digest is to be copied into.
* @param offset the offset into the out array the digest is to start at.
* @return size of output
*/
public int doFinal(byte[] out, int offset) {
if (wasReset) {
return sha256Digest.doFinal(out, offset);
} else {
int size = binaryOut.size();
binaryOut.copy(out, offset);
reset();
return size;
}
}

/**
* Resets the Message Digest.
*/
@Override
public void reset() {
if (wasReset) {
sha256Digest.reset();
} else {
if (binaryOut.size() > 0) {
wasReset = true;
binaryOut.reset();
}
}
}

private static class OpenByteArrayOutputStream
extends ByteArrayOutputStream {
public synchronized void reset() {
super.reset();

Arrays.clear(buf);
}

void copy(byte[] out, int outOff) {
System.arraycopy(buf, 0, out, outOff, this.size());
}
}
}
Loading

0 comments on commit edd8015

Please sign in to comment.