8136410: AlgorithmDecomposer is not parsing padding correctly
Reviewed-by: weijun
This commit is contained in:
parent
7d2c07c70d
commit
e03cf9daf6
@ -35,8 +35,10 @@ import java.util.regex.Pattern;
|
||||
public class AlgorithmDecomposer {
|
||||
|
||||
private static final Pattern transPattern = Pattern.compile("/");
|
||||
|
||||
// '(?<!padd)in': match 'in' but not preceded with 'padd'.
|
||||
private static final Pattern pattern =
|
||||
Pattern.compile("with|and|in", Pattern.CASE_INSENSITIVE);
|
||||
Pattern.compile("with|and|(?<!padd)in", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
/**
|
||||
* Decompose the standard algorithm name into sub-elements.
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8136410
|
||||
* @summary AlgorithmDecomposer is not parsing padding correctly
|
||||
* @modules java.base/sun.security.util
|
||||
*/
|
||||
|
||||
import sun.security.util.AlgorithmDecomposer;
|
||||
import java.util.Set;
|
||||
|
||||
public class DecomposeAlgorithms {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
AlgorithmDecomposer decomposer = new AlgorithmDecomposer();
|
||||
|
||||
check(decomposer, "AES/CBC/NoPadding", new String[] {
|
||||
"AES", "CBC", "NoPadding"});
|
||||
check(decomposer, "DES/CBC/PKCS5Padding", new String[] {
|
||||
"DES", "CBC", "PKCS5Padding"});
|
||||
check(decomposer, "RSA/ECB/OAEPWithSHA-1AndMGF1Padding", new String[] {
|
||||
"RSA", "ECB", "OAEP", "SHA1", "SHA-1", "MGF1Padding"});
|
||||
check(decomposer, "OAEPWithSHA-512AndMGF1Padding", new String[] {
|
||||
"OAEP", "SHA512", "SHA-512", "MGF1Padding"});
|
||||
check(decomposer, "OAEPWithSHA-512AndMGF1Padding", new String[] {
|
||||
"OAEP", "SHA512", "SHA-512", "MGF1Padding"});
|
||||
check(decomposer, "PBEWithSHA1AndRC2_40", new String[] {
|
||||
"PBE", "SHA1", "SHA-1", "RC2_40"});
|
||||
check(decomposer, "PBEWithHmacSHA224AndAES_128", new String[] {
|
||||
"PBE", "HmacSHA224", "AES_128"});
|
||||
}
|
||||
|
||||
private static void check(AlgorithmDecomposer parser,
|
||||
String fullAlgName, String[] components) throws Exception {
|
||||
|
||||
Set<String> parsed = parser.decompose(fullAlgName);
|
||||
if (parsed.size() != components.length) {
|
||||
throw new Exception("Not expected components number: " + parsed);
|
||||
}
|
||||
|
||||
for (String component : components) {
|
||||
if (!parsed.contains(component)) {
|
||||
throw new Exception("Not a expected component: " + component);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("OK: " + fullAlgName);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user