Path: blob/master/test/jdk/sun/security/x509/AlgorithmId/ExtensibleAlgorithmId.java
41153 views
/*1* Copyright (c) 1998, 2020, 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 4162868 8130181 824215126* @modules java.base/sun.security.x50927* @modules java.base/sun.security.util28* @run main/othervm ExtensibleAlgorithmId29* @summary Algorithm Name-to-OID mapping needs to be made extensible.30*/3132// Run in othervm, coz AlgorithmId.oidTable is only initialized once3334import java.security.*;35import sun.security.x509.AlgorithmId;3637public class ExtensibleAlgorithmId {3839public static void main(String[] args) throws Exception {40TestProvider p = new TestProvider();41Security.addProvider(p);42AlgorithmId algid = AlgorithmId.getAlgorithmId(TestProvider.ALG_NAME);43String oid = algid.getOID().toString();44if (!oid.equals(TestProvider.ALG_OID)) {45throw new Exception("Provider alias oid not used, found " + oid);46}47String name = algid.getName();48if (!name.equalsIgnoreCase(TestProvider.ALG_NAME)) {49throw new Exception("provider alias name not used, found " + name);50}51String alias = "Alg.Alias.Signature.OID." + oid;52String stdAlgName = p.getProperty(alias);53if (stdAlgName == null ||54!stdAlgName.equalsIgnoreCase(TestProvider.ALG_NAME)) {55throw new Exception("Wrong OID");56}57}5859static class TestProvider extends Provider {6061static String ALG_OID = "1.2.3.4.5.6.7.8.9.0";62static String ALG_NAME = "XYZ";6364public TestProvider() {65super("Dummy", "1.0", "XYZ algorithm");6667AccessController.doPrivileged(new PrivilegedAction() {68public Object run() {6970put("Signature." + ALG_NAME, "test.xyz");71// preferred OID72put("Alg.Alias.Signature.OID." + ALG_OID,73ALG_NAME);74put("Alg.Alias.Signature.9.8.7.6.5.4.3.2.1.0",75ALG_NAME);76return null;77}78});79}80}81}828384