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