-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added decryption pool for bounded decryption
- Loading branch information
Showing
8 changed files
with
230 additions
and
11 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
.../crypto/src/internalClusterTest/java/org/opensearch/encryption/CryptoModuleIntegTest.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,15 @@ | ||
/* | ||
* 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.test.OpenSearchIntegTestCase; | ||
|
||
public abstract class CryptoModuleIntegTest extends OpenSearchIntegTestCase { | ||
|
||
} |
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
62 changes: 62 additions & 0 deletions
62
...es/crypto/src/main/java/org/opensearch/encryption/frame/CryptoAsyncByteChannelWriter.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,62 @@ | ||
/* | ||
* 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.frame; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.channels.AsynchronousByteChannel; | ||
import java.nio.channels.CompletionHandler; | ||
|
||
import com.amazonaws.encryptionsdk.internal.MessageCryptoHandler; | ||
|
||
/** | ||
* Performs async | ||
*/ | ||
public class CryptoAsyncByteChannelWriter { | ||
|
||
private final MessageCryptoHandler cryptoHandler; | ||
private final AsynchronousByteChannel asyncByteChannel; | ||
|
||
public CryptoAsyncByteChannelWriter(AsynchronousByteChannel asyncByteChannel, MessageCryptoHandler cryptoHandler) { | ||
this.asyncByteChannel = asyncByteChannel; | ||
this.cryptoHandler = cryptoHandler; | ||
} | ||
|
||
/** | ||
* Create a ByteBuffer and publishes response to handler. If sufficient bytes were received for decryption then | ||
* response with decrypted bytes is published otherwise 0 bytes are published in result on handler. | ||
*/ | ||
private void write(final byte[] b, final int off, final int len, CompletionHandler<Integer, ByteBuffer> handler) { | ||
try { | ||
if (b == null) { | ||
throw new IllegalArgumentException("b cannot be null"); | ||
} | ||
|
||
if (len < 0 || off < 0) { | ||
throw new IllegalArgumentException(String.format("Invalid values for offset: %d and length: %d", off, len)); | ||
} | ||
|
||
final int outLen = cryptoHandler.estimatePartialOutputSize(len); | ||
final byte[] outBytes = new byte[outLen]; | ||
|
||
int bytesWritten = cryptoHandler.processBytes(b, off, len, outBytes, 0).getBytesWritten(); | ||
ByteBuffer byteBuffer = ByteBuffer.wrap(outBytes, 0, bytesWritten); | ||
if (bytesWritten > 0) { | ||
asyncByteChannel.write(byteBuffer, byteBuffer, handler); | ||
} else { | ||
handler.completed(0, byteBuffer); | ||
} | ||
} catch (Exception ex) { | ||
handler.failed(ex, null); | ||
} | ||
} | ||
|
||
public void setMaxInputLength(long size) { | ||
cryptoHandler.setMaxInputLength(size); | ||
} | ||
} |
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.