-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Splits Elastic module into elastic-common and elastic8
* Adding Opensearch module * Adding Opensearch unit tests * Opensearch SSL Test - needs completing * Replace Elastic6+7 with Elastic8
- Loading branch information
1 parent
9b634a8
commit 5832ac9
Showing
124 changed files
with
3,019 additions
and
3,977 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
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
98 changes: 98 additions & 0 deletions
98
...ra/src/main/scala/io/lenses/streamreactor/connect/cassandra/config/SSLConfigContext.scala
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,98 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.lenses.streamreactor.connect.cassandra.config | ||
|
||
import java.io.FileInputStream | ||
import java.security.KeyStore | ||
import java.security.SecureRandom | ||
import javax.net.ssl._ | ||
|
||
/** | ||
* Created by [email protected] on 14/04/16. | ||
* stream-reactor | ||
*/ | ||
object SSLConfigContext { | ||
def apply(config: SSLConfig): SSLContext = | ||
getSSLContext(config) | ||
|
||
/** | ||
* Get a SSL Connect for a given set of credentials | ||
* | ||
* @param config An SSLConfig containing key and truststore credentials | ||
* @return a SSLContext | ||
*/ | ||
def getSSLContext(config: SSLConfig): SSLContext = { | ||
val useClientCertAuth = config.useClientCert | ||
|
||
//is client certification authentication set | ||
val keyManagers: Array[KeyManager] = if (useClientCertAuth) { | ||
getKeyManagers(config) | ||
} else { | ||
Array[KeyManager]() | ||
} | ||
|
||
val ctx: SSLContext = SSLContext.getInstance("SSL") | ||
val trustManagers = getTrustManagers(config) | ||
ctx.init(keyManagers, trustManagers, new SecureRandom()) | ||
ctx | ||
} | ||
|
||
/** | ||
* Get an array of Trust Managers | ||
* | ||
* @param config An SSLConfig containing key and truststore credentials | ||
* @return An Array of TrustManagers | ||
*/ | ||
def getTrustManagers(config: SSLConfig): Array[TrustManager] = { | ||
val tsf = new FileInputStream(config.trustStorePath) | ||
val ts = KeyStore.getInstance(config.trustStoreType) | ||
ts.load(tsf, config.trustStorePass.toCharArray) | ||
val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm) | ||
tmf.init(ts) | ||
tmf.getTrustManagers | ||
} | ||
|
||
/** | ||
* Get an array of Key Managers | ||
* | ||
* @param config An SSLConfig containing key and truststore credentials | ||
* @return An Array of KeyManagers | ||
*/ | ||
def getKeyManagers(config: SSLConfig): Array[KeyManager] = { | ||
require(config.keyStorePath.nonEmpty, "Key store path is not set!") | ||
require(config.keyStorePass.nonEmpty, "Key store password is not set!") | ||
val ksf = new FileInputStream(config.keyStorePath.get) | ||
val ks = KeyStore.getInstance(config.keyStoreType) | ||
ks.load(ksf, config.keyStorePass.get.toCharArray) | ||
val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm) | ||
kmf.init(ks, config.keyStorePass.get.toCharArray) | ||
kmf.getKeyManagers | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Class for holding key and truststore settings | ||
*/ | ||
case class SSLConfig( | ||
trustStorePath: String, | ||
trustStorePass: String, | ||
keyStorePath: Option[String], | ||
keyStorePass: Option[String], | ||
useClientCert: Boolean = false, | ||
keyStoreType: String = "JKS", | ||
trustStoreType: String = "JKS", | ||
) |
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
64 changes: 64 additions & 0 deletions
64
...rc/test/scala/io/lenses/streamreactor/connect/cassandra/config/TestSSLConfigContext.scala
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,64 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.lenses.streamreactor.connect.cassandra.config | ||
|
||
import org.scalatest.BeforeAndAfter | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
import javax.net.ssl.KeyManager | ||
import javax.net.ssl.SSLContext | ||
import javax.net.ssl.TrustManager | ||
|
||
/** | ||
* Created by [email protected] on 19/04/16. | ||
* stream-reactor | ||
*/ | ||
class TestSSLConfigContext extends AnyWordSpec with Matchers with BeforeAndAfter { | ||
var sslConfig: SSLConfig = null | ||
var sslConfigNoClient: SSLConfig = null | ||
|
||
before { | ||
val trustStorePath = getClass.getResource("/stc_truststore.jks").getPath | ||
val keystorePath = getClass.getResource("/stc_keystore.jks").getPath | ||
val trustStorePassword = "erZHDS9Eo0CcNo" | ||
val keystorePassword = "8yJQLUnGkwZxOw" | ||
sslConfig = SSLConfig(trustStorePath, trustStorePassword, Some(keystorePath), Some(keystorePassword), true) | ||
sslConfigNoClient = SSLConfig(trustStorePath, trustStorePassword, Some(keystorePath), Some(keystorePassword), false) | ||
} | ||
|
||
"SSLConfigContext" should { | ||
"should return an Array of KeyManagers" in { | ||
val keyManagers = SSLConfigContext.getKeyManagers(sslConfig) | ||
keyManagers.length shouldBe 1 | ||
val entry = keyManagers.head | ||
entry shouldBe a[KeyManager] | ||
} | ||
|
||
"should return an Array of TrustManagers" in { | ||
val trustManager = SSLConfigContext.getTrustManagers(sslConfig) | ||
trustManager.length shouldBe 1 | ||
val entry = trustManager.head | ||
entry shouldBe a[TrustManager] | ||
} | ||
|
||
"should return a SSLContext" in { | ||
val context = SSLConfigContext(sslConfig) | ||
context.getProtocol shouldBe "SSL" | ||
context shouldBe a[SSLContext] | ||
} | ||
} | ||
} |
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.