Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/customizesecurityfile/CryptoLevel.java
32287 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package build.tools.customizesecurityfile;2627import java.io.*;2829/**30* Alters the crypto.policy security property31* if --enable-unlimited-crypto is enabled.32*/33public class CryptoLevel {3435private static final String PROP_NAME = "crypto.policy";3637public static void main(String[] args) throws Exception {38boolean fileModified = false;3940if (args.length < 3) {41System.err.println("Usage: java CryptoLevel" +42"[input java.security file name] " +43"[output java.security file name] " +44"[unlimited|limited]");45System.exit(1);46}47if (!args[2].equals("unlimited") && !args[2].equals("limited")) {48System.err.println("CryptoLevel error: Unexpected " +49"input: " + args[2]);50System.exit(1);51}5253try (FileReader fr = new FileReader(args[0]);54BufferedReader br = new BufferedReader(fr);55FileWriter fw = new FileWriter(args[1]);56BufferedWriter bw = new BufferedWriter(fw))57{58// parse the file line-by-line, looking for crypto.policy59String line = br.readLine();60while (line != null) {61if (line.startsWith('#' + PROP_NAME) ||62line.startsWith(PROP_NAME)) {63writeLine(bw, PROP_NAME + "=" + args[2]);64fileModified = true;65} else {66writeLine(bw, line);67}68line = br.readLine();69}70if (!fileModified) {71//no previous setting seen. Insert at end72writeLine(bw, PROP_NAME + "=" + args[2]);73}74bw.flush();75}76}7778private static void writeLine(BufferedWriter bw, String line)79throws IOException80{81bw.write(line);82bw.newLine();83}84}858687