Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: hk/hku/cecid/phoenix/pki/CRLFileSource.java


1   /*
2    * Academic Free License
3    * Version 1.0
4    *
5    * This Academic Free License applies to any software and associated 
6    * documentation (the "Software") whose owner (the "Licensor") has placed the 
7    * statement "Licensed under the Academic Free License Version 1.0" immediately 
8    * after the copyright notice that applies to the Software. 
9    *
10   * Permission is hereby granted, free of charge, to any person obtaining a copy 
11   * of the Software (1) to use, copy, modify, merge, publish, perform, 
12   * distribute, sublicense, and/or sell copies of the Software, and to permit 
13   * persons to whom the Software is furnished to do so, and (2) under patent 
14   * claims owned or controlled by the Licensor that are embodied in the Software 
15   * as furnished by the Licensor, to make, use, sell and offer for sale the 
16   * Software and derivative works thereof, subject to the following conditions: 
17   *
18   * - Redistributions of the Software in source code form must retain all 
19   *   copyright notices in the Software as furnished by the Licensor, this list 
20   *   of conditions, and the following disclaimers. 
21   * - Redistributions of the Software in executable form must reproduce all 
22   *   copyright notices in the Software as furnished by the Licensor, this list 
23   *   of conditions, and the following disclaimers in the documentation and/or 
24   *   other materials provided with the distribution. 
25   * - Neither the names of Licensor, nor the names of any contributors to the 
26   *   Software, nor any of their trademarks or service marks, may be used to 
27   *   endorse or promote products derived from this Software without express 
28   *   prior written permission of the Licensor. 
29   *
30   * DISCLAIMERS: LICENSOR WARRANTS THAT THE COPYRIGHT IN AND TO THE SOFTWARE IS 
31   * OWNED BY THE LICENSOR OR THAT THE SOFTWARE IS DISTRIBUTED BY LICENSOR UNDER 
32   * A VALID CURRENT LICENSE. EXCEPT AS EXPRESSLY STATED IN THE IMMEDIATELY 
33   * PRECEDING SENTENCE, THE SOFTWARE IS PROVIDED BY THE LICENSOR, CONTRIBUTORS 
34   * AND COPYRIGHT OWNERS "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
35   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
36   * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 
37   * LICENSOR, CONTRIBUTORS OR COPYRIGHT OWNERS BE LIABLE FOR ANY CLAIM, DAMAGES 
38   * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
39   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE. 
40   *
41   * This license is Copyright (C) 2002 Lawrence E. Rosen. All rights reserved. 
42   * Permission is hereby granted to copy and distribute this license without 
43   * modification. This license may not be modified without the express written 
44   * permission of its copyright owner. 
45   */
46  
47  /* ===== 
48   *
49   * $Header: /ebxml/staff/cecid/cvs_repository/pki/src/hk/hku/cecid/phoenix/pki/CRLFileSource.java,v 1.5 2002/12/13 03:59:13 kcyee Exp $
50   *
51   * Code authored by:
52   *
53   * kcyee [2002-04-30]
54   *
55   * Code reviewed by:
56   *
57   * username [YYYY-MM-DD]
58   *
59   * Remarks:
60   *
61   * =====
62   */
63  
64  package hk.hku.cecid.phoenix.pki;
65  
66  import java.io.File;
67  import java.io.FileInputStream;
68  import java.io.InputStream;
69  import java.io.IOException;
70  import java.security.cert.CertificateException;
71  import java.security.cert.CertificateFactory;
72  import java.security.cert.CRLException;
73  import java.security.cert.X509CRL;
74  
75  /**
76   * This class extends CRLSource to add initialization procedure for loading a 
77   * file-based CRL.
78   *
79   * @author kcyee
80   * @version $Revision: 1.5 $
81   */
82  public class CRLFileSource extends CRLSource {
83  
84      /**
85       * The file holding the CRL
86       */
87      protected File crlFile;
88  
89      /**
90       * Default constructor. It initializes the object. But the object 
91       * is still unusable until init() is called.
92       */
93      public CRLFileSource() {
94          super();
95          crlFile = null;
96      }
97  
98      /**
99       * Constructor with the file name of the CRL passed in. It initializes 
100      * the object. But the object is still unusable until init() is called.
101      *
102      * @param crlFile the file name of the CRL
103      */
104     public CRLFileSource(String crlFile) {
105         this(new File(crlFile));
106     }
107 
108     /**
109      * Constructor with the file object holding the CRL passed in. It 
110      * initializes the object. But the object is still unusable until init() 
111      * is called.
112      *
113      * @param crlFile the file object of the file holding the CRL
114      */
115     public CRLFileSource(File crlFile) {
116         super();
117         this.crlFile = crlFile;
118     }
119 
120     /**
121      * Initializes the object. The CRL file is being loaded into the 
122      * internal CRL object.
123      *
124      * @throws CRLException Initialization error occurs
125      */
126     public void init() throws CRLException {
127         if (crlFile == null || !crlFile.exists() || !crlFile.isFile()) {
128             throw new CRLException("Error loading file: " + crlFile + ".\n");
129         }
130 
131         try {
132             InputStream inStream = new FileInputStream(crlFile);
133             CertificateFactory cf = CertificateFactory.getInstance("X.509");
134             crl = (X509CRL) cf.generateCRL(inStream);
135             inStream.close();
136         }
137         catch (IOException e) {
138             throw new CRLException("IO exception when loading crl file.\n"
139                 + e.getMessage());
140         }
141         catch (CertificateException e) {
142             throw new CRLException(
143                 "Certificate exception when loading crl file.\n" 
144                 + e.getMessage());
145         }
146 
147         ready = true;
148     }
149 }