summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/dbs/CRLIssuingPointRecord.java
blob: 9f0797d40d97856cb67bd7758e5a7a3ec7cc2311 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.dbs;

import java.math.BigInteger;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.dbs.IDBObj;
import com.netscape.certsrv.dbs.crldb.ICRLIssuingPointRecord;

/**
 * A class represents a CRL issuing point record.
 * <P>
 * 
 * @author thomask
 * @version $Revision$, $Date$
 */
public class CRLIssuingPointRecord implements ICRLIssuingPointRecord, IDBObj {

    /**
     *
     */
    private static final long serialVersionUID = 400565044343905267L;
    protected String mId = null; // internal unique id
    protected BigInteger mCRLNumber = null; // CRL number
    protected Long mCRLSize = null;
    protected Date mThisUpdate = null;
    protected Date mNextUpdate = null;
    protected BigInteger mDeltaCRLNumber = null; // delta CRL number
    protected Long mDeltaCRLSize = null;
    protected String mFirstUnsaved = null;
    protected byte mCRL[] = null;
    protected byte mCACert[] = null;
    protected Hashtable mCRLCache = null;
    protected Hashtable mRevokedCerts = null;
    protected Hashtable mUnrevokedCerts = null;
    protected Hashtable mExpiredCerts = null;
    protected byte mDeltaCRL[] = null;
    protected static Vector<String> mNames = new Vector<String>();
    static {
        mNames.addElement(ATTR_ID);
        mNames.addElement(ATTR_CRL_NUMBER);
        mNames.addElement(ATTR_DELTA_NUMBER);
        mNames.addElement(ATTR_CRL_SIZE);
        mNames.addElement(ATTR_DELTA_SIZE);
        mNames.addElement(ATTR_THIS_UPDATE);
        mNames.addElement(ATTR_NEXT_UPDATE);
        mNames.addElement(ATTR_FIRST_UNSAVED);
        mNames.addElement(ATTR_CRL);
        mNames.addElement(ATTR_CA_CERT);
        mNames.addElement(ATTR_CRL_CACHE);
        mNames.addElement(ATTR_REVOKED_CERTS);
        mNames.addElement(ATTR_UNREVOKED_CERTS);
        mNames.addElement(ATTR_EXPIRED_CERTS);
        mNames.addElement(ATTR_DELTA_CRL);
    }

    /**
     * Constructs empty CRLIssuingPointRecord. This is
     * required in database framework.
     */
    public CRLIssuingPointRecord() {
    }

    /**
     * Constructs a CRLIssuingPointRecord
     */
    public CRLIssuingPointRecord(String id, BigInteger crlNumber, Long crlSize,
            Date thisUpdate, Date nextUpdate) {
        mId = id;
        mCRLNumber = crlNumber;
        mCRLSize = crlSize;
        mThisUpdate = thisUpdate;
        mNextUpdate = nextUpdate;
        mDeltaCRLNumber = BigInteger.ZERO;
        mFirstUnsaved = NEW_CACHE;
        mDeltaCRLSize = Long.valueOf(-1L);
        mCRLCache = null;
        mRevokedCerts = null;
        mUnrevokedCerts = null;
        mExpiredCerts = null;
    }

    /**
     * Constructs a CRLIssuingPointRecord
     */
    public CRLIssuingPointRecord(String id, BigInteger crlNumber, Long crlSize,
            Date thisUpdate, Date nextUpdate, BigInteger deltaCRLNumber, Long deltaCRLSize,
            Hashtable revokedCerts, Hashtable unrevokedCerts, Hashtable expiredCerts) {
        mId = id;
        mCRLNumber = crlNumber;
        mCRLSize = crlSize;
        mThisUpdate = thisUpdate;
        mNextUpdate = nextUpdate;
        mDeltaCRLNumber = deltaCRLNumber;
        mDeltaCRLSize = deltaCRLSize;
        mFirstUnsaved = NEW_CACHE;
        mCRLCache = null;
        mRevokedCerts = revokedCerts;
        mUnrevokedCerts = unrevokedCerts;
        mExpiredCerts = expiredCerts;
    }

    public void set(String name, Object obj) throws EBaseException {
        if (name.equalsIgnoreCase(ATTR_ID)) {
            mId = (String) obj;
        } else if (name.equalsIgnoreCase(ATTR_CRL_NUMBER)) {
            mCRLNumber = (BigInteger) obj;
        } else if (name.equalsIgnoreCase(ATTR_CRL_SIZE)) {
            mCRLSize = (Long) obj;
        } else if (name.equalsIgnoreCase(ATTR_THIS_UPDATE)) {
            mThisUpdate = (Date) obj;
        } else if (name.equalsIgnoreCase(ATTR_NEXT_UPDATE)) {
            mNextUpdate = (Date) obj;
        } else if (name.equalsIgnoreCase(ATTR_DELTA_NUMBER)) {
            mDeltaCRLNumber = (BigInteger) obj;
        } else if (name.equalsIgnoreCase(ATTR_DELTA_SIZE)) {
            mDeltaCRLSize = (Long) obj;
        } else if (name.equalsIgnoreCase(ATTR_FIRST_UNSAVED)) {
            mFirstUnsaved = (String) obj;
        } else if (name.equalsIgnoreCase(ATTR_CRL)) {
            mCRL = (byte[]) obj;
        } else if (name.equalsIgnoreCase(ATTR_CA_CERT)) {
            mCACert = (byte[]) obj;
        } else if (name.equalsIgnoreCase(ATTR_CRL_CACHE)) {
            mCRLCache = (Hashtable) obj;
        } else if (name.equalsIgnoreCase(ATTR_REVOKED_CERTS)) {
            mRevokedCerts = (Hashtable) obj;
        } else if (name.equalsIgnoreCase(ATTR_UNREVOKED_CERTS)) {
            mUnrevokedCerts = (Hashtable) obj;
        } else if (name.equalsIgnoreCase(ATTR_EXPIRED_CERTS)) {
            mExpiredCerts = (Hashtable) obj;
        } else if (name.equalsIgnoreCase(ATTR_DELTA_CRL)) {
            mDeltaCRL = (byte[]) obj;
        } else {
            throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", name));
        }
    }

    public Object get(String name) throws EBaseException {
        if (name.equalsIgnoreCase(ATTR_ID)) {
            return mId;
        } else if (name.equalsIgnoreCase(ATTR_CRL_NUMBER)) {
            return mCRLNumber;
        } else if (name.equalsIgnoreCase(ATTR_CRL_SIZE)) {
            return mCRLSize;
        } else if (name.equalsIgnoreCase(ATTR_THIS_UPDATE)) {
            return mThisUpdate;
        } else if (name.equalsIgnoreCase(ATTR_NEXT_UPDATE)) {
            return mNextUpdate;
        } else if (name.equalsIgnoreCase(ATTR_DELTA_NUMBER)) {
            return mDeltaCRLNumber;
        } else if (name.equalsIgnoreCase(ATTR_DELTA_SIZE)) {
            return mDeltaCRLSize;
        } else if (name.equalsIgnoreCase(ATTR_FIRST_UNSAVED)) {
            return mFirstUnsaved;
        } else if (name.equalsIgnoreCase(ATTR_CRL)) {
            return mCRL;
        } else if (name.equalsIgnoreCase(ATTR_CA_CERT)) {
            return mCACert;
        } else if (name.equalsIgnoreCase(ATTR_CRL_CACHE)) {
            return mCRLCache;
        } else if (name.equalsIgnoreCase(ATTR_REVOKED_CERTS)) {
            return mRevokedCerts;
        } else if (name.equalsIgnoreCase(ATTR_UNREVOKED_CERTS)) {
            return mUnrevokedCerts;
        } else if (name.equalsIgnoreCase(ATTR_EXPIRED_CERTS)) {
            return mExpiredCerts;
        } else if (name.equalsIgnoreCase(ATTR_DELTA_CRL)) {
            return mDeltaCRL;
        } else {
            throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", name));
        }
    }

    public void delete(String name) throws EBaseException {
        throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", name));
    }

    public Enumeration<String> getElements() {
        return mNames.elements();
    }

    public Enumeration<String> getSerializableAttrNames() {
        return mNames.elements();
    }

    /**
     * Retrieve unique CRL identifier.
     */
    public String getId() {
        return mId;
    }

    /**
     * Retrieves CRL number.
     */
    public BigInteger getCRLNumber() {
        return mCRLNumber;
    }

    /**
     * Retrieves CRL size.
     */
    public Long getCRLSize() {
        return mCRLSize;
    }

    /**
     * Retrieves this update time.
     */
    public Date getThisUpdate() {
        return mThisUpdate;
    }

    /**
     * Retrieves next update time.
     */
    public Date getNextUpdate() {
        return mNextUpdate;
    }

    /**
     * Retrieves delta CRL number.
     */
    public BigInteger getDeltaCRLNumber() {
        return mDeltaCRLNumber;
    }

    /**
     * Retrieves CRL size.
     */
    public Long getDeltaCRLSize() {
        return mDeltaCRLSize;
    }

    /**
     * Retrieve unique CRL identifier.
     */
    public String getFirstUnsaved() {
        return mFirstUnsaved;
    }

    /**
     * Retrieves CRL encodings.
     */
    public byte[] getCRL() {
        return mCRL;
    }

    /**
     * Retrieves CRL encodings.
     */
    public byte[] getDeltaCRL() {
        return mDeltaCRL;
    }

    public byte[] getCACert() {
        return mCACert;
    }

    public Hashtable getCRLCacheNoClone() {
        if (mCRLCache == null)
            return null;
        else
            return (Hashtable) mCRLCache;
    }

    public Hashtable getCRLCache() {
        if (mCRLCache == null)
            return null;
        else
            return (Hashtable) mCRLCache.clone();
    }

    /**
     * Retrieves cache info of revoked certificates.
     */
    public Hashtable getRevokedCerts() {
        if (mRevokedCerts == null)
            return null;
        else
            return (Hashtable) mRevokedCerts.clone();
    }

    /**
     * Retrieves cache info of unrevoked certificates.
     */
    public Hashtable getUnrevokedCerts() {
        if (mUnrevokedCerts == null)
            return null;
        else
            return (Hashtable) mUnrevokedCerts.clone();
    }

    /**
     * Retrieves cache info of expired certificates.
     */
    public Hashtable getExpiredCerts() {
        if (mExpiredCerts == null)
            return null;
        else
            return (Hashtable) mExpiredCerts.clone();
    }
}