forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create datasource API (opensearch-project#1458) (opensearch-project#1479
- Loading branch information
Showing
51 changed files
with
1,815 additions
and
367 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
Oops, something went wrong.