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;
33 import org.onap.clamp.clds.util.ResourceFileUtils;
34 import org.onap.clamp.util.PassDecoder;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.autoconfigure.web.ServerProperties;
37 import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
38 import org.springframework.boot.web.server.Ssl;
39 import org.springframework.boot.web.server.SslStoreProvider;
40 import org.springframework.boot.web.server.WebServerFactoryCustomizer;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Configuration;
43 import org.springframework.context.annotation.Profile;
44 import org.springframework.core.env.Environment;
45 import org.springframework.core.io.ResourceLoader;
48 @Profile("clamp-ssl-config")
49 public class SslConfig {
51 private Environment env;
54 WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer(ServerProperties serverProperties,
55 ResourceLoader resourceLoader) {
56 return (tomcat) -> tomcat.setSslStoreProvider(new SslStoreProvider() {
58 public KeyStore getKeyStore() throws KeyStoreException,
59 NoSuchAlgorithmException, CertificateException, IOException {
60 KeyStore keystore = KeyStore.getInstance(env.getProperty("server.ssl.key-store-type"));
61 String password = PassDecoder.decode(env.getProperty("server.ssl.key-store-password"),
62 env.getProperty("clamp.config.keyFile"));
63 keystore.load(ResourceFileUtils.getResourceAsStream(env.getProperty("server.ssl.key-store")),
64 password.toCharArray());
69 public KeyStore getTrustStore() throws KeyStoreException,
70 NoSuchAlgorithmException, CertificateException, IOException {
71 KeyStore truststore = KeyStore.getInstance("JKS");
72 String password = PassDecoder.decode(env.getProperty("server.ssl.trust-store-password"),
73 env.getProperty("clamp.config.keyFile"));
75 ResourceFileUtils.getResourceAsStream(env.getProperty("server.ssl.trust-store")),
76 password.toCharArray());
83 WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatSslCustomizer(ServerProperties serverProperties,
84 ResourceLoader resourceLoader) {
85 return (tomcat) -> tomcat.setSsl(new Ssl() {
87 public String getKeyPassword() {
88 String password = PassDecoder.decode(env.getProperty("server.ssl.key-password"),
89 env.getProperty("clamp.config.keyFile"));