1
1
package com .avast .sst .ssl
2
2
3
3
import cats .effect .Sync
4
- import com .typesafe .config .Config
4
+ import com .typesafe .config .{ Config , ConfigFactory }
5
5
import com .typesafe .sslconfig .ssl .{
6
6
ConfigSSLContextBuilder ,
7
7
DefaultKeyManagerFactoryWrapper ,
@@ -14,13 +14,19 @@ import scala.language.higherKinds
14
14
15
15
object SslContextModule {
16
16
17
- /** Initializes [[javax.net.ssl.SSLContext ]] from the provided config. */
18
- def make [F [_]: Sync ](config : Config ): F [SSLContext ] = Sync [F ].delay {
17
+ /**
18
+ * Initializes [[javax.net.ssl.SSLContext ]] from the provided config.
19
+ * @param withReference Whether we should use reference config of "ssl-config" library as well.
20
+ */
21
+ def make [F [_]: Sync ](config : Config , withReference : Boolean = true ): F [SSLContext ] = Sync [F ].delay {
19
22
val loggerFactory = Slf4jLogger .factory
23
+ val finalConfig = if (withReference) config.withFallback(referenceConfigUnsafe()) else config
20
24
new ConfigSSLContextBuilder (loggerFactory,
21
- SSLConfigFactory .parse(config , loggerFactory),
25
+ SSLConfigFactory .parse(finalConfig , loggerFactory),
22
26
new DefaultKeyManagerFactoryWrapper (KeyManagerFactory .getDefaultAlgorithm),
23
27
new DefaultTrustManagerFactoryWrapper (TrustManagerFactory .getDefaultAlgorithm)).build
24
28
}
25
29
30
+ private def referenceConfigUnsafe (): Config = ConfigFactory .defaultReference().getConfig(" ssl-config" )
31
+
26
32
}
0 commit comments