Path: blob/master/test/jdk/javax/crypto/CryptoPermission/LowercasePermCheck.java
41149 views
/*1* Copyright (c) 2005, 2007, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 622961826* @summary Ensure that the correct crypto permission is granted27* even when the transformation algorithm is lowercase or mixed28* case.29* @author Valerie Peng30*/3132import java.io.*;33import java.util.*;3435import java.security.*;36import java.security.spec.*;3738import javax.crypto.*;39import javax.crypto.spec.*;4041public class LowercasePermCheck {4243private static String[] ALGOS = {44"des", "desede", "rsa"45};4647public static void main(String[] args) throws Exception {48Provider p = Security.getProvider("SunJCE");49System.out.println("Testing provider " + p.getName() + "...");50if (Cipher.getMaxAllowedKeyLength("DES") == Integer.MAX_VALUE) {51// skip this test for unlimited jurisdiction policy files52System.out.println("Skip this test due to unlimited version");53return;54}55boolean isFailed = false;56for (int i = 0; i < ALGOS.length; i++) {57String algo = ALGOS[i];58Cipher c = Cipher.getInstance(algo, p);59int keyLen1 = Cipher.getMaxAllowedKeyLength(algo);60int keyLen2 = Cipher.getMaxAllowedKeyLength(algo.toUpperCase());6162if (keyLen1 != keyLen2) {63System.out.println("ERROR: Wrong keysize limit for " + algo);64System.out.println("Configured: " + keyLen2);65System.out.println("Actual: " + keyLen1);66isFailed = true;67}68System.out.println(algo + ": max " + keyLen1 + "-bit keys");69}70if (isFailed) {71throw new Exception("Test Failed!");72} else {73System.out.println("Test Passed!");74}75}76}777879