src/java.base/share/classes/sun/security/tools/keytool/Main.java

Print this page
7191662: JCE providers should be located via ServiceLoader


 712                 path = PathList.appendPath(
 713                         path, System.getProperty("env.class.path"));
 714                 path = PathList.appendPath(path, pathlist);
 715 
 716                 URL[] urls = PathList.pathToURLs(path);
 717                 cl = new URLClassLoader(urls);
 718             } else {
 719                 cl = ClassLoader.getSystemClassLoader();
 720             }
 721 
 722             for (Pair <String, String> provider: providers) {
 723                 String provName = provider.fst;
 724                 Class<?> provClass;
 725                 if (cl != null) {
 726                     provClass = cl.loadClass(provName);
 727                 } else {
 728                     provClass = Class.forName(provName);
 729                 }
 730 
 731                 String provArg = provider.snd;
 732                 Object obj;
 733                 if (provArg == null) {
 734                     obj = provClass.newInstance();
 735                 } else {
 736                     Constructor<?> c = provClass.getConstructor(PARAM_STRING);
 737                     obj = c.newInstance(provArg);
 738                 }
 739                 if (!(obj instanceof Provider)) {
 740                     MessageFormat form = new MessageFormat
 741                         (rb.getString("provName.not.a.provider"));
 742                     Object[] source = {provName};
 743                     throw new Exception(form.format(source));
 744                 }



 745                 Security.addProvider((Provider)obj);
 746             }
 747         }
 748 
 749         if (command == LIST && verbose && rfc) {
 750             System.err.println(rb.getString
 751                 ("Must.not.specify.both.v.and.rfc.with.list.command"));
 752             tinyHelp();
 753         }
 754 
 755         // Make sure provided passwords are at least 6 characters long
 756         if (command == GENKEYPAIR && keyPass!=null && keyPass.length < 6) {
 757             throw new Exception(rb.getString
 758                 ("Key.password.must.be.at.least.6.characters"));
 759         }
 760         if (newPass != null && newPass.length < 6) {
 761             throw new Exception(rb.getString
 762                 ("New.password.must.be.at.least.6.characters"));
 763         }
 764         if (destKeyPass != null && destKeyPass.length < 6) {




 712                 path = PathList.appendPath(
 713                         path, System.getProperty("env.class.path"));
 714                 path = PathList.appendPath(path, pathlist);
 715 
 716                 URL[] urls = PathList.pathToURLs(path);
 717                 cl = new URLClassLoader(urls);
 718             } else {
 719                 cl = ClassLoader.getSystemClassLoader();
 720             }
 721 
 722             for (Pair <String, String> provider: providers) {
 723                 String provName = provider.fst;
 724                 Class<?> provClass;
 725                 if (cl != null) {
 726                     provClass = cl.loadClass(provName);
 727                 } else {
 728                     provClass = Class.forName(provName);
 729                 }
 730 
 731                 String provArg = provider.snd;
 732                 Object obj = provClass.newInstance();






 733                 if (!(obj instanceof Provider)) {
 734                     MessageFormat form = new MessageFormat
 735                         (rb.getString("provName.not.a.provider"));
 736                     Object[] source = {provName};
 737                     throw new Exception(form.format(source));
 738                 }
 739                 if (provArg != null) {
 740                     obj = ((Provider) obj).configure(provArg);
 741                 }
 742                 Security.addProvider((Provider)obj);
 743             }
 744         }
 745 
 746         if (command == LIST && verbose && rfc) {
 747             System.err.println(rb.getString
 748                 ("Must.not.specify.both.v.and.rfc.with.list.command"));
 749             tinyHelp();
 750         }
 751 
 752         // Make sure provided passwords are at least 6 characters long
 753         if (command == GENKEYPAIR && keyPass!=null && keyPass.length < 6) {
 754             throw new Exception(rb.getString
 755                 ("Key.password.must.be.at.least.6.characters"));
 756         }
 757         if (newPass != null && newPass.length < 6) {
 758             throw new Exception(rb.getString
 759                 ("New.password.must.be.at.least.6.characters"));
 760         }
 761         if (destKeyPass != null && destKeyPass.length < 6) {