2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.config;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.security.KeyStore;
29 import java.security.KeyStoreException;
30 import java.security.NoSuchAlgorithmException;
31 import java.security.cert.CertificateException;
32 import org.onap.clamp.clds.util.ResourceFileUtils;
33 import org.onap.clamp.util.PassDecoder;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.boot.autoconfigure.web.ServerProperties;
36 import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
37 import org.springframework.boot.web.server.Ssl;
38 import org.springframework.boot.web.server.SslStoreProvider;
39 import org.springframework.boot.web.server.WebServerFactoryCustomizer;
40 import org.springframework.context.annotation.Bean;
41 import org.springframework.context.annotation.Configuration;
42 import org.springframework.context.annotation.Profile;
43 import org.springframework.core.env.Environment;
44 import org.springframework.core.io.ResourceLoader;
47 @Profile("clamp-ssl-config")
48 public class SslConfig {
50 private Environment env;
53 WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer(ServerProperties serverProperties,
54 ResourceLoader resourceLoader) {
55 return (tomcat) -> tomcat.setSslStoreProvider(new SslStoreProvider() {
57 public KeyStore getKeyStore() throws KeyStoreException,
58 NoSuchAlgorithmException, CertificateException, IOException {
59 KeyStore keystore = KeyStore.getInstance(env.getProperty("server.ssl.key-store-type"));
60 String password = PassDecoder.decode(env.getProperty("server.ssl.key-store-password"),
61 env.getProperty("clamp.config.keyFile"));
62 keystore.load(ResourceFileUtils.getResourceAsStream(env.getProperty("server.ssl.key-store")),
63 password.toCharArray());
68 public KeyStore getTrustStore() throws KeyStoreException,
69 NoSuchAlgorithmException, CertificateException, IOException {
70 KeyStore truststore = KeyStore.getInstance("JKS");
71 String password = PassDecoder.decode(env.getProperty("server.ssl.trust-store-password"),
72 env.getProperty("clamp.config.keyFile"));
74 ResourceFileUtils.getResourceAsStream(env.getProperty("server.ssl.trust-store")),
75 password.toCharArray());
82 WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatSslCustomizer(ServerProperties serverProperties,
83 ResourceLoader resourceLoader) {
84 return (tomcat) -> tomcat.setSsl(new Ssl() {
86 public String getKeyPassword() {
87 String password = PassDecoder.decode(env.getProperty("server.ssl.key-password"),
88 env.getProperty("clamp.config.keyFile"));