-
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.
Signed-off-by: Vikas Bansal <vikasvb@amazon.com>
- Loading branch information
Showing
23 changed files
with
613 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.common; | ||
|
||
import java.io.InputStream; | ||
|
||
/** | ||
* Model composed of an input stream, the total content length and offset | ||
*/ | ||
public class Stream { | ||
|
||
private final InputStream inputStream; | ||
private final long contentLength; | ||
private final long offset; | ||
|
||
/** | ||
* Construct a new stream object | ||
* | ||
* @param inputStream The input stream that is to be encapsulated | ||
* @param contentLength The total content length that is to be read from the stream | ||
* @param offset The offset pointer that this stream reads from in the file | ||
*/ | ||
public Stream(InputStream inputStream, long contentLength, long offset) { | ||
this.inputStream = inputStream; | ||
this.contentLength = contentLength; | ||
this.offset = offset; | ||
} | ||
|
||
/** | ||
* @return The input stream this object is reading from | ||
*/ | ||
public InputStream getInputStream() { | ||
return inputStream; | ||
} | ||
|
||
/** | ||
* @return The total length of the content that has to be read from this stream | ||
*/ | ||
public long getContentLength() { | ||
return contentLength; | ||
} | ||
|
||
/** | ||
* @return The offset pointer in the file that this stream is reading from | ||
*/ | ||
public long getOffset() { | ||
return offset; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
server/src/main/java/org/opensearch/crypto/CryptoClient.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,92 @@ | ||
/* | ||
* 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.crypto; | ||
|
||
import org.opensearch.common.Stream; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.concurrent.RefCounted; | ||
|
||
import java.io.InputStream; | ||
|
||
/** | ||
* Crypto plugin interface used for encryption and decryption. | ||
*/ | ||
public interface CryptoClient extends RefCounted { | ||
|
||
/** | ||
* A factory interface for constructing crypto client. | ||
* | ||
*/ | ||
interface Factory { | ||
|
||
/** | ||
* Constructs a crypto client used for encryption and decryption | ||
* | ||
* @param cryptoSettings Settings needed for creating crypto client. | ||
* @param keyProviderName Name of the key provider. | ||
* @return instance of CryptoClient | ||
*/ | ||
CryptoClient create(Settings cryptoSettings, String keyProviderName); | ||
} | ||
|
||
/** | ||
* @return key provider type | ||
*/ | ||
String type(); | ||
|
||
/** | ||
* @return key provider name | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* To Initialise a crypto context used in encryption. This might be needed to set the context before beginning | ||
* encryption. | ||
* | ||
* @return crypto context instance | ||
*/ | ||
Object initCryptoContext(); | ||
|
||
/** | ||
* In scenarios where content is divided into multiple parts and streams are emitted against each part, | ||
* it is sometimes required to adjust the size of a part. | ||
* | ||
* @param cryptoContextObj crypto context instance | ||
* @param streamSize Size of the raw stream | ||
* @return Adjusted size of the stream. | ||
*/ | ||
long adjustStreamSize(Object cryptoContextObj, long streamSize); | ||
|
||
/** | ||
* Wraps a raw InputStream with encrypting stream | ||
* | ||
* @param cryptoContext created earlier to set the crypto context. | ||
* @param stream Raw InputStream to encrypt | ||
* @return encrypting stream wrapped around raw InputStream. | ||
*/ | ||
Stream createEncryptingStream(Object cryptoContext, Stream stream); | ||
|
||
/** | ||
* Provides encrypted stream for a raw stream emitted for a part of content. | ||
* | ||
* @param cryptoContextObj crypto context instance. | ||
* @param stream raw stream for which encrypted stream has to be created. | ||
* @param totalStreams Number of streams being used for the entire content. | ||
* @param streamIdx Index of the current stream. | ||
* @return Encrypted stream for the provided raw stream. | ||
*/ | ||
Stream createEncryptingStreamOfPart(Object cryptoContextObj, Stream stream, int totalStreams, int streamIdx); | ||
|
||
/** | ||
* This method accepts an encrypted stream and provides a decrypting wrapper. | ||
* @param encryptingStream to be decrypted. | ||
* @return Decrypting wrapper stream | ||
*/ | ||
InputStream createDecryptingStream(InputStream encryptingStream); | ||
} |
12 changes: 12 additions & 0 deletions
12
server/src/main/java/org/opensearch/crypto/package-info.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,12 @@ | ||
/* | ||
* 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 for crypto client abstractions and exceptions. | ||
*/ | ||
package org.opensearch.crypto; |
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.