Skip to content

Commit

Permalink
Added mutable encryption config to BasicFunctionalityIT
Browse files Browse the repository at this point in the history
  • Loading branch information
Thendo20 committed Jun 23, 2024
1 parent d61b499 commit 4200e5c
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 15 deletions.
6 changes: 6 additions & 0 deletions datasafe-business/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.15.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package de.adorsys.datasafe.business.impl.e2e;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.google.common.io.Resources;
import de.adorsys.datasafe.business.impl.service.DefaultDatasafeServices;
import de.adorsys.datasafe.encrypiton.api.types.UserID;
import de.adorsys.datasafe.encrypiton.api.types.UserIDAuth;
import de.adorsys.datasafe.encrypiton.api.types.encryption.MutableEncryptionConfig;
import de.adorsys.datasafe.storage.api.StorageService;
import de.adorsys.datasafe.teststorage.WithStorageProvider;
import de.adorsys.datasafe.types.api.actions.ListRequest;
Expand All @@ -21,11 +27,11 @@
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.security.UnrecoverableKeyException;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -54,6 +60,7 @@ class BasicFunctionalityIT extends BaseE2EIT {

private StorageService storage;
private Uri location;
private static ObjectMapper mapper = createMapper();


/**
Expand Down Expand Up @@ -277,6 +284,37 @@ void testWriteToPrivateListPrivateReadPrivateAndSendToAndReadFromInbox(
removeFromPrivate(jane, privateJane.getResource().asPrivate());
removeFromInbox(john, inboxJohn.getResource().asPrivate());
}
@ParameterizedTest
@MethodSource("allStorages")
void testWriteToPrivateListPrivateReadPrivateAndSendToAndReadFromInboxCustom( WithStorageProvider.StorageDescriptor descriptor) {
String yamlFixture = "config/mutable.yaml";
customInit(descriptor, yamlFixture);

registerJohnAndJane();

writeDataToPrivate(jane, PRIVATE_FILE_PATH, MESSAGE_ONE);

AbsoluteLocation<ResolvedResource> privateJane = getFirstFileInPrivate(jane);

String privateContentJane = readPrivateUsingPrivateKey(jane, privateJane.getResource().asPrivate());

sendToInbox(jane, john.getUserID(), SHARED_FILE_PATH, privateContentJane);

AbsoluteLocation<ResolvedResource> inboxJohn = getFirstFileInInbox(john);

String result = readInboxUsingPrivateKey(john, inboxJohn.getResource().asPrivate());

assertThat(result).isEqualTo(MESSAGE_ONE);
assertThat(privateJane.getResource().asPrivate().decryptedPath())
.extracting(Uri::toASCIIString).isEqualTo(PRIVATE_FILE_PATH);
assertThat(privateJane.getResource().asPrivate().encryptedPath())
.extracting(Uri::toASCIIString).isNotEqualTo(PRIVATE_FILE_PATH);
validateInboxStructAndEncryption(inboxJohn);
validatePrivateStructAndEncryption(privateJane);

removeFromPrivate(jane, privateJane.getResource().asPrivate());
removeFromInbox(john, inboxJohn.getResource().asPrivate());
}

@ParameterizedTest
@MethodSource("allStorages")
Expand Down Expand Up @@ -387,4 +425,28 @@ private void init(WithStorageProvider.StorageDescriptor descriptor) {
this.location = descriptor.getLocation();
this.storage = descriptor.getStorageService().get();
}
private void customInit(WithStorageProvider.StorageDescriptor descriptor, String yamlFixture) {
MutableEncryptionConfig config = readResource(mapper, yamlFixture, MutableEncryptionConfig.class);
DefaultDatasafeServices datasafeServices = DatasafeServicesProvider
.customConfigDatasafeServices(descriptor.getStorageService().get(), descriptor.getLocation(), config);
initialize(DatasafeServicesProvider.dfsConfig(descriptor.getLocation()), datasafeServices);

this.location = descriptor.getLocation();
this.storage = descriptor.getStorageService().get();
}

private static <T> T readResource(ObjectMapper mapper, String path, Class<T> type) {
try (Reader reader = Resources.asCharSource(Resources.getResource(path), StandardCharsets.UTF_8).openStream()) {
return mapper.readValue(reader, type);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}

private static ObjectMapper createMapper() {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.adorsys.datasafe.business.impl.service.VersionedDatasafeServices;
import de.adorsys.datasafe.directory.api.config.DFSConfig;
import de.adorsys.datasafe.directory.impl.profile.config.DefaultDFSConfig;
import de.adorsys.datasafe.encrypiton.api.types.encryption.MutableEncryptionConfig;
import de.adorsys.datasafe.storage.api.StorageService;
import de.adorsys.datasafe.types.api.resource.Uri;
import de.adorsys.datasafe.types.api.types.ReadStorePassword;
Expand All @@ -26,6 +27,14 @@ public static DefaultDatasafeServices defaultDatasafeServices(StorageService sto
.storage(storageService)
.build();
}
public static DefaultDatasafeServices customConfigDatasafeServices(StorageService storageService, Uri systemRoot, MutableEncryptionConfig config) {
return DaggerDefaultDatasafeServices
.builder()
.config(dfsConfig(systemRoot))
.encryption(config.toEncryptionConfig())
.storage(storageService)
.build();
}

public static VersionedDatasafeServices versionedDatasafeServices(StorageService storageService, Uri systemRoot) {
return DaggerVersionedDatasafeServices
Expand Down
30 changes: 30 additions & 0 deletions datasafe-business/src/test/resources/config/mutable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
keystore:
type: BCFKS
encryptionAlgo: AES256_KWP
pbkdf:
scrypt:
cost: 1
blockSize: 2
parallelization: 3
saltLength: 32
macAlgo: HmacSHA3_512
passwordKeysAlgo: PBEWithHmacSHA256AndAES_256
keys:
encKeyNumber: 1
signKeyNumber: 2
secret:
algo: AES
size: 512
encrypting:
algo: RSA
size: 256
sigAlgo: SHA256withRSA
# curve:
signing:
algo: RSA
size: 256
sigAlgo: SHA256withRSA
# curve: curve
cms:
algo: SHA256withRSA
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
---
keystore:
type: store-type
encryptionAlgo: store-enc
type: BCFKS
encryptionAlgo: AES256_KWP
pbkdf:
pbkdf2:
algo: pbkdf-algo
saltLength: 2
iterCount: 3
macAlgo: store-mac
passwordKeysAlgo: store-pwd-keys
scrypt:
cost: 1
blockSize: 2
parallelization: 3
saltLength: 4
macAlgo: HmacSHA3_512
passwordKeysAlgo: PBEWithHmacSHA256AndAES_256
keys:
encKeyNumber: 1
signKeyNumber: 2
secret:
algo: sec-algo
algo: AES
size: 12
encrypting:
algo: enc-algo
algo: RSA
size: 13
sigAlgo: srv-sig-algo
curve: curve
curve:
signing:
algo: sig-algo
size: 14
sigAlgo: srv-sig-algo
sigAlgo: SHA256withRSA
curve: curve
cms:
algo: cms-algo1

0 comments on commit 4200e5c

Please sign in to comment.