src/share/classes/sun/security/krb5/Config.java

Print this page
rev 7199 : 8014310: JAAS/Krb5LoginModule using des encytypes failure with NPE after JDK-8012679


 763 
 764     private static String trimmed(String s) {
 765         s = s.trim();
 766         if (s.isEmpty()) return s;
 767         if (s.charAt(0) == '"' && s.charAt(s.length()-1) == '"' ||
 768                 s.charAt(0) == '\'' && s.charAt(s.length()-1) == '\'') {
 769             s = s.substring(1, s.length()-1).trim();
 770         }
 771         return s;
 772     }
 773 
 774     /**
 775      * For testing purpose. This method lists all information being parsed from
 776      * the configuration file to the hashtable.
 777      */
 778     public void listTable() {
 779         System.out.println(this);
 780     }
 781 
 782     /**
 783      * Returns the default encryption types.
 784      *

 785      */
 786     public int[] defaultEtype(String enctypes) {
 787         String default_enctypes;
 788         default_enctypes = get("libdefaults", enctypes);
 789         String delim = " ";
 790         StringTokenizer st;
 791         int[] etype;
 792         if (default_enctypes == null) {
 793             if (DEBUG) {
 794                 System.out.println("Using builtin default etypes for " +
 795                     enctypes);
 796             }
 797             etype = EType.getBuiltInDefaults();
 798         } else {


 799             for (int j = 0; j < default_enctypes.length(); j++) {
 800                 if (default_enctypes.substring(j, j + 1).equals(",")) {
 801                     // only two delimiters are allowed to use
 802                     // according to Kerberos DCE doc.
 803                     delim = ",";
 804                     break;
 805                 }
 806             }
 807             st = new StringTokenizer(default_enctypes, delim);
 808             int len = st.countTokens();
 809             ArrayList<Integer> ls = new ArrayList<>(len);
 810             int type;
 811             for (int i = 0; i < len; i++) {
 812                 type = Config.getType(st.nextToken());
 813                 if ((type != -1) &&
 814                     (EType.isSupported(type))) {
 815                     ls.add(type);
 816                 }
 817             }
 818             if (ls.isEmpty()) {
 819                 if (DEBUG) {
 820                     System.out.println(
 821                         "no supported default etypes for " + enctypes);
 822                 }
 823                 return null;
 824             } else {
 825                 etype = new int[ls.size()];
 826                 for (int i = 0; i < etype.length; i++) {
 827                     etype[i] = ls.get(i);
 828                 }
 829             }
 830         }
 831 
 832         if (DEBUG) {
 833             System.out.print("default etypes for " + enctypes + ":");
 834             for (int i = 0; i < etype.length; i++) {
 835                 System.out.print(" " + etype[i]);
 836             }
 837             System.out.println(".");
 838         }
 839         return etype;
 840     }
 841 
 842 
 843     /**
 844      * Get the etype and checksum value for the specified encryption and
 845      * checksum type.
 846      *
 847      */
 848     /*
 849      * This method converts the string representation of encryption type and
 850      * checksum type to int value that can be later used by EType and
 851      * Checksum classes.
 852      */
 853     public static int getType(String input) {




 763 
 764     private static String trimmed(String s) {
 765         s = s.trim();
 766         if (s.isEmpty()) return s;
 767         if (s.charAt(0) == '"' && s.charAt(s.length()-1) == '"' ||
 768                 s.charAt(0) == '\'' && s.charAt(s.length()-1) == '\'') {
 769             s = s.substring(1, s.length()-1).trim();
 770         }
 771         return s;
 772     }
 773 
 774     /**
 775      * For testing purpose. This method lists all information being parsed from
 776      * the configuration file to the hashtable.
 777      */
 778     public void listTable() {
 779         System.out.println(this);
 780     }
 781 
 782     /**
 783      * Returns all etypes specified in krb5.conf for the given configName,
 784      * or all the builtin defaults. This result is always non-empty.
 785      * If no etypes are found, an exception is thrown.
 786      */
 787     public int[] defaultEtype(String configName) throws KrbException {
 788         String default_enctypes;
 789         default_enctypes = get("libdefaults", configName);


 790         int[] etype;
 791         if (default_enctypes == null) {
 792             if (DEBUG) {
 793                 System.out.println("Using builtin default etypes for " +
 794                     configName);
 795             }
 796             etype = EType.getBuiltInDefaults();
 797         } else {
 798             String delim = " ";
 799             StringTokenizer st;
 800             for (int j = 0; j < default_enctypes.length(); j++) {
 801                 if (default_enctypes.substring(j, j + 1).equals(",")) {
 802                     // only two delimiters are allowed to use
 803                     // according to Kerberos DCE doc.
 804                     delim = ",";
 805                     break;
 806                 }
 807             }
 808             st = new StringTokenizer(default_enctypes, delim);
 809             int len = st.countTokens();
 810             ArrayList<Integer> ls = new ArrayList<>(len);
 811             int type;
 812             for (int i = 0; i < len; i++) {
 813                 type = Config.getType(st.nextToken());
 814                 if (type != -1 && EType.isSupported(type)) {

 815                     ls.add(type);
 816                 }
 817             }
 818             if (ls.isEmpty()) {
 819                 throw new KrbException("no supported default etypes for "
 820                         + configName);



 821             } else {
 822                 etype = new int[ls.size()];
 823                 for (int i = 0; i < etype.length; i++) {
 824                     etype[i] = ls.get(i);
 825                 }
 826             }
 827         }
 828 
 829         if (DEBUG) {
 830             System.out.print("default etypes for " + configName + ":");
 831             for (int i = 0; i < etype.length; i++) {
 832                 System.out.print(" " + etype[i]);
 833             }
 834             System.out.println(".");
 835         }
 836         return etype;
 837     }
 838 
 839 
 840     /**
 841      * Get the etype and checksum value for the specified encryption and
 842      * checksum type.
 843      *
 844      */
 845     /*
 846      * This method converts the string representation of encryption type and
 847      * checksum type to int value that can be later used by EType and
 848      * Checksum classes.
 849      */
 850     public static int getType(String input) {