Path: blob/master/src/java.base/share/classes/sun/security/provider/VerificationProvider.java
41159 views
/*1* Copyright (c) 1996, 2021, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.provider;2627import java.util.*;28import java.security.*;2930import sun.security.rsa.SunRsaSignEntries;31import static sun.security.util.SecurityConstants.PROVIDER_VER;323334/**35* Provider used for verification of signed JAR files *if* the Sun and36* SunRsaSign main classes have been removed. Otherwise, this provider is not37* necessary and registers no algorithms. This functionality only exists to38* support a use case required by a specific customer and is not generally39* supported.40*41* @since 1.742* @author Andreas Sterbenz43*/44public final class VerificationProvider extends Provider {4546@java.io.Serial47private static final long serialVersionUID = 7482667077568930381L;4849private static final boolean ACTIVE;5051static {52boolean b;53try {54Class.forName("sun.security.provider.Sun");55Class.forName("sun.security.rsa.SunRsaSign");56b = false;57} catch (ClassNotFoundException e) {58b = true;59}60ACTIVE = b;61}6263@SuppressWarnings("removal")64public VerificationProvider() {65super("SunJarVerification", PROVIDER_VER, "Jar Verification Provider");66// register all algorithms normally registered by the Sun and SunRsaSign67// providers, but only if they are missing68if (ACTIVE == false) {69return;70}7172Provider p = this;73Iterator<Provider.Service> sunIter = new SunEntries(p).iterator();74Iterator<Provider.Service> rsaIter =75new SunRsaSignEntries(p).iterator();7677// if there is no security manager installed, put directly into78// the provider79if (System.getSecurityManager() == null) {80putEntries(sunIter);81putEntries(rsaIter);82} else {83AccessController.doPrivileged(new PrivilegedAction<Object>() {84public Void run() {85putEntries(sunIter);86putEntries(rsaIter);87return null;88}89});90}91}9293void putEntries(Iterator<Provider.Service> i) {94while (i.hasNext()) {95putService(i.next());96}97}9899}100101102