-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: vamsi-amazon <[email protected]>
- Loading branch information
Showing
49 changed files
with
1,780 additions
and
370 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,5 @@ gen | |
/.prom.pid.lock | ||
|
||
.java-version | ||
.worktrees | ||
.worktrees | ||
http-client.env.json |
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
28 changes: 28 additions & 0 deletions
28
common/src/main/java/org/opensearch/sql/common/encryptor/Encryptor.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,28 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.common.encryptor; | ||
|
||
public interface Encryptor { | ||
|
||
/** | ||
* Takes plaintext and returns encrypted text. | ||
* | ||
* @param plainText plainText. | ||
* @return String encryptedText. | ||
*/ | ||
String encrypt(String plainText); | ||
|
||
/** | ||
* Takes encryptedText and returns plain text. | ||
* | ||
* @param encryptedText encryptedText. | ||
* @return String plainText. | ||
*/ | ||
String decrypt(String encryptedText); | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
common/src/main/java/org/opensearch/sql/common/encryptor/EncryptorImpl.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,55 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.common.encryptor; | ||
|
||
import com.amazonaws.encryptionsdk.AwsCrypto; | ||
import com.amazonaws.encryptionsdk.CommitmentPolicy; | ||
import com.amazonaws.encryptionsdk.CryptoResult; | ||
import com.amazonaws.encryptionsdk.jce.JceMasterKey; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import javax.crypto.spec.SecretKeySpec; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class EncryptorImpl implements Encryptor { | ||
|
||
private final String masterKey; | ||
|
||
@Override | ||
public String encrypt(String plainText) { | ||
|
||
final AwsCrypto crypto = AwsCrypto.builder() | ||
.withCommitmentPolicy(CommitmentPolicy.RequireEncryptRequireDecrypt) | ||
.build(); | ||
|
||
JceMasterKey jceMasterKey | ||
= JceMasterKey.getInstance(new SecretKeySpec(masterKey.getBytes(), "AES"), "Custom", "", | ||
"AES/GCM/NoPadding"); | ||
|
||
final CryptoResult<byte[], JceMasterKey> encryptResult = crypto.encryptData(jceMasterKey, | ||
plainText.getBytes(StandardCharsets.UTF_8)); | ||
return Base64.getEncoder().encodeToString(encryptResult.getResult()); | ||
} | ||
|
||
@Override | ||
public String decrypt(String encryptedText) { | ||
final AwsCrypto crypto = AwsCrypto.builder() | ||
.withCommitmentPolicy(CommitmentPolicy.RequireEncryptRequireDecrypt) | ||
.build(); | ||
|
||
JceMasterKey jceMasterKey | ||
= JceMasterKey.getInstance(new SecretKeySpec(masterKey.getBytes(), "AES"), "Custom", "", | ||
"AES/GCM/NoPadding"); | ||
|
||
final CryptoResult<byte[], JceMasterKey> decryptedResult | ||
= crypto.decryptData(jceMasterKey, Base64.getDecoder().decode(encryptedText)); | ||
return new String(decryptedResult.getResult()); | ||
} | ||
|
||
} |
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
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
19 changes: 19 additions & 0 deletions
19
core/src/main/java/org/opensearch/sql/datasource/DataSourceUserAuthorizationHelper.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,19 @@ | ||
package org.opensearch.sql.datasource; | ||
|
||
import java.util.List; | ||
import org.opensearch.sql.datasource.model.DataSourceMetadata; | ||
|
||
/** | ||
* Interface for datasource authorization helper. | ||
* The implementation of this class helps in determining | ||
* if authorization is required and the roles associated with the user. | ||
*/ | ||
public interface DataSourceUserAuthorizationHelper { | ||
|
||
/** | ||
* Authorizes DataSource within the current context. | ||
* | ||
* @param dataSourceMetadata {@link DataSourceMetadata} | ||
*/ | ||
void authorizeDataSource(DataSourceMetadata dataSourceMetadata); | ||
} |
Oops, something went wrong.