-
Notifications
You must be signed in to change notification settings - Fork 42
Enabling using secret values during a deployment #1755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karrgov
wants to merge
8
commits into
cloudfoundry:master
Choose a base branch
from
karrgov:passing_secrets_during_deployment_new
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2feafbd
Enabling using secret values during a deployment
karrgov a6078e5
Fixings of comments
karrgov 4424077
Adding the Ali cloud exclusion of bouncy castle
karrgov 5fa31a4
Fixing comments and adding additional new disposable UPS functionality
karrgov ae8c16d
Adding logging for testing purposes - flowable problem
karrgov 0f099c6
Adding fixes after disposable UPS functionality
karrgov d84ffcb
Fixing failing of Serializer and tests
karrgov bc82639
Fixing missing mtaId, which caused problems during bg deploy
karrgov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ava/org/cloudfoundry/multiapps/controller/core/security/encryption/AesEncryptionUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package org.cloudfoundry.multiapps.controller.core.security.encryption; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.security.InvalidAlgorithmParameterException; | ||
| import java.security.InvalidKeyException; | ||
| import java.security.NoSuchAlgorithmException; | ||
| import java.security.NoSuchProviderException; | ||
| import java.security.SecureRandom; | ||
| import java.text.MessageFormat; | ||
| import javax.crypto.Cipher; | ||
| import javax.crypto.NoSuchPaddingException; | ||
| import javax.crypto.spec.GCMParameterSpec; | ||
| import javax.crypto.spec.SecretKeySpec; | ||
|
|
||
| import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider; | ||
| import org.cloudfoundry.multiapps.common.SLException; | ||
| import org.cloudfoundry.multiapps.controller.core.Constants; | ||
| import org.cloudfoundry.multiapps.controller.core.Messages; | ||
|
|
||
| public class AesEncryptionUtil { | ||
|
|
||
| public static byte[] encrypt(String plainText, byte[] encryptionKey) { | ||
vkalapov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| byte[] gcmInitialisationVector = new byte[Constants.INITIALISATION_VECTOR_LENGTH]; | ||
| new SecureRandom().nextBytes(gcmInitialisationVector); | ||
|
|
||
| Cipher cipherObject = setUpCipherObject(encryptionKey, gcmInitialisationVector, Cipher.ENCRYPT_MODE); | ||
|
|
||
| byte[] cipherValue = cipherObject.doFinal(plainText.getBytes(StandardCharsets.UTF_8)); | ||
|
|
||
| byte[] combinedCipherValueAndInitialisationVector = new byte[gcmInitialisationVector.length + cipherValue.length]; | ||
|
|
||
| System.arraycopy(gcmInitialisationVector, 0, combinedCipherValueAndInitialisationVector, 0, gcmInitialisationVector.length); | ||
| System.arraycopy(cipherValue, 0, combinedCipherValueAndInitialisationVector, gcmInitialisationVector.length, | ||
| cipherValue.length); | ||
|
|
||
| return combinedCipherValueAndInitialisationVector; | ||
| } catch (Exception e) { | ||
| throw new SLException(MessageFormat.format(Messages.ENCRYPTION_HAS_FAILED, e.getMessage()), e); | ||
| } | ||
| } | ||
|
|
||
| public static String decrypt(byte[] encryptedValue, byte[] encryptionKey) { | ||
| try { | ||
| byte[] gcmInitialisationVector = new byte[Constants.INITIALISATION_VECTOR_LENGTH]; | ||
| System.arraycopy(encryptedValue, 0, gcmInitialisationVector, 0, | ||
| gcmInitialisationVector.length); | ||
|
|
||
| byte[] cipherValue = new byte[encryptedValue.length - Constants.INITIALISATION_VECTOR_LENGTH]; | ||
| System.arraycopy(encryptedValue, Constants.INITIALIZATION_VECTOR_POSITION, cipherValue, 0, cipherValue.length); | ||
|
|
||
| Cipher cipherObject = setUpCipherObject(encryptionKey, gcmInitialisationVector, Cipher.DECRYPT_MODE); | ||
|
|
||
| byte[] resultInBytes = cipherObject.doFinal(cipherValue); | ||
| return new String(resultInBytes, StandardCharsets.UTF_8); | ||
| } catch (Exception e) { | ||
| throw new SLException(MessageFormat.format(Messages.DECRYPTION_HAS_FAILED, e.getMessage()), e); | ||
| } | ||
| } | ||
|
|
||
| private static Cipher setUpCipherObject(byte[] encryptionKey, byte[] gcmInitialisationVector, int cipherMode) | ||
| throws InvalidAlgorithmParameterException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, | ||
| NoSuchProviderException { | ||
| Cipher cipherObject = Cipher.getInstance(Constants.CIPHER_TRANSFORMATION_NAME, BouncyCastleFipsProvider.PROVIDER_NAME); | ||
| SecretKeySpec secretKeySpec = new SecretKeySpec(encryptionKey, Constants.ENCRYPTION_DECRYPTION_ALGORITHM_NAME); | ||
| GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(Constants.GCM_AUTHENTICATION_TAG_LENGTH, gcmInitialisationVector); | ||
|
|
||
| cipherObject.init(cipherMode, secretKeySpec, gcmParameterSpec); | ||
|
|
||
| return cipherObject; | ||
| } | ||
|
|
||
| } | ||
73 changes: 73 additions & 0 deletions
73
...dfoundry/multiapps/controller/core/security/serialization/DynamicSecureSerialization.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package org.cloudfoundry.multiapps.controller.core.security.serialization; | ||
|
|
||
| import org.cloudfoundry.multiapps.controller.core.security.serialization.model.DeploymentDescriptorSerializer; | ||
| import org.cloudfoundry.multiapps.controller.core.security.serialization.model.ModuleSerializer; | ||
| import org.cloudfoundry.multiapps.controller.core.security.serialization.model.ProvidedDependencySerializer; | ||
| import org.cloudfoundry.multiapps.controller.core.security.serialization.model.RequiredDependencySerializer; | ||
| import org.cloudfoundry.multiapps.controller.core.security.serialization.model.ResourceSerializer; | ||
| import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; | ||
| import org.cloudfoundry.multiapps.mta.model.Module; | ||
| import org.cloudfoundry.multiapps.mta.model.ProvidedDependency; | ||
| import org.cloudfoundry.multiapps.mta.model.RequiredDependency; | ||
| import org.cloudfoundry.multiapps.mta.model.Resource; | ||
| import org.cloudfoundry.multiapps.mta.model.VersionedEntity; | ||
|
|
||
| public final class DynamicSecureSerialization { | ||
IvanBorislavovDimitrov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private final SecureSerializerConfiguration secureSerializerConfiguration; | ||
|
|
||
| public DynamicSecureSerialization(SecureSerializerConfiguration secureSerializerConfiguration) { | ||
| this.secureSerializerConfiguration = secureSerializerConfiguration; | ||
| } | ||
|
|
||
| public String toJson(Object object) { | ||
| SecureJsonSerializer secureJsonSerializer = createDynamicJsonSerializer(object); | ||
| return secureJsonSerializer.serialize(object); | ||
| } | ||
|
|
||
| private SecureJsonSerializer createDynamicJsonSerializer(Object object) { | ||
| SecureJsonSerializer secureJsonSerializer = createDynamicJsonSerializerForVersionedEntity(object); | ||
| if (secureJsonSerializer == null) { | ||
| return new SecureJsonSerializer(secureSerializerConfiguration); | ||
| } | ||
|
|
||
| return secureJsonSerializer; | ||
| } | ||
|
|
||
| private SecureJsonSerializer createDynamicJsonSerializerForVersionedEntity(Object object) { | ||
| if (object instanceof VersionedEntity) { | ||
| return createDynamicJsonSerializerForVersionedEntity((VersionedEntity) object); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| private SecureJsonSerializer createDynamicJsonSerializerForVersionedEntity(VersionedEntity versionedEntity) { | ||
| if (versionedEntity.getMajorSchemaVersion() < 3) { | ||
| return null; | ||
| } | ||
|
|
||
| if (versionedEntity instanceof DeploymentDescriptor) { | ||
| return new DeploymentDescriptorSerializer(secureSerializerConfiguration); | ||
| } | ||
|
|
||
| if (versionedEntity instanceof Module) { | ||
| return new ModuleSerializer(secureSerializerConfiguration); | ||
| } | ||
|
|
||
| if (versionedEntity instanceof ProvidedDependency) { | ||
| return new ProvidedDependencySerializer(secureSerializerConfiguration); | ||
| } | ||
|
|
||
| if (versionedEntity instanceof RequiredDependency) { | ||
| return new RequiredDependencySerializer(secureSerializerConfiguration); | ||
| } | ||
|
|
||
| if (versionedEntity instanceof Resource) { | ||
| return new ResourceSerializer(secureSerializerConfiguration); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| } | ||
18 changes: 18 additions & 0 deletions
18
...dfoundry/multiapps/controller/core/security/serialization/SecureSerializationFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.cloudfoundry.multiapps.controller.core.security.serialization; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| public final class SecureSerializationFactory { | ||
|
|
||
| private SecureSerializationFactory() { | ||
|
|
||
| } | ||
|
|
||
| public static DynamicSecureSerialization ofAdditionalValues(Collection<String> additionalSensitiveElementNames) { | ||
| SecureSerializerConfiguration secureSerializerConfigurationWithAdditionalValues = new SecureSerializerConfiguration(); | ||
|
|
||
| secureSerializerConfigurationWithAdditionalValues.setAdditionalSensitiveElementNames(additionalSensitiveElementNames); | ||
| return new DynamicSecureSerialization(secureSerializerConfigurationWithAdditionalValues); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.