From 63957d915674c81bd14db0ebb4ae852014748ea1 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 11 May 2022 16:29:49 +0200 Subject: [PATCH] SEBSERV-304 --- .../impl/AbstractCertificateCryptor.java | 5 +++- .../impl/CertificateAsymetricKeyCryptor.java | 5 ++++ .../impl/CertificateSymetricKeyCryptor.java | 5 ++++ .../impl/SEBConfigEncryptionServiceImpl.java | 28 ------------------- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/AbstractCertificateCryptor.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/AbstractCertificateCryptor.java index b049cff1..b07dcd62 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/AbstractCertificateCryptor.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/AbstractCertificateCryptor.java @@ -25,6 +25,7 @@ import ch.ethz.seb.sebserver.gbl.model.sebconfig.Certificates; import ch.ethz.seb.sebserver.gbl.util.Cryptor; import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.CertificateService; import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.SEBConfigEncryptionContext; +import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.SEBConfigEncryptionService; import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.impl.SEBConfigEncryptionServiceImpl.EncryptionContext; public abstract class AbstractCertificateCryptor { @@ -65,7 +66,7 @@ public abstract class AbstractCertificateCryptor { if (Arrays.equals(otherPublicKeyHash, publicKeyHash)) { return EncryptionContext.contextOf( sebConfigEncryptionContext.institutionId(), - sebConfigEncryptionContext.getStrategy(), + getStrategy(), certificate, alias); } @@ -79,6 +80,8 @@ public abstract class AbstractCertificateCryptor { } } + protected abstract SEBConfigEncryptionService.Strategy getStrategy(); + protected byte[] generatePublicKeyHash(final Certificate cert) { try { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/CertificateAsymetricKeyCryptor.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/CertificateAsymetricKeyCryptor.java index e6181dea..835a8590 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/CertificateAsymetricKeyCryptor.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/CertificateAsymetricKeyCryptor.java @@ -132,4 +132,9 @@ public class CertificateAsymetricKeyCryptor extends AbstractCertificateCryptor i } } + @Override + protected Strategy getStrategy() { + return Strategy.PUBLIC_KEY_HASH; + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/CertificateSymetricKeyCryptor.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/CertificateSymetricKeyCryptor.java index e91f0d40..b10c8cdf 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/CertificateSymetricKeyCryptor.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/CertificateSymetricKeyCryptor.java @@ -194,4 +194,9 @@ public class CertificateSymetricKeyCryptor extends AbstractCertificateCryptor im return byteArray; } + @Override + protected Strategy getStrategy() { + return Strategy.PUBLIC_KEY_HASH_SYMMETRIC_KEY; + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/SEBConfigEncryptionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/SEBConfigEncryptionServiceImpl.java index e94da6c4..ce6156fd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/SEBConfigEncryptionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/SEBConfigEncryptionServiceImpl.java @@ -150,34 +150,6 @@ public final class SEBConfigEncryptionServiceImpl implements SEBConfigEncryption .getOrThrow() .decrypt(pout, newIn, context); -// if (strategy == Strategy.PLAIN_TEXT) { -// -// getEncryptor(strategy) -// .getOrThrow() -// .decrypt(pout, newIn, context); -// -// } else if ((strategy == Strategy.PASSWORD_PSWD || strategy == Strategy.PASSWORD_PWCC)) { -// if (StringUtils.isBlank(context.getPassword())) { -// return new AsyncResult<>(new APIMessage.APIMessageException( -// APIMessage.ErrorMessage.MISSING_PASSWORD.of("Missing Password"))); -// } else { -// -// // then decrypt stream with password -// getEncryptor(strategy) -// .getOrThrow() -// .decrypt(pout, newIn, context); -// } -// } else { -// -// // then decrypt stream with certificate -// getEncryptor(strategy) -// .getOrThrow() -// .decrypt( -// pout, -// newIn, -// EncryptionContext.contextOf(context.institutionId(), strategy, null, null)); -// } - IOUtils.copyLarge(pin, output); return new AsyncResult<>(null);