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 CertPathValidator { 59 60 68 private static final String CPV_TYPE = "certpathvalidator.type"; 69 private static final Debug debug = Debug.getInstance("certpath"); 70 private CertPathValidatorSpi validatorSpi; 71 private Provider provider; 72 private String algorithm; 73 74 82 protected CertPathValidator(CertPathValidatorSpi validatorSpi, 83 Provider provider, String algorithm) 84 { 85 this.validatorSpi = validatorSpi; 86 this.provider = provider; 87 this.algorithm = algorithm; 88 } 89 90 108 public static CertPathValidator getInstance(String algorithm) 109 throws NoSuchAlgorithmException { 110 Instance instance = GetInstance.getInstance("CertPathValidator", 111 CertPathValidatorSpi .class, algorithm); 112 return new CertPathValidator ((CertPathValidatorSpi )instance.impl, 113 instance.provider, algorithm); 114 } 115 116 132 public static CertPathValidator getInstance(String algorithm, 133 String provider) throws NoSuchAlgorithmException , 134 NoSuchProviderException { 135 Instance instance = GetInstance.getInstance("CertPathValidator", 136 CertPathValidatorSpi .class, algorithm, provider); 137 return new CertPathValidator ((CertPathValidatorSpi )instance.impl, 138 instance.provider, algorithm); 139 } 140 141 156 public static CertPathValidator getInstance(String algorithm, 157 Provider provider) throws NoSuchAlgorithmException { 158 Instance instance = GetInstance.getInstance("CertPathValidator", 159 CertPathValidatorSpi .class, algorithm, provider); 160 return new CertPathValidator ((CertPathValidatorSpi )instance.impl, 161 instance.provider, algorithm); 162 } 163 164 170 public final Provider getProvider() { 171 return this.provider; 172 } 173 174 179 public final String getAlgorithm() { 180 return this.algorithm; 181 } 182 183 202 public final CertPathValidatorResult validate(CertPath certPath, 203 CertPathParameters params) 204 throws CertPathValidatorException , InvalidAlgorithmParameterException 205 { 206 return validatorSpi.engineValidate(certPath, params); 207 } 208 209 230 public final static String getDefaultType() { 231 String cpvtype; 232 cpvtype = (String )AccessController.doPrivileged(new PrivilegedAction () { 233 public Object run() { 234 return Security.getProperty(CPV_TYPE); 235 } 236 }); 237 if (cpvtype == null) { 238 cpvtype = "PKIX"; 239 } 240 return cpvtype; 241 } 242 } 243 | Popular Tags |