2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
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=========================================================
21 package org.onap.aai.restcore;
23 import org.apache.commons.cli.CommandLine;
24 import org.apache.commons.cli.CommandLineParser;
25 import org.apache.commons.cli.DefaultParser;
26 import org.apache.commons.cli.Options;
27 import org.apache.commons.cli.ParseException;
28 import org.eclipse.jetty.util.security.Password;
31 * The purpose of this class is to be a tool for
32 * manually applying jetty obfuscation/deobfuscation
33 * so that one can obfuscate the various passwords/secrets
34 * in aaiconfig.properties.
36 * Originally, they were being encrypted by a similar
37 * command line utility, however the encryption key
38 * was being hardcoded in the src package
39 * which is a security violation.
40 * Since this ultimately just moved the problem of how
41 * to hide secrets to a different secret in a different file,
42 * and since that encryption was really just being done to
43 * obfuscate those values in case someone needed to look at
44 * properties with others looking at their screen,
45 * we decided that jetty obfuscation would be adequate
46 * for that task as well as
47 * removing the "turtles all the way down" secret-to-hide-
48 * the-secret-to-hide-the-secret problem.
50 public class JettyObfuscationConversionCommandLineUtil {
55 * @param args the arguments
57 public static void main(String[] args) {
58 Options options = new Options();
59 options.addOption("e", true, "obfuscate the given string");
60 options.addOption("d", true, "deobfuscate the given string");
62 CommandLineParser parser = new DefaultParser();
65 CommandLine cmd = parser.parse(options, args);
66 String toProcess = null;
68 if (cmd.hasOption("e")) {
69 toProcess = cmd.getOptionValue("e");
70 String encoded = Password.obfuscate(toProcess);
71 System.out.println(encoded);
72 } else if (cmd.hasOption("d")) {
73 toProcess = cmd.getOptionValue("d");
74 String decoded_str = Password.deobfuscate(toProcess);
75 System.out.println(decoded_str);
79 } catch (ParseException e) {
80 System.out.println("failed to parse input");
81 System.out.println(e.toString());
83 } catch (Exception e) {
84 System.out.println("exception:" + e.toString());
91 private static void usage() {
92 System.out.println("usage:");
93 System.out.println("-e [string] to obfuscate");
94 System.out.println("-d [string] to deobfuscate");
95 System.out.println("-h help");