Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/util/AbstractAlgorithmConstraints.java
38830 views
/*1* Copyright (c) 2015, 2019, 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 sun.security.util;2627import java.security.AccessController;28import java.security.AlgorithmConstraints;29import java.security.PrivilegedAction;30import java.security.Security;31import java.util.ArrayList;32import java.util.Arrays;33import java.util.Collections;34import java.util.List;35import java.util.Set;3637/**38* The class contains common functionality for algorithm constraints classes.39*/40public abstract class AbstractAlgorithmConstraints41implements AlgorithmConstraints {4243protected final AlgorithmDecomposer decomposer;4445protected AbstractAlgorithmConstraints(AlgorithmDecomposer decomposer) {46this.decomposer = decomposer;47}4849// Get algorithm constraints from the specified security property.50static List<String> getAlgorithms(String propertyName) {51String property = AccessController.doPrivileged(52new PrivilegedAction<String>() {53@Override54public String run() {55return Security.getProperty(propertyName);56}57});5859String[] algorithmsInProperty = null;60if (property != null && !property.isEmpty()) {61// remove double quote marks from beginning/end of the property62if (property.length() >= 2 && property.charAt(0) == '"' &&63property.charAt(property.length() - 1) == '"') {64property = property.substring(1, property.length() - 1);65}66algorithmsInProperty = property.split(",");67for (int i = 0; i < algorithmsInProperty.length; i++) {68algorithmsInProperty[i] = algorithmsInProperty[i].trim();69}70}7172// map the disabled algorithms73if (algorithmsInProperty == null) {74return Collections.emptyList();75}76return new ArrayList<>(Arrays.asList(algorithmsInProperty));77}7879static boolean checkAlgorithm(List<String> algorithms, String algorithm,80AlgorithmDecomposer decomposer) {81if (algorithm == null || algorithm.length() == 0) {82throw new IllegalArgumentException("No algorithm name specified");83}8485Set<String> elements = null;86for (String item : algorithms) {87if (item == null || item.isEmpty()) {88continue;89}9091// check the full name92if (item.equalsIgnoreCase(algorithm)) {93return false;94}9596// decompose the algorithm into sub-elements97if (elements == null) {98elements = decomposer.decompose(algorithm);99}100101// check the items of the algorithm102for (String element : elements) {103if (item.equalsIgnoreCase(element)) {104return false;105}106}107}108109return true;110}111112}113114115