/
CRLIssuingPoint.java
3376 lines (2928 loc) · 131 KB
/
CRLIssuingPoint.java
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// --- 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.ca;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.Vector;
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.base.IConfigStore;
import com.netscape.certsrv.base.ISubsystem;
import com.netscape.certsrv.base.SessionContext;
import com.netscape.certsrv.ca.ECAException;
import com.netscape.certsrv.ca.EErrorPublishCRL;
import com.netscape.certsrv.ca.ICMSCRLExtensions;
import com.netscape.certsrv.ca.ICRLIssuingPoint;
import com.netscape.certsrv.ca.ICertificateAuthority;
import com.netscape.certsrv.common.Constants;
import com.netscape.certsrv.common.NameValuePairs;
import com.netscape.certsrv.dbs.EDBNotAvailException;
import com.netscape.certsrv.dbs.IElementProcessor;
import com.netscape.certsrv.dbs.certdb.ICertRecord;
import com.netscape.certsrv.dbs.certdb.ICertRecordList;
import com.netscape.certsrv.dbs.certdb.ICertificateRepository;
import com.netscape.certsrv.dbs.certdb.IRevocationInfo;
import com.netscape.certsrv.dbs.crldb.ICRLIssuingPointRecord;
import com.netscape.certsrv.dbs.crldb.ICRLRepository;
import com.netscape.certsrv.logging.AuditFormat;
import com.netscape.certsrv.logging.ILogger;
import com.netscape.certsrv.logging.event.DeltaCRLGenerationEvent;
import com.netscape.certsrv.logging.event.DeltaCRLPublishingEvent;
import com.netscape.certsrv.logging.event.FullCRLGenerationEvent;
import com.netscape.certsrv.logging.event.FullCRLPublishingEvent;
import com.netscape.certsrv.publish.ILdapRule;
import com.netscape.certsrv.publish.IPublisherProcessor;
import com.netscape.certsrv.request.IRequest;
import com.netscape.certsrv.request.IRequestListener;
import com.netscape.certsrv.request.IRequestQueue;
import com.netscape.certsrv.request.IRequestVirtualList;
import com.netscape.certsrv.request.RequestId;
import com.netscape.certsrv.util.IStatsSubsystem;
import com.netscape.cms.logging.Logger;
import com.netscape.cms.logging.SignedAuditLogger;
import com.netscape.cmscore.dbs.CRLIssuingPointRecord;
import com.netscape.cmscore.dbs.CertRecord;
import com.netscape.cmscore.dbs.CertificateRepository;
import netscape.security.util.BitArray;
import netscape.security.x509.AlgorithmId;
import netscape.security.x509.CRLExtensions;
import netscape.security.x509.CRLNumberExtension;
import netscape.security.x509.CRLReasonExtension;
import netscape.security.x509.DeltaCRLIndicatorExtension;
import netscape.security.x509.Extension;
import netscape.security.x509.FreshestCRLExtension;
import netscape.security.x509.IssuingDistributionPoint;
import netscape.security.x509.IssuingDistributionPointExtension;
import netscape.security.x509.RevocationReason;
import netscape.security.x509.RevokedCertImpl;
import netscape.security.x509.RevokedCertificate;
import netscape.security.x509.X509CRLImpl;
import netscape.security.x509.X509CertImpl;
/**
* This class encapsulates CRL issuing mechanism. CertificateAuthority
* contains a map of CRLIssuingPoint indexed by string ids. Each issuing
* point contains information about CRL issuing and publishing parameters
* as well as state information which includes last issued CRL, next CRL
* serial number, time of the next update etc.
* If autoUpdateInterval is set to non-zero value then worker thread
* is created that will perform CRL update at scheduled intervals. Update
* can also be triggered by invoking updateCRL method directly. Another
* parameter minUpdateInterval can be used to prevent CRL
* from being updated too often
* <P>
*
* @author awnuk
* @author lhsiao
* @author galperin
* @version $Revision$, $Date$
*/
public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable {
public static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CRLIssuingPoint.class);
private static Logger systemLogger = Logger.getLogger(ILogger.EV_SYSTEM, ILogger.S_CA);
private static Logger transactionLogger = Logger.getLogger(ILogger.EV_AUDIT, ILogger.S_OTHER);
private static Logger signedAuditLogger = SignedAuditLogger.getLogger();
/* Foreign config param for IssuingDistributionPointExtension. */
public static final String PROP_CACERTS = "onlyContainsCACerts";
public static final long SECOND = 1000L;
public static final long MINUTE = (SECOND * 60L);
private static final int CRL_PAGE_SIZE = 10000;
private static final String PROP_CRL_STARTING_NUMBER = "startingCrlNumber";
/* configuration file property names */
public IPublisherProcessor mPublisherProcessor = null;
private IConfigStore mConfigStore;
private int mCountMod = 0;
private int mCount = 0;
private int mPageSize = CRL_PAGE_SIZE;
private CMSCRLExtensions mCMSCRLExtensions = null;
/**
* Internal unique id of this CRL issuing point.
*/
protected String mId = null;
/**
* Reference to the CertificateAuthority instance which owns this
* issuing point.
*/
protected ICertificateAuthority mCA = null;
/**
* Reference to the CRL repository maintained in CA.
*/
protected ICRLRepository mCRLRepository = null;
/**
* Reference to the cert repository maintained in CA.
*/
private ICertificateRepository mCertRepository = null;
/**
* Enable CRL issuing point.
*/
private boolean mEnable = true;
/**
* Description of the issuing point
*/
private String mDescription = null;
/**
* CRL cache
*/
private Hashtable<BigInteger, RevokedCertificate> mCRLCerts = new Hashtable<BigInteger, RevokedCertificate>();
private Hashtable<BigInteger, RevokedCertificate> mRevokedCerts = new Hashtable<BigInteger, RevokedCertificate>();
private Hashtable<BigInteger, RevokedCertificate> mUnrevokedCerts = new Hashtable<BigInteger, RevokedCertificate>();
private Hashtable<BigInteger, RevokedCertificate> mExpiredCerts = new Hashtable<BigInteger, RevokedCertificate>();
private boolean mIncludeExpiredCerts = false;
private boolean mIncludeExpiredCertsOneExtraTime = false;
private boolean mCACertsOnly = false;
private boolean mProfileCertsOnly = false;
private Vector<String> mProfileList = null;
/**
* Enable CRL cache.
*/
private boolean mEnableCRLCache = true;
private boolean mCRLCacheIsCleared = true;
private boolean mEnableCacheRecovery = false;
private String mFirstUnsaved = null;
private boolean mEnableCacheTesting = false;
/**
* Last CRL cache update
*/
private long mLastCacheUpdate = 0;
/**
* Time interval in milliseconds between consequential CRL cache
* updates performed automatically.
*/
private long mCacheUpdateInterval;
/**
* Enable CRL updates.
*/
private boolean mEnableCRLUpdates = true;
/**
* CRL update schema.
*/
private int mUpdateSchema = 1;
private int mSchemaCounter = 0;
/**
* Enable CRL daily updates at listed times.
*/
private boolean mEnableDailyUpdates = false;
private Vector<Vector<Integer>> mDailyUpdates = null;
private int mCurrentDay = 0;
private int mLastDay = 0;
private int mTimeListSize = 0;
private boolean mExtendedTimeList = false;
/**
* Enable CRL auto update with interval
*/
private boolean mEnableUpdateFreq = false;
/**
* Time interval in milliseconds between consequential CRL Enable CRL daily update at updates
* performed automatically.
*/
private long mAutoUpdateInterval;
/**
* Minimum time interval in milliseconds between consequential
* CRL updates (manual or automatic).
*/
private long mMinUpdateInterval;
/**
* Update CRL even if auto interval > 0
*/
private boolean mAlwaysUpdate = false;
/**
* next update grace period
*/
private long mNextUpdateGracePeriod;
/**
* time to wait at the next loop if exception happens during CRL generation
*/
private long mUnexpectedExceptionWaitTime;
/**
* Max number allowed to loop if exception happens during CRL generation.
* When mUnexpectedExceptionLoopMax is reached, a slow down procedure
* will be executed
*/
private int mUnexpectedExceptionLoopMax;
/**
* next update as this update extension
*/
private long mNextAsThisUpdateExtension;
/**
* Boolean flag controlling whether CRLv2 extensions are to be
* used in CRL.
*/
private boolean mAllowExtensions = false;
/**
* DN of the directory entry where CRLs from this issuing point
* are published.
*/
private String mPublishDN = null;
/**
* signing algorithm
*/
private String mSigningAlgorithm = null;
private String mLastSigningAlgorithm = null;
/**
* Cached value of the CRL extensions to be placed in CRL
*/
//protected CRLExtensions mCrlExtensions;
/**
* CRL number
*/
private BigInteger mCRLNumber;
private BigInteger mNextCRLNumber;
private BigInteger mLastCRLNumber;
/**
* Delta CRL number
*/
private BigInteger mDeltaCRLNumber;
private BigInteger mNextDeltaCRLNumber;
/**
* Last CRL update date
*/
private Date mLastUpdate;
private Date mLastFullUpdate;
/**
* Next scheduled CRL update date
*/
private Date mNextUpdate;
private Date mNextDeltaUpdate;
private boolean mExtendedNextUpdate;
/**
* Worker thread doing auto-update
*/
private Thread mUpdateThread = null;
/**
* for going one more round when auto-interval is set to 0 (turned off)
*/
private boolean mDoLastAutoUpdate = false;
/**
* whether issuing point has been initialized.
*/
private int mInitialized = CRL_IP_NOT_INITIALIZED;
/**
* number of entries in the CRL
*/
private long mCRLSize = -1;
private long mDeltaCRLSize = -1;
/**
* update status, publishing status Strings to store in requests to
* display result.
*/
private String mCrlUpdateStatus;
private String mCrlUpdateError;
private String mCrlPublishStatus;
private String mCrlPublishError;
/**
* begin, end serial number range of revoked certs if any.
*/
protected BigInteger mBeginSerial = null;
protected BigInteger mEndSerial = null;
private int mUpdatingCRL = CRL_UPDATE_DONE;
private boolean mDoManualUpdate = false;
private String mSignatureAlgorithmForManualUpdate = null;
private boolean mPublishOnStart = false;
private long[] mSplits = new long[10];
private boolean mSaveMemory = false;
/**
* Constructs a CRL issuing point from instantiating from class name.
* CRL Issuing point must be followed by method call init(CA, id, config);
*/
public CRLIssuingPoint() {
}
public boolean isCRLIssuingPointEnabled() {
return mEnable;
}
public void enableCRLIssuingPoint(boolean enable) {
if ((!enable) && (mEnable ^ enable)) {
clearCRLCache();
updateCRLCacheRepository();
}
mEnable = enable;
setAutoUpdates();
}
public boolean isCRLGenerationEnabled() {
return mEnableCRLUpdates;
}
public String getCrlUpdateStatusStr() {
return mCrlUpdateStatus;
}
public String getCrlUpdateErrorStr() {
return mCrlUpdateError;
}
public String getCrlPublishStatusStr() {
return mCrlPublishStatus;
}
public String getCrlPublishErrorStr() {
return mCrlPublishError;
}
public ICMSCRLExtensions getCRLExtensions() {
return mCMSCRLExtensions;
}
public int isCRLIssuingPointInitialized() {
return mInitialized;
}
public boolean isManualUpdateSet() {
return mDoManualUpdate;
}
public boolean areExpiredCertsIncluded() {
return mIncludeExpiredCerts;
}
public boolean isCACertsOnly() {
return mCACertsOnly;
}
public boolean isProfileCertsOnly() {
return (mProfileCertsOnly && mProfileList != null && mProfileList.size() > 0);
}
public boolean checkCurrentProfile(String id) {
boolean b = false;
if (mProfileCertsOnly && mProfileList != null && mProfileList.size() > 0) {
for (int k = 0; k < mProfileList.size(); k++) {
String profileId = mProfileList.elementAt(k);
if (id != null && profileId != null && profileId.equalsIgnoreCase(id)) {
b = true;
break;
}
}
}
return b;
}
/**
* Initializes a CRL issuing point config.
* <P>
*
* @param ca reference to CertificateAuthority instance which
* owns this issuing point.
* @param id string id of this CRL issuing point.
* @param config configuration of this CRL issuing point.
* @exception EBaseException if initialization failed
* @exception IOException
*/
public void init(ISubsystem ca, String id, IConfigStore config)
throws EBaseException {
mCA = (ICertificateAuthority) ca;
mId = id;
if (mId.equals(ICertificateAuthority.PROP_MASTER_CRL)) {
mCrlUpdateStatus = IRequest.CRL_UPDATE_STATUS;
mCrlUpdateError = IRequest.CRL_UPDATE_ERROR;
mCrlPublishStatus = IRequest.CRL_PUBLISH_STATUS;
mCrlPublishError = IRequest.CRL_PUBLISH_ERROR;
} else {
mCrlUpdateStatus = IRequest.CRL_UPDATE_STATUS + "_" + mId;
mCrlUpdateError = IRequest.CRL_UPDATE_ERROR + "_" + mId;
mCrlPublishStatus = IRequest.CRL_PUBLISH_STATUS + "_" + mId;
mCrlPublishError = IRequest.CRL_PUBLISH_ERROR + "_" + mId;
}
mConfigStore = config;
IConfigStore crlSubStore = mCA.getConfigStore().getSubStore(ICertificateAuthority.PROP_CRL_SUBSTORE);
mPageSize = crlSubStore.getInteger(ICertificateAuthority.PROP_CRL_PAGE_SIZE, CRL_PAGE_SIZE);
logger.debug("CRL Page Size: " + mPageSize);
mCountMod = config.getInteger("countMod", 0);
mCRLRepository = mCA.getCRLRepository();
mCertRepository = mCA.getCertificateRepository();
((CertificateRepository) mCertRepository).addCRLIssuingPoint(mId, this);
mPublisherProcessor = mCA.getPublisherProcessor();
//mCRLPublisher = mCA.getCRLPublisher();
((CAService) mCA.getCAService()).addCRLIssuingPoint(mId, this);
// read in config parameters.
initConfig(config);
// create request listener.
String lname = RevocationRequestListener.class.getName();
String crlListName = lname + "_" + mId;
if (mCA.getRequestListener(crlListName) == null) {
mCA.registerRequestListener(
crlListName, new RevocationRequestListener());
}
for (int i = 0; i < mSplits.length; i++) {
mSplits[i] = 0;
}
// this will start a thread if necessary for automatic updates.
setAutoUpdates();
}
private int checkTime(String time) {
String digits = "0123456789";
int len = time.length();
if (len < 3 || len > 5)
return -1;
int s = time.indexOf(':');
if (s < 0 || s > 2 || (len - s) != 3)
return -1;
int h = 0;
for (int i = 0; i < s; i++) {
h *= 10;
int k = digits.indexOf(time.charAt(i));
if (k < 0)
return -1;
h += k;
}
if (h > 23)
return -1;
int m = 0;
for (int i = s + 1; i < len; i++) {
m *= 10;
int k = digits.indexOf(time.charAt(i));
if (k < 0)
return -1;
m += k;
}
if (m > 59)
return -1;
return ((h * 60) + m);
}
private boolean areTimeListsIdentical(Vector<Vector<Integer>> list1, Vector<Vector<Integer>> list2) {
boolean identical = true;
if (list1 == null || list2 == null)
identical = false;
if (identical && list1.size() != list2.size())
identical = false;
for (int i = 0; identical && i < list1.size(); i++) {
Vector<Integer> times1 = list1.elementAt(i);
Vector<Integer> times2 = list2.elementAt(i);
if (times1.size() != times2.size())
identical = false;
for (int j = 0; identical && j < times1.size(); j++) {
if ((((times1.elementAt(j))).intValue()) != (((times2.elementAt(j))).intValue())) {
identical = false;
}
}
}
logger.debug("areTimeListsIdentical: identical: " + identical);
return identical;
}
private int getTimeListSize(Vector<Vector<Integer>> listedDays) {
int listSize = 0;
for (int i = 0; listedDays != null && i < listedDays.size(); i++) {
Vector<Integer> listedTimes = listedDays.elementAt(i);
listSize += ((listedTimes != null) ? listedTimes.size() : 0);
}
logger.debug("getTimeListSize: ListSize=" + listSize);
return listSize;
}
private boolean isTimeListExtended(String list) {
boolean extendedTimeList = true;
if (list == null || list.indexOf('*') == -1)
extendedTimeList = false;
return extendedTimeList;
}
private Vector<Vector<Integer>> getTimeList(String list) {
boolean timeListPresent = false;
if (list == null || list.length() == 0)
return null;
if (list.charAt(0) == ',' || list.charAt(list.length() - 1) == ',')
return null;
Vector<Vector<Integer>> listedDays = new Vector<Vector<Integer>>();
StringTokenizer days = new StringTokenizer(list, ";", true);
Vector<Integer> listedTimes = null;
while (days.hasMoreTokens()) {
String dayList = days.nextToken().trim();
if (dayList == null)
continue;
if (dayList.equals(";")) {
if (timeListPresent) {
timeListPresent = false;
} else {
listedTimes = new Vector<Integer>();
listedDays.addElement(listedTimes);
}
continue;
} else {
listedTimes = new Vector<Integer>();
listedDays.addElement(listedTimes);
timeListPresent = true;
}
int t0 = -1;
StringTokenizer times = new StringTokenizer(dayList, ",");
while (times.hasMoreTokens()) {
String time = times.nextToken();
int k = 1;
if (time.charAt(0) == '*') {
time = time.substring(1);
k = -1;
}
int t = checkTime(time);
if (t < 0) {
return null;
} else {
if (t > t0) {
listedTimes.addElement(Integer.valueOf(k * t));
t0 = t;
} else {
return null;
}
}
}
}
if (!timeListPresent) {
listedTimes = new Vector<Integer>();
listedDays.addElement(listedTimes);
}
return listedDays;
}
private String checkProfile(String id, Enumeration<String> e) {
if (e != null) {
while (e.hasMoreElements()) {
String profileId = e.nextElement();
if (profileId != null && profileId.equalsIgnoreCase(id))
return id;
}
}
return null;
}
private Vector<String> getProfileList(String list) {
Enumeration<String> e = null;
IConfigStore pc = CMS.getConfigStore().getSubStore("profile");
if (pc != null)
e = pc.getSubStoreNames();
if (list == null)
return null;
if (list.length() > 0 && list.charAt(list.length() - 1) == ',')
return null;
Vector<String> listedProfiles = new Vector<String>();
StringTokenizer elements = new StringTokenizer(list, ",", true);
int n = 0;
while (elements.hasMoreTokens()) {
String element = elements.nextToken().trim();
if (element == null || element.length() == 0)
return null;
if (element.equals(",") && n % 2 == 0)
return null;
if (n % 2 == 0) {
String id = checkProfile(element, e);
if (id != null) {
listedProfiles.addElement(id);
}
}
n++;
}
if (n % 2 == 0)
return null;
return listedProfiles;
}
/**
* get CRL config store info
*/
protected void initConfig(IConfigStore config)
throws EBaseException {
mEnable = config.getBoolean(Constants.PR_ENABLE, true);
mDescription = config.getString(Constants.PR_DESCRIPTION);
// Get CRL cache config.
mEnableCRLCache = config.getBoolean(Constants.PR_ENABLE_CACHE, true);
mCacheUpdateInterval = MINUTE * config.getInteger(Constants.PR_CACHE_FREQ, 0);
mEnableCacheRecovery = config.getBoolean(Constants.PR_CACHE_RECOVERY, false);
mEnableCacheTesting = config.getBoolean(Constants.PR_CACHE_TESTING, false);
// check if CRL generation is enabled
mEnableCRLUpdates = config.getBoolean(Constants.PR_ENABLE_CRL, true);
// get update schema
mUpdateSchema = config.getInteger(Constants.PR_UPDATE_SCHEMA, 1);
mSchemaCounter = 0;
// Get always update even if updated perdically.
mAlwaysUpdate = config.getBoolean(Constants.PR_UPDATE_ALWAYS, false);
// Get list of daily updates.
mEnableDailyUpdates = config.getBoolean(Constants.PR_ENABLE_DAILY, false);
String daily = config.getString(Constants.PR_DAILY_UPDATES, null);
mDailyUpdates = getTimeList(daily);
mExtendedTimeList = isTimeListExtended(daily);
mTimeListSize = getTimeListSize(mDailyUpdates);
if (mDailyUpdates == null || mDailyUpdates.isEmpty() || mTimeListSize == 0) {
mEnableDailyUpdates = false;
log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_INVALID_TIME_LIST"));
}
// Get auto update interval in minutes.
mEnableUpdateFreq = config.getBoolean(Constants.PR_ENABLE_FREQ, true);
mAutoUpdateInterval = MINUTE * config.getInteger(Constants.PR_UPDATE_FREQ, 0);
mMinUpdateInterval = MINUTE * config.getInteger(PROP_MIN_UPDATE_INTERVAL, 0);
if (mEnableUpdateFreq && mAutoUpdateInterval > 0 &&
mAutoUpdateInterval < mMinUpdateInterval)
mAutoUpdateInterval = mMinUpdateInterval;
// get next update grace period
mNextUpdateGracePeriod = MINUTE * config.getInteger(Constants.PR_GRACE_PERIOD, 0);
// get unexpected exception wait time; default to 30 minutes
mUnexpectedExceptionWaitTime = MINUTE * config.getInteger("unexpectedExceptionWaitTime", 30);
logger.debug("CRLIssuingPoint:initConfig: mUnexpectedExceptionWaitTime set to " + mUnexpectedExceptionWaitTime);
// get unexpected exception loop max; default to 10 times
mUnexpectedExceptionLoopMax = config.getInteger("unexpectedExceptionLoopMax", 10);
logger.debug("CRLIssuingPoint:initConfig: mUnexpectedExceptionLoopMax set to " + mUnexpectedExceptionLoopMax);
// get next update as this update extension
mNextAsThisUpdateExtension = MINUTE * config.getInteger(Constants.PR_NEXT_AS_THIS_EXTENSION, 0);
// Get V2 or V1 CRL
mAllowExtensions = config.getBoolean(Constants.PR_EXTENSIONS, false);
mIncludeExpiredCerts = config.getBoolean(Constants.PR_INCLUDE_EXPIREDCERTS, false);
mIncludeExpiredCertsOneExtraTime = config.getBoolean(Constants.PR_INCLUDE_EXPIREDCERTS_ONEEXTRATIME, false);
mCACertsOnly = config.getBoolean(Constants.PR_CA_CERTS_ONLY, false);
mProfileCertsOnly = config.getBoolean(Constants.PR_PROFILE_CERTS_ONLY, false);
if (mProfileCertsOnly) {
String profiles = config.getString(Constants.PR_PROFILE_LIST, null);
mProfileList = getProfileList(profiles);
}
// Get default signing algorithm.
// check if algorithm is supported.
mSigningAlgorithm = mCA.getCRLSigningUnit().getDefaultAlgorithm();
String algorithm = config.getString(Constants.PR_SIGNING_ALGORITHM, null);
if (algorithm != null) {
// make sure this algorithm is acceptable to CA.
mCA.getCRLSigningUnit().checkSigningAlgorithmFromName(algorithm);
mSigningAlgorithm = algorithm;
}
mPublishOnStart = config.getBoolean(PROP_PUBLISH_ON_START, false);
// if publish dn is null then certificate will be published to
// CA's entry in the directory.
mPublishDN = config.getString(PROP_PUBLISH_DN, null);
mSaveMemory = config.getBoolean("saveMemory", false);
mCMSCRLExtensions = new CMSCRLExtensions(this, config);
mExtendedNextUpdate =
((mUpdateSchema > 1 || (mEnableDailyUpdates && mExtendedTimeList)) && isDeltaCRLEnabled()) ?
config.getBoolean(Constants.PR_EXTENDED_NEXT_UPDATE, true) :
false;
// Get serial number ranges if any.
mBeginSerial = config.getBigInteger(PROP_BEGIN_SERIAL, null);
if (mBeginSerial != null && mBeginSerial.compareTo(BigInteger.ZERO) < 0) {
throw new EBaseException(
CMS.getUserMessage("CMS_BASE_INVALID_PROPERTY_1",
PROP_BEGIN_SERIAL, "BigInteger", "positive number"));
}
mEndSerial = config.getBigInteger(PROP_END_SERIAL, null);
if (mEndSerial != null && mEndSerial.compareTo(BigInteger.ZERO) < 0) {
throw new EBaseException(
CMS.getUserMessage("CMS_BASE_INVALID_PROPERTY_1",
PROP_END_SERIAL, "BigInteger", "positive number"));
}
}
/**
* Reads CRL issuing point, if missing, it creates one.
* Initializes CRL cache and republishes CRL if requested
* Called from auto update thread (run()).
* Do not call it from init(), because it will block CMS on start.
* @throws EBaseException
*/
private void initCRL() throws EBaseException {
ICRLIssuingPointRecord crlRecord = null;
mLastCacheUpdate = System.currentTimeMillis() + mCacheUpdateInterval;
try {
crlRecord = mCRLRepository.readCRLIssuingPointRecord(mId);
} catch (EDBNotAvailException e) {
log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_ISSUING_INST_CRL", e.toString()));
mInitialized = CRL_IP_INITIALIZATION_FAILED;
return;
} catch (EBaseException e) {
// CRL was never set.
// fall to the following..
}
if (crlRecord != null) {
mCRLNumber = crlRecord.getCRLNumber();
if (crlRecord.getCRLSize() != null) {
mCRLSize = crlRecord.getCRLSize().longValue();
}
mNextCRLNumber = mCRLNumber.add(BigInteger.ONE);
if (crlRecord.getDeltaCRLSize() != null) {
mDeltaCRLSize = crlRecord.getDeltaCRLSize().longValue();
}
mDeltaCRLNumber = crlRecord.getDeltaCRLNumber();
if (mDeltaCRLNumber == null) {
mDeltaCRLNumber = mCRLNumber; // better recovery later
} else {
if (mDeltaCRLNumber.compareTo(mCRLNumber) < 0) {
mDeltaCRLNumber = mCRLNumber;
clearCRLCache();
mDeltaCRLSize = -1L;
}
}
mNextDeltaCRLNumber = mDeltaCRLNumber.add(BigInteger.ONE);
if (mNextDeltaCRLNumber.compareTo(mNextCRLNumber) > 0) {
mNextCRLNumber = mNextDeltaCRLNumber;
}
mLastCRLNumber = BigInteger.ZERO;
mLastUpdate = crlRecord.getThisUpdate();
if (mLastUpdate == null) {
mLastUpdate = new Date(0L);
}
mLastFullUpdate = null;
mNextUpdate = crlRecord.getNextUpdate();
if (isDeltaCRLEnabled()) {
mNextDeltaUpdate = (mNextUpdate != null) ? new Date(mNextUpdate.getTime()) : null;
}
mFirstUnsaved = crlRecord.getFirstUnsaved();
logger.debug("initCRL CRLNumber=" + mCRLNumber.toString() + " CRLSize=" + mCRLSize +
" FirstUnsaved=" + mFirstUnsaved);
if (mFirstUnsaved == null ||
(mFirstUnsaved != null && mFirstUnsaved.equals(ICRLIssuingPointRecord.NEW_CACHE))) {
clearCRLCache();
updateCRLCacheRepository();
} else {
byte[] crl = crlRecord.getCRL();
if (crl != null) {
X509CRLImpl x509crl = null;
if (mEnableCRLCache || mPublishOnStart) {
try {
x509crl = new X509CRLImpl(crl);
} catch (Exception e) {
clearCRLCache();
log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_ISSUING_DECODE_CRL", e.toString()));
} catch (OutOfMemoryError e) {
clearCRLCache();
log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_ISSUING_DECODE_CRL", e.toString()));
mInitialized = CRL_IP_INITIALIZATION_FAILED;
return;
}
}
if (x509crl != null) {
mLastFullUpdate = x509crl.getThisUpdate();
if (mEnableCRLCache) {
if (mCRLCacheIsCleared && mUpdatingCRL == CRL_UPDATE_DONE) {
mRevokedCerts = crlRecord.getRevokedCerts();
if (mRevokedCerts == null) {
mRevokedCerts = new Hashtable<BigInteger, RevokedCertificate>();
}
mUnrevokedCerts = crlRecord.getUnrevokedCerts();
if (mUnrevokedCerts == null) {
mUnrevokedCerts = new Hashtable<BigInteger, RevokedCertificate>();
}
mExpiredCerts = crlRecord.getExpiredCerts();
if (mExpiredCerts == null) {
mExpiredCerts = new Hashtable<BigInteger, RevokedCertificate>();
}
if (isDeltaCRLEnabled()) {
mNextUpdate = x509crl.getNextUpdate();
}
mCRLCerts = x509crl.getListOfRevokedCertificates();
}
if (mFirstUnsaved != null && !mFirstUnsaved.equals(ICRLIssuingPointRecord.CLEAN_CACHE)) {
recoverCRLCache();
} else {
mCRLCacheIsCleared = false;
}
mInitialized = CRL_IP_INITIALIZED;
}
if (mPublishOnStart) {
try {
publishCRL(x509crl);
x509crl = null;
} catch (EBaseException e) {
x509crl = null;
log(ILogger.LL_FAILURE,
CMS.getLogMessage("CMSCORE_CA_ISSUING_PUBLISH_CRL", mCRLNumber.toString(),
e.toString()));
} catch (OutOfMemoryError e) {
x509crl = null;
log(ILogger.LL_FAILURE,
CMS.getLogMessage("CMSCORE_CA_ISSUING_PUBLISH_CRL", mCRLNumber.toString(),
e.toString()));
}
}
}
}
}
}
if (crlRecord == null) {
// no crl was ever created, or crl in db is corrupted.
// create new one.
IConfigStore ipStore = mCA.getConfigStore().getSubStore(ICertificateAuthority.PROP_CRL_SUBSTORE).getSubStore(mId);
try {
BigInteger startingCrlNumberBig = ipStore.getBigInteger(PROP_CRL_STARTING_NUMBER, BigInteger.ZERO);
logger.debug("startingCrlNumber: " + startingCrlNumberBig);
// Check for bogus negative value
if(startingCrlNumberBig.compareTo(BigInteger.ZERO) < 0) {
//Make it the default of ZERO
startingCrlNumberBig = BigInteger.ZERO;
}
crlRecord = new CRLIssuingPointRecord(mId, startingCrlNumberBig, Long.valueOf(-1),
null, null, BigInteger.ZERO, Long.valueOf(-1),
mRevokedCerts, mUnrevokedCerts, mExpiredCerts);
mCRLRepository.addCRLIssuingPointRecord(crlRecord);
mCRLNumber = startingCrlNumberBig;
// The default case calls for ZERO being the starting point where
// it is then incremented by one to ONE
// If we specificy an explicit starting point,
// We want that exact number to be the next CRL Number.
if(mCRLNumber.compareTo(BigInteger.ZERO) == 0) {
mNextCRLNumber = BigInteger.ONE;
} else {
mNextCRLNumber = mCRLNumber;
}
mLastCRLNumber = mCRLNumber;
mDeltaCRLNumber = mCRLNumber;
mNextDeltaCRLNumber = mNextCRLNumber;
mLastUpdate = new Date(0L);
if (crlRecord != null) {
// This will trigger updateCRLNow, which will also publish CRL.
if ((mDoManualUpdate == false) &&
(mEnableCRLCache || mAlwaysUpdate ||
(mEnableUpdateFreq && mAutoUpdateInterval > 0))) {
mInitialized = CRL_IP_INITIALIZED;
setManualUpdate(null);
}
}
} catch (EBaseException ex) {
log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_ISSUING_CREATE_CRL", ex.toString()));
mInitialized = CRL_IP_INITIALIZATION_FAILED;
return;
}
}
mInitialized = CRL_IP_INITIALIZED;
}
private Object configMonitor = new Object();
public boolean updateConfig(NameValuePairs params) {
synchronized (configMonitor) {
boolean noRestart = true;
boolean modifiedSchedule = false;
for (Map.Entry<String, String> entry : params.entrySet()) {
String name = entry.getKey();
String value = entry.getValue();
// -- Update Schema --
if (name.equals(Constants.PR_ENABLE_CRL)) {
if (value.equals(Constants.FALSE) && mEnableCRLUpdates) {
mEnableCRLUpdates = false;
modifiedSchedule = true;
} else if (value.equals(Constants.TRUE) && (!mEnableCRLUpdates)) {