2 * Copyright (c) 2005-2007,2010 Apple Inc. All Rights Reserved.
4 * parseCrl.c - parse a DER-encoded X509 CRL using libDER.
11 #include <libDER/libDER.h>
12 #include <libDER/asn1Types.h>
13 #include <libDER/DER_CertCrl.h>
14 #include <libDER/DER_Keys.h>
15 #include <libDERUtils/fileIo.h>
16 #include <libDERUtils/libDERUtils.h>
17 #include <libDERUtils/printFields.h>
19 static void usage(char **argv
)
21 printf("usage: %s crlFile [options]\n", argv
[0]);
23 printf(" -v -- verbose \n");
29 * This is a SEQUENCE OF so we use the low-level DERDecodeSeq* routines to snag one entry
32 static void printRevokedCerts(
33 DERItem
*revokedCerts
,
37 DERDecodedInfo currItem
;
40 DERRevokedCert revoked
;
42 drtn
= DERDecodeSeqContentInit(revokedCerts
, &seq
);
44 DERPerror("DERDecodeSeqContentInit(revokedCerts)", drtn
);
48 for(certNum
=0; ; certNum
++) {
49 drtn
= DERDecodeSeqNext(&seq
, &currItem
);
51 case DR_EndOfSequence
:
52 /* normal termination */
55 DERPerror("DERDecodeSeqNext", drtn
);
59 printf("revoked cert %u\n", certNum
);
61 drtn
= DERParseSequenceContent(&currItem
.content
,
62 DERNumRevokedCertItemSpecs
, DERRevokedCertItemSpecs
,
63 &revoked
, sizeof(revoked
));
65 DERPerror("DERParseSequenceContent(RevokedCert)", drtn
);
69 printItem("serialNum", IT_Leaf
, verbose
, ASN1_INTEGER
, &revoked
.serialNum
);
70 decodePrintItem("revocationDate", IT_Leaf
, verbose
, &revoked
.revocationDate
);
71 printItem("extensions", IT_Branch
, verbose
, ASN1_CONSTR_SEQUENCE
, &revoked
.extensions
);
77 int main(int argc
, char **argv
)
79 unsigned char *crlData
= NULL
;
80 unsigned crlDataLen
= 0;
81 DERSignedCertCrl signedCrl
;
93 if(readFile(argv
[1], &crlData
, &crlDataLen
)) {
94 printf("***Error reading CRL from %s. Aborting.\n", argv
[1]);
99 while ((arg
= getopt(argc
, argv
, "vh")) != -1) {
112 /* Top level decode of signed CRL into 3 components */
114 item
.length
= crlDataLen
;
115 drtn
= DERParseSequence(&item
, DERNumSignedCertCrlItemSpecs
, DERSignedCertCrlItemSpecs
,
116 &signedCrl
, sizeof(signedCrl
));
118 DERPerror("DERParseSequence(SignedCrl)", drtn
);
121 printItem("TBSCrl", IT_Branch
, verbose
, ASN1_CONSTR_SEQUENCE
, &signedCrl
.tbs
);
125 /* decode the TBSCrl - it was saved in full DER form */
126 drtn
= DERParseSequence(&signedCrl
.tbs
,
127 DERNumTBSCrlItemSpecs
, DERTBSCrlItemSpecs
,
130 DERPerror("DERParseSequenceContent(TBSCrl)", drtn
);
133 if(tbs
.version
.data
) {
134 printItem("version", IT_Leaf
, verbose
, ASN1_INTEGER
, &tbs
.version
);
137 printItem("tbsSigAlg", IT_Branch
, verbose
, ASN1_CONSTR_SEQUENCE
, &tbs
.tbsSigAlg
);
139 printAlgId(&tbs
.tbsSigAlg
, verbose
);
142 printItem("issuer", IT_Leaf
, verbose
, ASN1_CONSTR_SEQUENCE
, &tbs
.issuer
);
144 decodePrintItem("thisUpdate", IT_Leaf
, verbose
, &tbs
.thisUpdate
);
145 decodePrintItem("nextUpdate", IT_Leaf
, verbose
, &tbs
.nextUpdate
);
147 if(tbs
.revokedCerts
.data
) {
148 printItem("version", IT_Leaf
, verbose
, ASN1_CONSTR_SEQUENCE
, &tbs
.revokedCerts
);
150 printRevokedCerts(&tbs
.revokedCerts
, verbose
);
154 if(tbs
.extensions
.data
) {
155 printItem("extensions", IT_Leaf
, verbose
, ASN1_CONSTRUCTED
| ASN1_CONTEXT_SPECIFIC
| 3,
159 printItem("sigAlg", IT_Branch
, verbose
, ASN1_CONSTR_SEQUENCE
, &signedCrl
.sigAlg
);
161 printAlgId(&signedCrl
.sigAlg
, verbose
);
164 printItem("sig", IT_Leaf
, verbose
, ASN1_BIT_STRING
, &signedCrl
.sig
);