Path: blob/master/src/java.base/share/classes/sun/security/provider/SunEntries.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.io.*;28import java.net.*;29import java.util.*;30import java.security.*;3132import jdk.internal.util.StaticProperty;33import sun.security.action.GetPropertyAction;34import sun.security.util.SecurityProviderConstants;35import static sun.security.util.SecurityProviderConstants.getAliases;3637/**38* Defines the entries of the SUN provider.39*40* Algorithms supported, and their names:41*42* - SHA is the message digest scheme described in FIPS 180-1.43* Aliases for SHA are SHA-1 and SHA1.44*45* - SHA1withDSA is the signature scheme described in FIPS 186.46* (SHA used in DSA is SHA-1: FIPS 186 with Change No 1.)47* Aliases for SHA1withDSA are DSA, DSS, SHA/DSA, SHA-1/DSA, SHA1/DSA,48* SHAwithDSA, DSAWithSHA1, and the object49* identifier strings "OID.1.3.14.3.2.13", "OID.1.3.14.3.2.27" and50* "OID.1.2.840.10040.4.3".51*52* - SHA-2 is a set of message digest schemes described in FIPS 180-2.53* SHA-2 family of hash functions includes SHA-224, SHA-256, SHA-384,54* and SHA-512.55*56* - [SHA-224|SHA-256|SHA-384|SHA-512]withDSA are the signature schemes57* described in FIPS 186-3. The associated object identifiers are58* "OID.2.16.840.1.101.3.4.3.[1|2|3|4]" respectively.59*60* - [SHA3-224|SHA3-256|SHA3-384|SHA3-512]withDSA are the signature schemes61* using SHA-3 family of digests with DSA. The associated object identifiers62* are "OID.2.16.840.1.101.3.4.3.[5|6|7|8]" respectively.63*64* - DSA is the key generation scheme as described in FIPS 186.65* Aliases for DSA include the OID strings "OID.1.3.14.3.2.12"66* and "OID.1.2.840.10040.4.1".67*68* - MD5 is the message digest scheme described in RFC 1321.69* There are no aliases for MD5.70*71* - X.509 is the certificate factory type for X.509 certificates72* and CRLs. Aliases for X.509 are X509.73*74* - PKIX is the certification path validation algorithm described75* in RFC 5280. The ValidationAlgorithm attribute notes the76* specification that this provider implements.77*78* - JavaPolicy is the default file-based Policy type.79*80* - JavaLoginConfig is the default file-based LoginModule Configuration type.81*/8283public final class SunEntries {8485// the default algo used by SecureRandom class for new SecureRandom() calls86public static final String DEF_SECURE_RANDOM_ALGO;8788SunEntries(Provider p) {89services = new LinkedHashSet<>(50, 0.9f);9091// start populating content using the specified provider9293// common attribute map94HashMap<String, String> attrs = new HashMap<>(3);9596/*97* SecureRandom engines98*/99attrs.put("ThreadSafe", "true");100if (NativePRNG.isAvailable()) {101add(p, "SecureRandom", "NativePRNG",102"sun.security.provider.NativePRNG", attrs);103}104if (NativePRNG.Blocking.isAvailable()) {105add(p, "SecureRandom", "NativePRNGBlocking",106"sun.security.provider.NativePRNG$Blocking", attrs);107}108if (NativePRNG.NonBlocking.isAvailable()) {109add(p, "SecureRandom", "NativePRNGNonBlocking",110"sun.security.provider.NativePRNG$NonBlocking", attrs);111}112attrs.put("ImplementedIn", "Software");113add(p, "SecureRandom", "DRBG", "sun.security.provider.DRBG", attrs);114add(p, "SecureRandom", "SHA1PRNG",115"sun.security.provider.SecureRandom", attrs);116117/*118* Signature engines119*/120attrs.clear();121String dsaKeyClasses = "java.security.interfaces.DSAPublicKey" +122"|java.security.interfaces.DSAPrivateKey";123attrs.put("SupportedKeyClasses", dsaKeyClasses);124attrs.put("ImplementedIn", "Software");125126attrs.put("KeySize", "1024"); // for NONE and SHA1 DSA signatures127128addWithAlias(p, "Signature", "SHA1withDSA",129"sun.security.provider.DSA$SHA1withDSA", attrs);130addWithAlias(p, "Signature", "NONEwithDSA",131"sun.security.provider.DSA$RawDSA", attrs);132133// for DSA signatures with 224/256-bit digests134attrs.put("KeySize", "2048");135136addWithAlias(p, "Signature", "SHA224withDSA",137"sun.security.provider.DSA$SHA224withDSA", attrs);138addWithAlias(p, "Signature", "SHA256withDSA",139"sun.security.provider.DSA$SHA256withDSA", attrs);140141addWithAlias(p, "Signature", "SHA3-224withDSA",142"sun.security.provider.DSA$SHA3_224withDSA", attrs);143addWithAlias(p, "Signature", "SHA3-256withDSA",144"sun.security.provider.DSA$SHA3_256withDSA", attrs);145146attrs.put("KeySize", "3072"); // for DSA sig using 384/512-bit digests147148addWithAlias(p, "Signature", "SHA384withDSA",149"sun.security.provider.DSA$SHA384withDSA", attrs);150addWithAlias(p, "Signature", "SHA512withDSA",151"sun.security.provider.DSA$SHA512withDSA", attrs);152addWithAlias(p, "Signature", "SHA3-384withDSA",153"sun.security.provider.DSA$SHA3_384withDSA", attrs);154addWithAlias(p, "Signature", "SHA3-512withDSA",155"sun.security.provider.DSA$SHA3_512withDSA", attrs);156157attrs.remove("KeySize");158159add(p, "Signature", "SHA1withDSAinP1363Format",160"sun.security.provider.DSA$SHA1withDSAinP1363Format");161add(p, "Signature", "NONEwithDSAinP1363Format",162"sun.security.provider.DSA$RawDSAinP1363Format");163add(p, "Signature", "SHA224withDSAinP1363Format",164"sun.security.provider.DSA$SHA224withDSAinP1363Format");165add(p, "Signature", "SHA256withDSAinP1363Format",166"sun.security.provider.DSA$SHA256withDSAinP1363Format");167add(p, "Signature", "SHA384withDSAinP1363Format",168"sun.security.provider.DSA$SHA384withDSAinP1363Format");169add(p, "Signature", "SHA512withDSAinP1363Format",170"sun.security.provider.DSA$SHA512withDSAinP1363Format");171add(p, "Signature", "SHA3-224withDSAinP1363Format",172"sun.security.provider.DSA$SHA3_224withDSAinP1363Format");173add(p, "Signature", "SHA3-256withDSAinP1363Format",174"sun.security.provider.DSA$SHA3_256withDSAinP1363Format");175add(p, "Signature", "SHA3-384withDSAinP1363Format",176"sun.security.provider.DSA$SHA3_384withDSAinP1363Format");177add(p, "Signature", "SHA3-512withDSAinP1363Format",178"sun.security.provider.DSA$SHA3_512withDSAinP1363Format");179/*180* Key Pair Generator engines181*/182attrs.clear();183attrs.put("ImplementedIn", "Software");184attrs.put("KeySize", "2048"); // for DSA KPG and APG only185186String dsaKPGImplClass = "sun.security.provider.DSAKeyPairGenerator$";187dsaKPGImplClass += (useLegacyDSA? "Legacy" : "Current");188addWithAlias(p, "KeyPairGenerator", "DSA", dsaKPGImplClass, attrs);189190/*191* Algorithm Parameter Generator engines192*/193addWithAlias(p, "AlgorithmParameterGenerator", "DSA",194"sun.security.provider.DSAParameterGenerator", attrs);195attrs.remove("KeySize");196197/*198* Algorithm Parameter engines199*/200addWithAlias(p, "AlgorithmParameters", "DSA",201"sun.security.provider.DSAParameters", attrs);202203/*204* Key factories205*/206addWithAlias(p, "KeyFactory", "DSA",207"sun.security.provider.DSAKeyFactory", attrs);208209/*210* Digest engines211*/212add(p, "MessageDigest", "MD2", "sun.security.provider.MD2", attrs);213add(p, "MessageDigest", "MD5", "sun.security.provider.MD5", attrs);214addWithAlias(p, "MessageDigest", "SHA-1", "sun.security.provider.SHA",215attrs);216217addWithAlias(p, "MessageDigest", "SHA-224",218"sun.security.provider.SHA2$SHA224", attrs);219addWithAlias(p, "MessageDigest", "SHA-256",220"sun.security.provider.SHA2$SHA256", attrs);221addWithAlias(p, "MessageDigest", "SHA-384",222"sun.security.provider.SHA5$SHA384", attrs);223addWithAlias(p, "MessageDigest", "SHA-512",224"sun.security.provider.SHA5$SHA512", attrs);225addWithAlias(p, "MessageDigest", "SHA-512/224",226"sun.security.provider.SHA5$SHA512_224", attrs);227addWithAlias(p, "MessageDigest", "SHA-512/256",228"sun.security.provider.SHA5$SHA512_256", attrs);229addWithAlias(p, "MessageDigest", "SHA3-224",230"sun.security.provider.SHA3$SHA224", attrs);231addWithAlias(p, "MessageDigest", "SHA3-256",232"sun.security.provider.SHA3$SHA256", attrs);233addWithAlias(p, "MessageDigest", "SHA3-384",234"sun.security.provider.SHA3$SHA384", attrs);235addWithAlias(p, "MessageDigest", "SHA3-512",236"sun.security.provider.SHA3$SHA512", attrs);237238/*239* Certificates240*/241addWithAlias(p, "CertificateFactory", "X.509",242"sun.security.provider.X509Factory", attrs);243244/*245* KeyStore246*/247add(p, "KeyStore", "PKCS12",248"sun.security.pkcs12.PKCS12KeyStore$DualFormatPKCS12");249add(p, "KeyStore", "JKS",250"sun.security.provider.JavaKeyStore$DualFormatJKS", attrs);251add(p, "KeyStore", "CaseExactJKS",252"sun.security.provider.JavaKeyStore$CaseExactJKS", attrs);253add(p, "KeyStore", "DKS", "sun.security.provider.DomainKeyStore$DKS",254attrs);255256257/*258* CertStores259*/260add(p, "CertStore", "Collection",261"sun.security.provider.certpath.CollectionCertStore",262attrs);263add(p, "CertStore", "com.sun.security.IndexedCollection",264"sun.security.provider.certpath.IndexedCollectionCertStore",265attrs);266267/*268* Policy269*/270add(p, "Policy", "JavaPolicy", "sun.security.provider.PolicySpiFile");271272/*273* Configuration274*/275add(p, "Configuration", "JavaLoginConfig",276"sun.security.provider.ConfigFile$Spi");277278/*279* CertPathBuilder and CertPathValidator280*/281attrs.clear();282attrs.put("ValidationAlgorithm", "RFC5280");283attrs.put("ImplementedIn", "Software");284285add(p, "CertPathBuilder", "PKIX",286"sun.security.provider.certpath.SunCertPathBuilder",287attrs);288add(p, "CertPathValidator", "PKIX",289"sun.security.provider.certpath.PKIXCertPathValidator",290attrs);291}292293Iterator<Provider.Service> iterator() {294return services.iterator();295}296297private void add(Provider p, String type, String algo, String cn) {298services.add(new Provider.Service(p, type, algo, cn, null, null));299}300301private void add(Provider p, String type, String algo, String cn,302HashMap<String, String> attrs) {303services.add(new Provider.Service(p, type, algo, cn, null, attrs));304}305306private void addWithAlias(Provider p, String type, String algo, String cn,307HashMap<String, String> attrs) {308services.add(new Provider.Service(p, type, algo, cn,309getAliases(algo), attrs));310}311312private LinkedHashSet<Provider.Service> services;313314// name of the *System* property, takes precedence over PROP_RNDSOURCE315private static final String PROP_EGD = "java.security.egd";316// name of the *Security* property317private static final String PROP_RNDSOURCE = "securerandom.source";318319private static final boolean useLegacyDSA =320Boolean.parseBoolean(GetPropertyAction.privilegedGetProperty321("jdk.security.legacyDSAKeyPairGenerator"));322323static final String URL_DEV_RANDOM = "file:/dev/random";324static final String URL_DEV_URANDOM = "file:/dev/urandom";325326@SuppressWarnings("removal")327private static final String seedSource = AccessController.doPrivileged(328new PrivilegedAction<String>() {329330@Override331public String run() {332String egdSource = System.getProperty(PROP_EGD, "");333if (egdSource.length() != 0) {334return egdSource;335}336egdSource = Security.getProperty(PROP_RNDSOURCE);337if (egdSource == null) {338return "";339}340return egdSource;341}342});343344static {345DEF_SECURE_RANDOM_ALGO = (NativePRNG.isAvailable() &&346(seedSource.equals(URL_DEV_URANDOM) ||347seedSource.equals(URL_DEV_RANDOM)) ?348"NativePRNG" : "DRBG");349}350351static String getSeedSource() {352return seedSource;353}354355/*356* Use a URI to access this File. Previous code used a URL357* which is less strict on syntax. If we encounter a358* URISyntaxException we make best efforts for backwards359* compatibility. e.g. space character in deviceName string.360*361* Method called within PrivilegedExceptionAction block.362*363* Moved from SeedGenerator to avoid initialization problems with364* signed providers.365*/366static File getDeviceFile(URL device) throws IOException {367try {368URI deviceURI = device.toURI();369if(deviceURI.isOpaque()) {370// File constructor does not accept opaque URI371URI localDir = new File(372StaticProperty.userDir()).toURI();373String uriPath = localDir.toString() +374deviceURI.toString().substring(5);375return new File(URI.create(uriPath));376} else {377return new File(deviceURI);378}379} catch (URISyntaxException use) {380/*381* Make best effort to access this File.382* We can try using the URL path.383*/384return new File(device.getPath());385}386}387}388389390