2 * Copyright © 2018-2019 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service
19 import io.grpc.netty.GrpcSslContexts
20 import io.grpc.netty.NettyServerBuilder
21 import io.netty.handler.ssl.ClientAuth
22 import io.netty.handler.ssl.SslContext
23 import io.netty.handler.ssl.SslContextBuilder
24 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TLSAuthGrpcServerProperties
25 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
27 class TLSAuthGrpcServerService(private val tlsAuthGrpcServerProperties: TLSAuthGrpcServerProperties) :
28 BluePrintGrpcServerService {
30 override fun serverBuilder(): NettyServerBuilder {
31 return NettyServerBuilder
32 .forPort(tlsAuthGrpcServerProperties.port)
33 .sslContext(sslContext())
36 fun sslContext(): SslContext {
37 val sslClientContextBuilder = SslContextBuilder
39 normalizedFile(tlsAuthGrpcServerProperties.certChain),
40 normalizedFile(tlsAuthGrpcServerProperties.privateKey)
43 tlsAuthGrpcServerProperties.trustCertCollection?.let { trustCertFile ->
44 sslClientContextBuilder.trustManager(normalizedFile(trustCertFile))
45 sslClientContextBuilder.clientAuth(ClientAuth.REQUIRE)
47 return GrpcSslContexts.configure(sslClientContextBuilder).build()