2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.ssl.boundary
22 import arrow.core.None
23 import arrow.core.Option
24 import arrow.core.Some
26 import arrow.instances.option.monad.monad
27 import arrow.typeclasses.binding
28 import org.apache.commons.cli.CommandLine
29 import org.onap.dcae.collectors.veshv.domain.JdkKeys
30 import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
31 import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption
32 import org.onap.dcae.collectors.veshv.utils.commandline.hasOption
33 import org.onap.dcae.collectors.veshv.utils.commandline.stringValue
37 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
38 * @since September 2018
42 const val KEY_STORE_FILE = "/etc/ves-hv/server.p12"
43 const val TRUST_STORE_FILE = "/etc/ves-hv/trust.p12"
45 fun createSecurityConfiguration(cmdLine: CommandLine): Option<SecurityConfiguration> {
46 val sslDisable = cmdLine.hasOption(CommandLineOption.SSL_DISABLE)
48 return if (sslDisable) disabledSecurityConfiguration(sslDisable) else enabledSecurityConfiguration(cmdLine)
51 private fun disabledSecurityConfiguration(sslDisable: Boolean): Some<SecurityConfiguration> {
52 return Some(SecurityConfiguration(
53 sslDisable = sslDisable,
58 private fun enabledSecurityConfiguration(cmdLine: CommandLine): Option<SecurityConfiguration> {
59 return Option.monad().binding {
60 val ksFile = cmdLine.stringValue(CommandLineOption.KEY_STORE_FILE, KEY_STORE_FILE)
61 val ksPass = cmdLine.stringValue(CommandLineOption.KEY_STORE_PASSWORD).bind()
62 val tsFile = cmdLine.stringValue(CommandLineOption.TRUST_STORE_FILE, TRUST_STORE_FILE)
63 val tsPass = cmdLine.stringValue(CommandLineOption.TRUST_STORE_PASSWORD).bind()
66 keyStore = streamFromFile(ksFile),
67 keyStorePassword = ksPass.toCharArray(),
68 trustStore = streamFromFile(tsFile),
69 trustStorePassword = tsPass.toCharArray()
72 SecurityConfiguration(
79 private fun streamFromFile(file: String) = { File(file).inputStream() }