Path: blob/master/test/jdk/sun/security/ssl/rsa/CheckProviderEntries.java
41152 views
/*1* Copyright (c) 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.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*/2223import java.security.*;24import java.util.Iterator;25import java.security.Provider.Service;2627/*28* @test29* @bug 822001630* @summary This test checks the RSA-related services in SunJSSE provider31*/32public class CheckProviderEntries {3334private static boolean testResult = true;3536private static void error(String msg) {37testResult = false;38System.out.println(msg);39}40public static void main(String[] args) throws NoSuchAlgorithmException,41InvalidKeyException, SignatureException {42Provider p = Security.getProvider("SunJSSE");43Iterator<Provider.Service> iter = p.getServices().iterator();44while (iter.hasNext()) {45Service s = iter.next();46String type = s.getType();47String algo = s.getAlgorithm();48System.out.println("Type: " + type + " " + algo);49try {50if (algo.indexOf("RSA") != -1) {51// only MD5andSHA1withRSA signature support52// error out on any other RSA support53if (type.equals("Signature") &&54algo.equals("MD5andSHA1withRSA")) {55s.newInstance(null);56continue;57}58error("Error: unexpected RSA services");59}60} catch (NoSuchAlgorithmException | InvalidParameterException e) {61error("Error: cannot create obj " + e);62}63}64if (testResult) {65System.out.println("Test Passed");66} else {67throw new RuntimeException("One or more tests failed");68}69}70}717273