Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/util/AbstractAlgorithmConstraints.java
38830 views
1
/*
2
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.security.util;
27
28
import java.security.AccessController;
29
import java.security.AlgorithmConstraints;
30
import java.security.PrivilegedAction;
31
import java.security.Security;
32
import java.util.ArrayList;
33
import java.util.Arrays;
34
import java.util.Collections;
35
import java.util.List;
36
import java.util.Set;
37
38
/**
39
* The class contains common functionality for algorithm constraints classes.
40
*/
41
public abstract class AbstractAlgorithmConstraints
42
implements AlgorithmConstraints {
43
44
protected final AlgorithmDecomposer decomposer;
45
46
protected AbstractAlgorithmConstraints(AlgorithmDecomposer decomposer) {
47
this.decomposer = decomposer;
48
}
49
50
// Get algorithm constraints from the specified security property.
51
static List<String> getAlgorithms(String propertyName) {
52
String property = AccessController.doPrivileged(
53
new PrivilegedAction<String>() {
54
@Override
55
public String run() {
56
return Security.getProperty(propertyName);
57
}
58
});
59
60
String[] algorithmsInProperty = null;
61
if (property != null && !property.isEmpty()) {
62
// remove double quote marks from beginning/end of the property
63
if (property.length() >= 2 && property.charAt(0) == '"' &&
64
property.charAt(property.length() - 1) == '"') {
65
property = property.substring(1, property.length() - 1);
66
}
67
algorithmsInProperty = property.split(",");
68
for (int i = 0; i < algorithmsInProperty.length; i++) {
69
algorithmsInProperty[i] = algorithmsInProperty[i].trim();
70
}
71
}
72
73
// map the disabled algorithms
74
if (algorithmsInProperty == null) {
75
return Collections.emptyList();
76
}
77
return new ArrayList<>(Arrays.asList(algorithmsInProperty));
78
}
79
80
static boolean checkAlgorithm(List<String> algorithms, String algorithm,
81
AlgorithmDecomposer decomposer) {
82
if (algorithm == null || algorithm.length() == 0) {
83
throw new IllegalArgumentException("No algorithm name specified");
84
}
85
86
Set<String> elements = null;
87
for (String item : algorithms) {
88
if (item == null || item.isEmpty()) {
89
continue;
90
}
91
92
// check the full name
93
if (item.equalsIgnoreCase(algorithm)) {
94
return false;
95
}
96
97
// decompose the algorithm into sub-elements
98
if (elements == null) {
99
elements = decomposer.decompose(algorithm);
100
}
101
102
// check the items of the algorithm
103
for (String element : elements) {
104
if (item.equalsIgnoreCase(element)) {
105
return false;
106
}
107
}
108
}
109
110
return true;
111
}
112
113
}
114
115