1 7 8 package java.security.cert; 9 10 import java.security.AccessController ; 11 import java.security.InvalidAlgorithmParameterException ; 12 import java.security.NoSuchAlgorithmException ; 13 import java.security.NoSuchProviderException ; 14 import java.security.PrivilegedAction ; 15 import java.security.Provider ; 16 import java.security.Security ; 17 import sun.security.util.Debug; 18 19 import sun.security.jca.*; 20 import sun.security.jca.GetInstance.Instance; 21 22 58 public class CertPathBuilder { 59 60 68 private static final String CPB_TYPE = "certpathbuilder.type"; 69 private static final Debug debug = Debug.getInstance("certpath"); 70 private CertPathBuilderSpi builderSpi; 71 private Provider provider; 72 private String algorithm; 73 74 82 protected CertPathBuilder(CertPathBuilderSpi builderSpi, Provider provider, 83 String algorithm) 84 { 85 this.builderSpi = builderSpi; 86 this.provider = provider; 87 this.algorithm = algorithm; 88 } 89 90 108 public static CertPathBuilder getInstance(String algorithm) 109 throws NoSuchAlgorithmException { 110 Instance instance = GetInstance.getInstance("CertPathBuilder", 111 CertPathBuilderSpi .class, algorithm); 112 return new CertPathBuilder ((CertPathBuilderSpi )instance.impl, 113 instance.provider, algorithm); 114 } 115 116 131 public static CertPathBuilder getInstance(String algorithm, String provider) 132 throws NoSuchAlgorithmException , NoSuchProviderException { 133 Instance instance = GetInstance.getInstance("CertPathBuilder", 134 CertPathBuilderSpi .class, algorithm, provider); 135 return new CertPathBuilder ((CertPathBuilderSpi )instance.impl, 136 instance.provider, algorithm); 137 } 138 139 154 public static CertPathBuilder getInstance(String algorithm, 155 Provider provider) throws NoSuchAlgorithmException { 156 Instance instance = GetInstance.getInstance("CertPathBuilder", 157 CertPathBuilderSpi .class, algorithm, provider); 158 return new CertPathBuilder ((CertPathBuilderSpi )instance.impl, 159 instance.provider, algorithm); 160 } 161 162 167 public final Provider getProvider() { 168 return this.provider; 169 } 170 171 176 public final String getAlgorithm() { 177 return this.algorithm; 178 } 179 180 191 public final CertPathBuilderResult build(CertPathParameters params) 192 throws CertPathBuilderException , InvalidAlgorithmParameterException 193 { 194 return builderSpi.engineBuild(params); 195 } 196 197 218 public final static String getDefaultType() { 219 String cpbtype; 220 cpbtype = (String )AccessController.doPrivileged(new PrivilegedAction () { 221 public Object run() { 222 return Security.getProperty(CPB_TYPE); 223 } 224 }); 225 if (cpbtype == null) { 226 cpbtype = "PKIX"; 227 } 228 return cpbtype; 229 } 230 } 231 | Popular Tags |