jdk/src/java.base/share/classes/sun/security/jca/ProviderList.java
changeset 38435 292ad46c1bf1
parent 36511 9d0388c6b336
child 40416 5d91b2fd668c
equal deleted inserted replaced
38434:a38df2210d1f 38435:292ad46c1bf1
   648             }
   648             }
   649             return s;
   649             return s;
   650         }
   650         }
   651     }
   651     }
   652 
   652 
       
   653     /* Defined Groups for jdk.security.provider.preferred */
       
   654     private static final String SHA2Group[] = { "SHA-224", "SHA-256",
       
   655             "SHA-384", "SHA-512", "SHA-512/224", "SHA-512/256" };
       
   656     private static final String HmacSHA2Group[] = { "HmacSHA224",
       
   657             "HmacSHA256", "HmacSHA384", "HmacSHA512"};
       
   658     private static final String SHA2RSAGroup[] = { "SHA224withRSA",
       
   659             "SHA256withRSA", "SHA384withRSA", "SHA512withRSA"};
       
   660     private static final String SHA2DSAGroup[] = { "SHA224withDSA",
       
   661             "SHA256withDSA", "SHA384withDSA", "SHA512withDSA"};
       
   662     private static final String SHA2ECDSAGroup[] = { "SHA224withECDSA",
       
   663             "SHA256withECDSA", "SHA384withECDSA", "SHA512withECDSA"};
       
   664     private static final String SHA3Group[] = { "SHA3-224", "SHA3-256",
       
   665             "SHA3-384", "SHA3-512" };
       
   666     private static final String HmacSHA3Group[] = { "HmacSHA3-224",
       
   667             "HmacSHA3-256", "HmacSHA3-384", "HmacSHA3-512"};
       
   668 
   653     // Individual preferred property entry from jdk.security.provider.preferred
   669     // Individual preferred property entry from jdk.security.provider.preferred
   654     private class PreferredEntry {
   670     private static class PreferredEntry {
   655         String type = null;
   671         private String type = null;
   656         String algorithm;
   672         private String algorithm;
   657         String provider;
   673         private String provider;
   658         String alternateName = null;
   674         private String alternateNames[] = null;
       
   675         private boolean group = false;
   659 
   676 
   660         PreferredEntry(String t, String p) {
   677         PreferredEntry(String t, String p) {
   661             int i = t.indexOf('.');
   678             int i = t.indexOf('.');
   662             if (i > 0) {
   679             if (i > 0) {
   663                 type = t.substring(0, i);
   680                 type = t.substring(0, i);
   665             } else {
   682             } else {
   666                 algorithm = t;
   683                 algorithm = t;
   667             }
   684             }
   668 
   685 
   669             provider = p;
   686             provider = p;
   670             if (algorithm.compareToIgnoreCase("SHA1") == 0) {
   687             // Group definitions
   671                 alternateName = "SHA-1";
   688             if (type != null && type.compareToIgnoreCase("Group") == 0) {
       
   689                 // Currently intrinsic algorithm groups
       
   690                 if (algorithm.compareToIgnoreCase("SHA2") == 0) {
       
   691                     alternateNames = SHA2Group;
       
   692                 } else if (algorithm.compareToIgnoreCase("HmacSHA2") == 0) {
       
   693                     alternateNames = HmacSHA2Group;
       
   694                 } else if (algorithm.compareToIgnoreCase("SHA2RSA") == 0) {
       
   695                     alternateNames = SHA2RSAGroup;
       
   696                 } else if (algorithm.compareToIgnoreCase("SHA2DSA") == 0) {
       
   697                     alternateNames = SHA2DSAGroup;
       
   698                 } else if (algorithm.compareToIgnoreCase("SHA2ECDSA") == 0) {
       
   699                     alternateNames = SHA2ECDSAGroup;
       
   700                 } else if (algorithm.compareToIgnoreCase("SHA3") == 0) {
       
   701                     alternateNames = SHA3Group;
       
   702                 } else if (algorithm.compareToIgnoreCase("HmacSHA3") == 0) {
       
   703                     alternateNames = HmacSHA3Group;
       
   704                 }
       
   705                 if (alternateNames != null) {
       
   706                     group = true;
       
   707                 }
       
   708 
       
   709             // If the algorithm name given is SHA1
       
   710             } else if (algorithm.compareToIgnoreCase("SHA1") == 0) {
       
   711                 alternateNames = new String[] { "SHA-1" };
   672             } else if (algorithm.compareToIgnoreCase("SHA-1") == 0) {
   712             } else if (algorithm.compareToIgnoreCase("SHA-1") == 0) {
   673                 alternateName = "SHA1";
   713                 alternateNames = new String[] { "SHA1" };
   674             }
   714             }
   675         }
   715         }
   676 
   716 
   677         boolean match(String t, String a) {
   717         boolean match(String t, String a) {
   678             if (debug != null) {
   718             if (debug != null) {
   679                 debug.println("Config match:  " + toString() + " == [" + t +
   719                 debug.println("Config check:  " + toString() + " == " +
   680                         ", " + a + "]");
   720                         print(t, a, null));
   681             }
   721             }
   682 
   722 
   683             // Compare service type if configured
   723             // Compare service type if configured
   684             if (type != null && type.compareToIgnoreCase(t) != 0) {
   724             if (type != null && !group && type.compareToIgnoreCase(t) != 0) {
   685                 return false;
   725                 return false;
   686             }
   726             }
   687 
   727 
   688             // Compare the algorithm string.
   728             // Compare the algorithm string.
   689             if (a.compareToIgnoreCase(algorithm) == 0) {
   729             if (!group && a.compareToIgnoreCase(algorithm) == 0) {
   690                 if (debug != null) {
   730                 if (debug != null) {
   691                     debug.println("Config entry found:  " + toString());
   731                     debug.println("Config entry matched:  " + toString());
   692                 }
   732                 }
   693                 return true;
   733                 return true;
   694             }
   734             }
   695 
   735 
   696             if (alternateName != null &&
   736             if (alternateNames != null) {
   697                     a.compareToIgnoreCase(alternateName) == 0) {
   737                 for (String alt : alternateNames) {
   698                 if (debug != null) {
   738                     if (debug != null) {
   699                     debug.println("Config entry found (alternateName):  " +
   739                         debug.println("AltName check:  " + print(type, alt,
   700                             toString());
   740                                 provider));
   701                 }
   741                     }
   702                 return true;
   742                     if (a.compareToIgnoreCase(alt) == 0) {
       
   743                         if (debug != null) {
       
   744                             debug.println("AltName entry matched:  " +
       
   745                                     provider);
       
   746                         }
       
   747                         return true;
       
   748                     }
       
   749                 }
   703             }
   750             }
   704 
   751 
   705             // No match
   752             // No match
   706             return false;
   753             return false;
   707         }
   754         }
   708 
   755 
       
   756         // Print debugging output of PreferredEntry
       
   757         private String print(String t, String a, String p) {
       
   758             return "[" + ((t != null) ? t : "" ) + ", " + a +
       
   759                     ((p != null) ? " : " + p : "" ) + "] ";
       
   760         }
       
   761 
   709         public String toString() {
   762         public String toString() {
   710             return "[" + type + ", " + algorithm + " : " + provider + "] ";
   763             return print(type, algorithm, provider);
   711         }
   764         }
   712     }
   765     }
   713 
   766 
   714 }
   767 }