Source code: jsdsi/CertPathValidator.java
1 /*
2 * Copyright 2002 Massachusetts Institute of Technology
3 *
4 * Permission to use, copy, modify, and distribute this program for any
5 * purpose and without fee is hereby granted, provided that this
6 * copyright and permission notice appear on all copies and supporting
7 * documentation, the name of M.I.T. not be used in advertising or
8 * publicity pertaining to distribution of the program without specific
9 * prior permission, and notice be given in supporting documentation that
10 * copying and distribution is by permission of M.I.T. M.I.T. makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 */
14 package jsdsi;
15
16 import java.security.InvalidAlgorithmParameterException;
17 import java.security.GeneralSecurityException;
18 import java.security.cert.CertPathValidatorSpi;
19 import java.security.cert.CertPathValidatorException;
20
21 /**
22 * Checks whether a certification path satisfies certain parameters:
23 * essentially a wrapper around Proof.verify().
24 *
25 * @see Proof
26 *
27 * @author Sameer Ajmani
28 * @version $Revision: 1.3 $ $Date: 2003/11/24 19:05:55 $
29 */
30 public class CertPathValidator extends CertPathValidatorSpi {
31 /**
32 * @see java.security.cert.CertPathValidatorSpi#engineValidate(CertPath, CertPathParameters)
33 */
34 public java.security.cert.CertPathValidatorResult engineValidate(
35 java.security.cert.CertPath path,
36 java.security.cert.CertPathParameters params)
37 throws CertPathValidatorException, InvalidAlgorithmParameterException {
38 try {
39 return engineValidate(
40 (jsdsi.CertPath) path,
41 (jsdsi.CertPathParameters) params);
42 } catch (ClassCastException e) {
43 throw (InvalidAlgorithmParameterException) new InvalidAlgorithmParameterException()
44 .initCause(
45 e);
46 }
47 }
48
49 /**
50 * @see java.security.cert.CertPathValidatorSpi#engineValidate(CertPath, CertPathParameters)
51 */
52 public jsdsi.CertPathValidatorResult engineValidate(
53 jsdsi.CertPath path,
54 jsdsi.CertPathParameters params)
55 throws CertPathValidatorException, InvalidAlgorithmParameterException {
56 if (!path.getProof().getCert().implies(params.getCert())) {
57 throw new CertPathValidatorException
58 ("param cert does not match or imply proof cert");
59 }
60
61 try {
62 path.getProof().verify();
63 return new jsdsi.CertPathValidatorResult(null);
64 } catch (GeneralSecurityException e) {
65 return new jsdsi.CertPathValidatorResult(e);
66 }
67 }
68 }