From db75c0a0b305c86429a6940de4d56870d3daf5bf Mon Sep 17 00:00:00 2001 From: Skip Wonnell Date: Tue, 15 Aug 2017 12:43:03 -0500 Subject: Initial commit for appc-encryption-tool bundle appc-encryption-tool: module to retrieve and store encryped credentials Change-Id: I3d45c662c9d58dbeec2ab7fffb51658c9ee0d5d3 Signed-off-by: Skip Wonnell Issue-Id: APPC-67 --- appc-config/appc-encryption-tool/.gitignore | 1 + .../appc-encryption-tool/features/.gitignore | 1 + appc-config/appc-encryption-tool/features/pom.xml | 94 +++++++++ .../features/src/main/resources/features.xml | 49 +++++ appc-config/appc-encryption-tool/installer/pom.xml | 148 ++++++++++++++ .../src/assembly/assemble_installer_zip.xml | 59 ++++++ .../src/assembly/assemble_mvnrepo_zip.xml | 47 +++++ .../src/main/resources/scripts/install-feature.sh | 40 ++++ appc-config/appc-encryption-tool/pom.xml | 47 +++++ .../appc-encryption-tool/provider/.gitignore | 1 + .../provider/appc_southbound.properties | 4 + appc-config/appc-encryption-tool/provider/pom.xml | 80 ++++++++ .../encryptiontool/EncryptionToolActivator.java | 55 ++++++ .../appc/encryptiontool/wrapper/Constants.java | 33 ++++ .../appc/encryptiontool/wrapper/DbServiceUtil.java | 72 +++++++ .../encryptiontool/wrapper/EncryptionTool.java | 214 +++++++++++++++++++++ .../wrapper/EncryptionToolDGWrapper.java | 80 ++++++++ .../wrapper/WrapperEncryptionTool.java | 142 ++++++++++++++ .../appc/encryptiontool/TestEncryptionTool.java | 65 +++++++ .../src/test/resources/svclogic.properties | 33 ++++ appc-config/pom.xml | 3 +- 21 files changed, 1267 insertions(+), 1 deletion(-) create mode 100644 appc-config/appc-encryption-tool/.gitignore create mode 100644 appc-config/appc-encryption-tool/features/.gitignore create mode 100644 appc-config/appc-encryption-tool/features/pom.xml create mode 100644 appc-config/appc-encryption-tool/features/src/main/resources/features.xml create mode 100644 appc-config/appc-encryption-tool/installer/pom.xml create mode 100644 appc-config/appc-encryption-tool/installer/src/assembly/assemble_installer_zip.xml create mode 100644 appc-config/appc-encryption-tool/installer/src/assembly/assemble_mvnrepo_zip.xml create mode 100644 appc-config/appc-encryption-tool/installer/src/main/resources/scripts/install-feature.sh create mode 100644 appc-config/appc-encryption-tool/pom.xml create mode 100644 appc-config/appc-encryption-tool/provider/.gitignore create mode 100644 appc-config/appc-encryption-tool/provider/appc_southbound.properties create mode 100644 appc-config/appc-encryption-tool/provider/pom.xml create mode 100644 appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/EncryptionToolActivator.java create mode 100644 appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/Constants.java create mode 100644 appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/DbServiceUtil.java create mode 100644 appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/EncryptionTool.java create mode 100644 appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java create mode 100644 appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/WrapperEncryptionTool.java create mode 100644 appc-config/appc-encryption-tool/provider/src/test/java/org/openecomp/appc/encryptiontool/TestEncryptionTool.java create mode 100644 appc-config/appc-encryption-tool/provider/src/test/resources/svclogic.properties diff --git a/appc-config/appc-encryption-tool/.gitignore b/appc-config/appc-encryption-tool/.gitignore new file mode 100644 index 000000000..b83d22266 --- /dev/null +++ b/appc-config/appc-encryption-tool/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/appc-config/appc-encryption-tool/features/.gitignore b/appc-config/appc-encryption-tool/features/.gitignore new file mode 100644 index 000000000..b83d22266 --- /dev/null +++ b/appc-config/appc-encryption-tool/features/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/appc-config/appc-encryption-tool/features/pom.xml b/appc-config/appc-encryption-tool/features/pom.xml new file mode 100644 index 000000000..581517444 --- /dev/null +++ b/appc-config/appc-encryption-tool/features/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + + org.openecomp.appc + appc-config-encryption-tool + 1.1.0-SNAPSHOT + + appc-config-encryption-tool-features + APPC Encryption Tool Plugin - Features + jar + + + org.openecomp.appc + appc-config-encryption-tool-provider + ${project.version} + + + commons-lang + commons-lang + 2.6 + compile + + + org.opendaylight.mdsal + features-mdsal + ${odl.mdsal.version} + features + xml + runtime + + + + org.opendaylight.controller + opendaylight-karaf-empty + ${odl.karaf.empty.distro.version} + zip + + + + org.opendaylight.odlparent + features-test + ${odl.commons.opendaylight.version} + test + + + + + + + true + src/main/resources + + + + + org.apache.maven.plugins + maven-resources-plugin + + + filter + + resources + + generate-resources + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/${features.file} + xml + features + + + + + + + + + diff --git a/appc-config/appc-encryption-tool/features/src/main/resources/features.xml b/appc-config/appc-encryption-tool/features/src/main/resources/features.xml new file mode 100644 index 000000000..ddb1a8526 --- /dev/null +++ b/appc-config/appc-encryption-tool/features/src/main/resources/features.xml @@ -0,0 +1,49 @@ + + + + + + + mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.version}/xml/features + + + + odl-mdsal-broker + + sdnc-dblib + sdnc-sli + sdnc-sql-resource + + mvn:commons-lang/commons-lang/2.6 + mvn:org.apache.velocity/velocity/${velocity.version} + mvn:commons-collections/commons-collections/${common.collections.version} + wrap:mvn:commons-configuration/commons-configuration/1.10 + wrap:mvn:org.jasypt/jasypt/1.9.2 + mvn:mysql/mysql-connector-java/${mysql.connector.version} + wrap:mvn:com.att.eelf/eelf-core/${eelf.version} + mvn:ch.qos.logback/logback-core/${logback.version} + mvn:ch.qos.logback/logback-classic/${logback.version} + mvn:org.openecomp.appc/appc-config-encryption-tool-provider/${project.version} + + diff --git a/appc-config/appc-encryption-tool/installer/pom.xml b/appc-config/appc-encryption-tool/installer/pom.xml new file mode 100644 index 000000000..03e483e78 --- /dev/null +++ b/appc-config/appc-encryption-tool/installer/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + + org.openecomp.appc + appc-config-encryption-tool + 1.1.0-SNAPSHOT + + + appc-config-encryption-tool-installer + Config Component Encryption Tool - Installer + pom + + appc-config-encryption-tool + appc-config-encryption-tool + mvn:org.openecomp.appc/appc-config-encryption-tool-features/${project.version}/xml/features + false + + + + org.openecomp.appc + appc-config-encryption-tool-features + features + xml + + + * + * + + + + + org.openecomp.appc + appc-config-encryption-tool-provider + 1.1.0-SNAPSHOT + + + + + + maven-assembly-plugin + + + maven-repo-zip + + single + + package + + false + false + stage/${application.name}-${project.version} + + src/assembly/assemble_mvnrepo_zip.xml + + + + + installer-zip + + single + + package + + false + true + ${application.name}-${project.version} + + src/assembly/assemble_installer_zip.xml + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/system + false + true + true + true + false + false + org.opendaylight + provided + + + + + + maven-resources-plugin + + + copy-version + + copy-resources + + + validate + + ${basedir}/target/stage + + + src/main/resources/scripts + + install-feature.sh + + true + + + + + + + + + diff --git a/appc-config/appc-encryption-tool/installer/src/assembly/assemble_installer_zip.xml b/appc-config/appc-encryption-tool/installer/src/assembly/assemble_installer_zip.xml new file mode 100644 index 000000000..3b8fe894a --- /dev/null +++ b/appc-config/appc-encryption-tool/installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,59 @@ + + + + + + encryption-tool + + zip + + + + false + + + + target/stage/ + ${application.name} + 755 + + *.sh + + + + target/stage/ + ${application.name} + 644 + + *.sh + + + + + + + diff --git a/appc-config/appc-encryption-tool/installer/src/assembly/assemble_mvnrepo_zip.xml b/appc-config/appc-encryption-tool/installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100644 index 000000000..98e1b9a9d --- /dev/null +++ b/appc-config/appc-encryption-tool/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,47 @@ + + + + + + encryption-tool + + zip + + + + false + + + + target/assembly/ + . + + + + + + diff --git a/appc-config/appc-encryption-tool/installer/src/main/resources/scripts/install-feature.sh b/appc-config/appc-encryption-tool/installer/src/main/resources/scripts/install-feature.sh new file mode 100644 index 000000000..b8e924279 --- /dev/null +++ b/appc-config/appc-encryption-tool/installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,40 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APP-C +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +### + +#!/bin/bash + +ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} +ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} +ODL_KARAF_CLIENT_OPTS=${ODL_KARAF_CLIENT_OPTS:-"-u karaf"} +INSTALLERDIR=$(dirname $0) + +REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip + +if [ -f ${REPOZIP} ] +then + unzip -n -d ${ODL_HOME} ${REPOZIP} +else + echo "ERROR : repo zip ($REPOZIP) not found" + exit 1 +fi + +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:repo-add ${features.repositories} +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:install ${features.boot} diff --git a/appc-config/appc-encryption-tool/pom.xml b/appc-config/appc-encryption-tool/pom.xml new file mode 100644 index 000000000..2e8e24419 --- /dev/null +++ b/appc-config/appc-encryption-tool/pom.xml @@ -0,0 +1,47 @@ + + + + org.openecomp.appc + appc-config + 1.1.0-SNAPSHOT + + + 4.0.0 + pom + appc-config-encryption-tool + + APPC Encryption Tool + Common Utilities for DG + + + ${sdnctl.sli.version} + UTF-8 + 5.1.39 + + + + + + org.openecomp.appc + appc-config-encryption-tool-features + features + xml + ${project.version} + + + + org.openecomp.appc + appc-config-encryption-tool-provider + ${project.version} + + + + + + provider + features + installer + + + diff --git a/appc-config/appc-encryption-tool/provider/.gitignore b/appc-config/appc-encryption-tool/provider/.gitignore new file mode 100644 index 000000000..b83d22266 --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/appc-config/appc-encryption-tool/provider/appc_southbound.properties b/appc-config/appc-encryption-tool/provider/appc_southbound.properties new file mode 100644 index 000000000..2ef508203 --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/appc_southbound.properties @@ -0,0 +1,4 @@ +testVnf_Type.testAction1.user = +testVnf_Type.testAction1.port = +testVnf_Type.testAction1.password = +testVnf_Type.testAction1.url = diff --git a/appc-config/appc-encryption-tool/provider/pom.xml b/appc-config/appc-encryption-tool/provider/pom.xml new file mode 100644 index 000000000..6c48ada8b --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + + org.openecomp.appc + appc-config-encryption-tool + 1.1.0-SNAPSHOT + + appc-config-encryption-tool-provider + bundle + APPC Encryption Tool - Provider + http://maven.apache.org + + UTF-8 + + + + equinoxSDK381 + org.eclipse.osgi + ${equinox.osgi.version} + + + org.openecomp.sdnc.core + sli-provider + + + org.openecomp.sdnc.adaptors + sql-resource-provider + + + commons-io + commons-io + + + org.jasypt + jasypt + 1.9.2 + compile + + + com.att.eelf + eelf-core + + + commons-configuration + commons-configuration + 1.10 + + + junit + junit + test + + + + + + org.apache.felix + maven-bundle-plugin + ${bundle.plugin.version} + true + + + org.openecomp.appc.encryptiontool + org.openecomp.appc.encryptiontool.EncryptionToolActivator + org.openecomp.appc.encryptiontool + * + * + + ${project.basedir}/src/main/resources/META-INF + + + + + + + + + diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/EncryptionToolActivator.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/EncryptionToolActivator.java new file mode 100644 index 000000000..002450114 --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/EncryptionToolActivator.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.encryptiontool; + +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.openecomp.appc.encryptiontool.wrapper.EncryptionToolDGWrapper; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class EncryptionToolActivator implements BundleActivator { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(EncryptionToolActivator.class); + private List registrations = new LinkedList(); + + @Override + public void start(BundleContext ctx) throws Exception { + EncryptionToolDGWrapper encryptionToolWrapper = new EncryptionToolDGWrapper(); + log.info("Registering service-- " + encryptionToolWrapper.getClass().getName()); + registrations.add(ctx.registerService(encryptionToolWrapper.getClass().getName(), encryptionToolWrapper, null)); + + } + + @Override + public void stop(BundleContext arg0) throws Exception { + for (ServiceRegistration registration : registrations) { + registration.unregister(); + registration = null; + } + } +} diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/Constants.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/Constants.java new file mode 100644 index 000000000..710b61a43 --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/Constants.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.encryptiontool.wrapper; + +public class Constants +{ + + public static final String DBLIB_SERVICE = "org.openecomp.sdnctl.sli.resource.dblib.DBResourceManager"; + public static final String DEVICE_AUTHENTICATION="DEVICE_AUTHENTICATION"; + public static final String SCHEMA_SDNCTL="SDNCTL"; + + private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; + + public static final String APPC_CONFIG_DIR="/opt/app/bvc/properties"; +} diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/DbServiceUtil.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/DbServiceUtil.java new file mode 100644 index 000000000..4f7630478 --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/DbServiceUtil.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.encryptiontool.wrapper; + +import java.io.File; +import java.net.URL; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Properties; + +import javax.sql.rowset.CachedRowSet; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.openecomp.sdnc.sli.resource.dblib.DBResourceManager; +import org.openecomp.sdnc.sli.resource.dblib.DbLibService; + +public class DbServiceUtil +{ + private static final Logger log = LoggerFactory + .getLogger(DbServiceUtil.class); + + private static Properties props; + private static DBResourceManager jdbcDataSource = null; + + public static boolean updateDB(String tableName, ArrayList inputArgs, + String scema, String whereClause, String setCluase) throws SQLException + { + String updatePasswordString = "update " + tableName + " set " + setCluase + " where " + whereClause ; + boolean result = jdbcDataSource.writeData(updatePasswordString, inputArgs,Constants.SCHEMA_SDNCTL); + return result; + } + + public static CachedRowSet getData(String tableName, ArrayList argList, String schema, + String getselectData, String getDataClasue ) throws SQLException + { + String selectQuery = "select " + getselectData + "from " + tableName + " where " + getDataClasue ; + CachedRowSet data = jdbcDataSource.getData(selectQuery, argList, schema); + return data; + } + + + public static DBResourceManager initDbLibService() throws Exception + { + props = new Properties(); + File file = new File("/opt/app/bvc/properties/dblib.properties"); + URL propURL = file.toURI().toURL(); + props.load(propURL.openStream()); + jdbcDataSource = DBResourceManager.create(props); + return jdbcDataSource; + } + +} diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/EncryptionTool.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/EncryptionTool.java new file mode 100644 index 000000000..3a1b25ffa --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/EncryptionTool.java @@ -0,0 +1,214 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.encryptiontool.wrapper; + +import java.security.Provider; +import java.security.Provider.Service; +import java.security.Security; + +import javax.crypto.Cipher; + +import org.jasypt.contrib.org.apache.commons.codec_1_3.binary.Base64; +import org.jasypt.util.text.BasicTextEncryptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class is used to encapsulate the encryption and decryption support in one place and to provide a utility to + * encrypt and decrypt data. + */ +public class EncryptionTool { + + /** + * This lock object is used ONLY if the singleton has not been set up. + */ + private static final Object lock = new Object(); + + /** + * The salt is used to initialize the PBE (password Based Encrpytion) algorithm. + */ + private static final byte[] DEFAULT_SALT = { + (byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c, (byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99 + }; + + /** + * The prefix we insert onto any data we encrypt so that we can tell if it is encrpyted later and therefore decrypt + * it + */ + @SuppressWarnings("nls") + public static final String ENCRYPTED_VALUE_PREFIX = "enc:"; + + /** + * The instance of the encryption utility object + */ + private static EncryptionTool instance = null; + + /** + * The iteration count used to initialize the PBE algorithm and to generate the key spec + */ + private static final int ITERATION_COUNT = 20; + + /** + * The logger for this class. + */ + private static final Logger LOG = LoggerFactory.getLogger(EncryptionTool.class); + + /** + * The secret passphrase (PBE) that we use to perform encryption and decryption. The algorithm we are using is a + * symmetrical cipher. + */ + private static char[] secret = { + 'C', '_', 'z', 'l', '!', 'K', '!', '4', '?', 'O', 'z', 'E', 'K', 'E', '>', 'U', 'R', '/', '%', 'Y', '\\', 'f', + 'b', '"', 'e', 'n', '{', '"', 'l', 'U', 'F', '+', 'E', '\'', 'R', 'T', 'p', '1', 'V', '4', 'l', 'a', '9', 'w', + 'v', '5', 'Z', '#', 'i', 'V', '"', 'd', 'l', '!', 'L', 'M', 'g', 'L', 'Q', '{', 'v', 'v', 'K', 'V' + }; + + /** + * The algorithm to encrypt and decrpyt data is "Password (or passphrase) Based Encryption with Message Digest #5 + * and the Data Encryption Standard", i.e., PBEWithMD5AndDES. + */ + @SuppressWarnings("nls") + private static final String SECURITY_ALGORITHM = "PBEWITHMD5AND256BITAES";// "PBEWithMD5AndDES"; + + /** + * The decryption cipher object + */ + private Cipher decryptCipher = null; + + /** + * The encryption cipher object + */ + private Cipher encryptCipher = null; + + private BasicTextEncryptor encryptor; + + /** + * Get an instance of the EncryptionTool + * + * @return The encryption tool to be used + */ + public static final EncryptionTool getInstance() { + if (instance == null) { + synchronized (lock) { + if (instance == null) { + instance = new EncryptionTool(); + } + } + } + return instance; + } + + /** + * Create the EncryptionTool instance + */ + @SuppressWarnings("nls") + private EncryptionTool() { + // encryptor = new BasicTextEncryptor(); + // encryptor.setPassword(secret.toString()); + String out = "Found the following security algorithms:"; + for (Provider p : Security.getProviders()) { + for (Service s : p.getServices()) { + String algo = s.getAlgorithm(); + out += + String.format("\n -Algorithm [ %s ] in provider [ %s ] and service [ %s ]", algo, p.getName(), + s.getClassName()); + } + } + LOG.debug(out); + } + + /** + * Decrypt the provided encrypted text + * + * @param cipherText + * THe cipher text to be decrypted. If the ciphertext is not encrypted, then it is returned as is. + * @return the clear test of the (possibly) encrypted value. The original value if the string is not encrypted. + */ + @SuppressWarnings("nls") + public synchronized String decrypt(String cipherText) { + if (isEncrypted(cipherText)) { + String encValue = cipherText.substring(ENCRYPTED_VALUE_PREFIX.length()); + // return encryptor.decrypt(encValue); + byte[] plainByte = Base64.decodeBase64(encValue.getBytes()); + byte[] decryptByte = xorWithSecret(plainByte); + return new String(decryptByte); + } else { + return cipherText; + } + + } + + /** + * Encrypt the provided clear text + * + * @param clearText + * The clear text to be encrypted + * @return the encrypted text. If the clear text is empty (null or zero length), then an empty string is returned. + * If the clear text is already encrypted, it is not encrypted again and is returned as is. Otherwise, the + * clear text is encrypted and returned. + */ + @SuppressWarnings("nls") + public synchronized String encrypt(String clearText) { + if (clearText != null) { + byte[] encByte = xorWithSecret(clearText.getBytes()); + String encryptedValue = new String(Base64.encodeBase64(encByte)); + return ENCRYPTED_VALUE_PREFIX + encryptedValue; + } else { + return null; + } + } + + /** + * Is a value encrypted? A value is considered to be encrypted if it begins with the + * {@linkplain #ENCRYPTED_VALUE_PREFIX encrypted value prefix}. + * + * @param value + * the value to check. + * @return true/false; + */ + private static boolean isEncrypted(final String value) { + return value != null && value.startsWith(ENCRYPTED_VALUE_PREFIX); + } + + /** + * XORs the input byte array with the secret key, padding 0x0 to the end of the secret key if the input is longer + * and returns a byte array the same size as input + * + * @param inp + * The byte array to be XORed with secret + * @return A byte array the same size as inp or null if input is null. + */ + private byte[] xorWithSecret(byte[] inp) { + if (inp == null) { + return null; + } + + byte[] secretBytes = new String(secret).getBytes(); + int size = inp.length; + + byte[] out = new byte[size]; + for (int i = 0; i < size; i++) { + out[i] = (byte) ((inp[i]) ^ (secretBytes[i % secretBytes.length])); + } + return out; + } + +} diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java new file mode 100644 index 000000000..3dde4e5c0 --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.encryptiontool.wrapper; + +import java.util.Map; + +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.commons.lang.StringUtils; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicException; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(EncryptionToolDGWrapper.class); + + public void runEncryption(Map inParams, SvcLogicContext ctx) throws SvcLogicException + { + String responsePrefix = inParams.get("prefix"); + String userName = inParams.get("userName"); + String password = inParams.get("password"); + String vnf_type = inParams.get("vnf_type"); + + try{ + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "" ; + if(StringUtils.isBlank(userName) || StringUtils.isBlank(password) || StringUtils.isBlank(vnf_type)){ + throw new Exception("username or Password is missing"); + } + + String [] input = new String[] {vnf_type,userName,password}; + WrapperEncryptionTool.main(input); + } + catch (Exception e) + { + throw new SvcLogicException(e.getMessage()); + } + + } + public void getProperty(Map inParams, SvcLogicContext ctx) throws SvcLogicException + { + String responsePrefix = inParams.get("prefix"); + String propertyName = inParams.get("propertyName"); + + try{ + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "" ; + PropertiesConfiguration conf = new PropertiesConfiguration(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties"); + conf.setBasePath(null); + EncryptionTool et = EncryptionTool.getInstance(); + + ctx.setAttribute(responsePrefix + "propertyName", et.decrypt(conf.getProperty(propertyName).toString())); + } + catch (Exception e) { + ctx.setAttribute(responsePrefix + "status", "failure"); + ctx.setAttribute(responsePrefix + "error-message", e.getMessage()); + e.printStackTrace(); + throw new SvcLogicException(e.getMessage()); + } + } +} diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/WrapperEncryptionTool.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/WrapperEncryptionTool.java new file mode 100644 index 000000000..aa86149aa --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/openecomp/appc/encryptiontool/wrapper/WrapperEncryptionTool.java @@ -0,0 +1,142 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.encryptiontool.wrapper; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Properties; + +import javax.sql.rowset.CachedRowSet; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.openecomp.sdnc.sli.resource.dblib.DBResourceManager; + +public class WrapperEncryptionTool { + + private static final Logger log = LoggerFactory + .getLogger(WrapperEncryptionTool.class); + + public static void main(String[] args) + { + int rowCount = 0; + String vnf_type=args[0]; + String user = args[1]; + String password = args[2]; + String action = args[3]; + String port = args[4]; + String url = args[5]; + + if("".equals(vnf_type)) + { + System.out.println("ERROR-VNF_TYPE can not be null"); + return; + } + if("".equals(user)) + { + System.out.println("ERROR-USER can not be null"); + return; + } + if("".equals(password)) + { + System.out.println("ERROR-PASSWORD can not be null"); + return; + } + + EncryptionTool encryptionTool = EncryptionTool.getInstance(); + String enPass = encryptionTool.encrypt(password); + + if(action != null && !action.isEmpty()){ + updateProperties(user,vnf_type , enPass, action, port, url); + return ; + } + + ArrayList argList = new ArrayList<>(); + argList.add(vnf_type); + argList.add(user); + String clause = " vnf_type = ? and user_name = ? "; + String setClause = " password = ? "; + String getselectData = " * "; + DBResourceManager dbResourceManager = null; + try + { + dbResourceManager = DbServiceUtil.initDbLibService(); + CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, + argList, Constants.SCHEMA_SDNCTL, getselectData,clause ); + while(data.next()) + { + rowCount ++; + } + if(rowCount == 0) + log.info("APPC-MESSAGE: ERROR - No record Found for VNF_TYPE: " + vnf_type + ", User " + user ); + else + { + argList.clear(); + argList.add(enPass); + argList.add(vnf_type); + argList.add(user); + DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, argList, + Constants.SCHEMA_SDNCTL, clause, setClause); + log.info("APPC-MESSAGE: Password Updated Successfully"); + } + } + catch (Exception e) + { + e.printStackTrace(); + log.info("APPC-MESSAGE:" + e.getMessage()); + } + finally + { + dbResourceManager.cleanUp(); + System.exit(0); + } + } + + private static void updateProperties(String user, String vnf_type, String password, + String action, String port, String url) { + + log.info("Received Inputs User:" + user + " vnf_type:" + vnf_type + " action:" + action ); + + String property = vnf_type + "." + action + "."; + + try { + PropertiesConfiguration conf = new PropertiesConfiguration(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties"); + conf.setProperty(property + "user", user); + if(port != null && !port.isEmpty() ) + conf.setProperty(property + "port", port); + if(password != null && !password.isEmpty() ) + conf.setProperty(property + "password", password); + if(url != null && !url.isEmpty() ) + conf.setProperty(property + "url", url); + + conf.save(); + + } + catch (Exception e ) { + e.printStackTrace(); + log.info("APPC-MESSAGE:" + e.getMessage()); + } + + } +} diff --git a/appc-config/appc-encryption-tool/provider/src/test/java/org/openecomp/appc/encryptiontool/TestEncryptionTool.java b/appc-config/appc-encryption-tool/provider/src/test/java/org/openecomp/appc/encryptiontool/TestEncryptionTool.java new file mode 100644 index 000000000..3811be34a --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/test/java/org/openecomp/appc/encryptiontool/TestEncryptionTool.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.encryptiontool; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.junit.Test; +import org.openecomp.appc.encryptiontool.wrapper.EncryptionToolDGWrapper; +import org.openecomp.appc.encryptiontool.wrapper.WrapperEncryptionTool; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class TestEncryptionTool { + + //@Test + public void testEncryptionTool() throws Exception{ + + String [] input = new String[] {"testVnf_Type","testUser","testPassword11", "testAction1", "8080", "http://localhost:8080/restconf/healthcheck"}; + WrapperEncryptionTool.main(input); + + } + //@Test + public void testgetPropertyDG() throws Exception{ + EncryptionToolDGWrapper encryptionToolDBWrapper = new EncryptionToolDGWrapper(); + SvcLogicContext ctx = new SvcLogicContext(); + Map inParams = new HashMap(); + + inParams.put("prefix", "test"); + inParams.put("propertyName", "testVnf_Type.testAction1.url"); + + encryptionToolDBWrapper.getProperty(inParams, ctx); + + System.out.println("propertyValue :" + ctx.getAttribute("test.propertyName")); + + System.out.println("All propertyValue :" + ctx.getAttributeKeySet()); + } + +} diff --git a/appc-config/appc-encryption-tool/provider/src/test/resources/svclogic.properties b/appc-config/appc-encryption-tool/provider/src/test/resources/svclogic.properties new file mode 100644 index 000000000..ba3e9b820 --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/test/resources/svclogic.properties @@ -0,0 +1,33 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APP-C +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +com.att.sdnctl.sli.dbtype= +com.att.sdnctl.sli.jdbc.hosts= +com.att.sdnctl.sli.jdbc.url= +com.att.sdnctl.sli.jdbc.database= +com.att.sdnctl.sli.jdbc.user= +com.att.sdnctl.sli.jdbc.password= +com.att.sdnctl.sli.jdbc.connection.name= + +com.att.sdnctl.sli.jdbc.connection.timeout= +com.att.sdnctl.sli.jdbc.request.timeout= +com.att.sdnctl.sli.jdbc.limit.init= +com.att.sdnctl.sli.jdbc.limit.min= +com.att.sdnctl.sli.jdbc.limit.max= diff --git a/appc-config/pom.xml b/appc-config/pom.xml index 93d2ca3d9..14c844d3c 100644 --- a/appc-config/pom.xml +++ b/appc-config/pom.xml @@ -23,7 +23,7 @@ 2.5 1.1.0 - 1.1.0 + 1.1.2 1.1.0 1.1.0 @@ -89,6 +89,7 @@ appc-config-params + appc-encryption-tool -- cgit 1.2.3-korg