-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved encryption-sdk from lib to modules to resolve dependency issues
Signed-off-by: Vikas Bansal <43470111+vikasvb90@users.noreply.github.com>
- Loading branch information
Showing
48 changed files
with
957 additions
and
408 deletions.
There are no files selected for viewing
This file contains 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 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
1 change: 0 additions & 1 deletion
1
libs/encryption-sdk/licenses/aws-encryption-sdk-java-2.4.0.jar.sha1
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
libs/encryption-sdk/src/main/java/org/opensearch/encryption/CryptoManager.java
This file was deleted.
Oops, something went wrong.
127 changes: 0 additions & 127 deletions
127
libs/encryption-sdk/src/main/java/org/opensearch/encryption/CryptoManagerFactory.java
This file was deleted.
Oops, something went wrong.
This file contains 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 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 @@ | ||
51704a672e65456d37f444c5992c079feff31218 |
File renamed without changes.
File renamed without changes.
This file contains 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 @@ | ||
df22e1b6a9f6b218913f5b68dd16641344397fe0 |
This file contains 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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2000 - 2013 The Legion of the Bouncy Castle Inc. | ||
(http://www.bouncycastle.org) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions
67
modules/crypto/src/main/java/org/opensearch/encryption/CryptoModulePlugin.java
This file contains 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,67 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.encryption; | ||
|
||
import org.opensearch.common.crypto.CryptoHandler; | ||
import org.opensearch.common.crypto.MasterKeyProvider; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.encryption.keyprovider.CryptoMasterKey; | ||
import org.opensearch.plugins.CryptoPlugin; | ||
import org.opensearch.plugins.Plugin; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.amazonaws.encryptionsdk.caching.CachingCryptoMaterialsManager; | ||
import com.amazonaws.encryptionsdk.caching.LocalCryptoMaterialsCache; | ||
|
||
public class CryptoModulePlugin extends Plugin implements CryptoPlugin<Object, Object> { | ||
|
||
private final int dataKeyCacheSize = 500; | ||
private final String algorithm = "ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY"; | ||
|
||
// - Cache TTL and Jitter is used to decide the Crypto Cache TTL. | ||
// - Random number between: (TTL Jitter, TTL - Jitter) | ||
private final long dataKeyCacheTTL = TimeValue.timeValueDays(2).getMillis(); | ||
private static final long dataKeyCacheJitter = TimeUnit.MINUTES.toMillis(30); // - 30 minutes | ||
|
||
public CryptoHandler<Object, Object> getOrCreateCryptoHandler( | ||
MasterKeyProvider keyProvider, | ||
String keyProviderName, | ||
String keyProviderType, | ||
Runnable onClose | ||
) { | ||
CachingCryptoMaterialsManager materialsManager = createMaterialsManager(keyProvider, keyProviderName, algorithm); | ||
return createCryptoHandler(algorithm, materialsManager, keyProvider); | ||
} | ||
|
||
// package private for tests | ||
CryptoHandler<Object, Object> createCryptoHandler( | ||
String algorithm, | ||
CachingCryptoMaterialsManager materialsManager, | ||
MasterKeyProvider masterKeyProvider | ||
) { | ||
return new NoOpCryptoHandler(); | ||
} | ||
|
||
// Package private for tests | ||
CachingCryptoMaterialsManager createMaterialsManager(MasterKeyProvider masterKeyProvider, String keyProviderName, String algorithm) { | ||
SecureRandom r = new SecureRandom(); | ||
long low = dataKeyCacheTTL - dataKeyCacheJitter; | ||
long high = dataKeyCacheTTL + dataKeyCacheJitter; | ||
long masterKeyCacheTTL = r.nextInt((int) (high - low)) + low; | ||
|
||
CryptoMasterKey cryptoMasterKey = new CryptoMasterKey(masterKeyProvider, keyProviderName, algorithm); | ||
return CachingCryptoMaterialsManager.newBuilder() | ||
.withMasterKeyProvider(cryptoMasterKey) | ||
.withCache(new LocalCryptoMaterialsCache(dataKeyCacheSize)) | ||
.withMaxAge(masterKeyCacheTTL, TimeUnit.MILLISECONDS) | ||
.build(); | ||
} | ||
} |
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.