1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
38 * Code for dealing with x.509 v3 crl and crl entries extensions.
40 * $Id: crlv2.c,v 1.6 2007/10/12 01:44:41 julien.pierre.boogz%sun.com Exp $
52 CERT_FindCRLExtensionByOID(CERTCrl
*crl
, SECItem
*oid
, SECItem
*value
)
54 return (cert_FindExtensionByOID (crl
->extensions
, oid
, value
));
59 CERT_FindCRLExtension(CERTCrl
*crl
, int tag
, SECItem
*value
)
61 return (cert_FindExtension (crl
->extensions
, tag
, value
));
65 /* Callback to set extensions and adjust verison */
67 SetCrlExts(void *object
, CERTCertExtension
**exts
)
69 CERTCrl
*crl
= (CERTCrl
*)object
;
71 crl
->extensions
= exts
;
72 DER_SetUInteger (crl
->arena
, &crl
->version
, SEC_CRL_VERSION_2
);
76 CERT_StartCRLExtensions(CERTCrl
*crl
)
78 return (cert_StartExtensions ((void *)crl
, crl
->arena
, SetCrlExts
));
82 SetCrlEntryExts(void *object
, CERTCertExtension
**exts
)
84 CERTCrlEntry
*crlEntry
= (CERTCrlEntry
*)object
;
86 crlEntry
->extensions
= exts
;
90 CERT_StartCRLEntryExtensions(CERTCrl
*crl
, CERTCrlEntry
*entry
)
92 return (cert_StartExtensions (entry
, crl
->arena
, SetCrlEntryExts
));
95 SECStatus
CERT_FindCRLNumberExten (PRArenaPool
*arena
, CERTCrl
*crl
,
98 SECItem encodedExtenValue
;
99 SECItem
*tmpItem
= NULL
;
103 encodedExtenValue
.data
= NULL
;
104 encodedExtenValue
.len
= 0;
106 rv
= cert_FindExtension(crl
->extensions
, SEC_OID_X509_CRL_NUMBER
,
108 if ( rv
!= SECSuccess
)
111 mark
= PORT_ArenaMark(arena
);
113 tmpItem
= SECITEM_ArenaDupItem(arena
, &encodedExtenValue
);
115 rv
= SEC_QuickDERDecodeItem (arena
, value
,
116 SEC_ASN1_GET(SEC_IntegerTemplate
),
122 PORT_Free (encodedExtenValue
.data
);
123 if (rv
== SECFailure
) {
124 PORT_ArenaRelease(arena
, mark
);
126 PORT_ArenaUnmark(arena
, mark
);
131 SECStatus
CERT_FindCRLEntryReasonExten (CERTCrlEntry
*crlEntry
,
132 CERTCRLEntryReasonCode
*value
)
134 SECItem wrapperItem
= {siBuffer
,0};
135 SECItem tmpItem
= {siBuffer
,0};
137 PRArenaPool
*arena
= NULL
;
139 arena
= PORT_NewArena(DER_DEFAULT_CHUNKSIZE
);
144 rv
= cert_FindExtension(crlEntry
->extensions
, SEC_OID_X509_REASON_CODE
,
146 if ( rv
!= SECSuccess
) {
150 rv
= SEC_QuickDERDecodeItem(arena
, &tmpItem
,
151 SEC_ASN1_GET(SEC_EnumeratedTemplate
),
154 if ( rv
!= SECSuccess
) {
158 *value
= (CERTCRLEntryReasonCode
) DER_GetInteger(&tmpItem
);
162 PORT_FreeArena(arena
, PR_FALSE
);
165 if ( wrapperItem
.data
) {
166 PORT_Free(wrapperItem
.data
);
172 SECStatus
CERT_FindInvalidDateExten (CERTCrl
*crl
, int64
*value
)
174 SECItem encodedExtenValue
;
175 SECItem decodedExtenValue
= {siBuffer
,0};
178 encodedExtenValue
.data
= decodedExtenValue
.data
= NULL
;
179 encodedExtenValue
.len
= decodedExtenValue
.len
= 0;
181 rv
= cert_FindExtension
182 (crl
->extensions
, SEC_OID_X509_INVALID_DATE
, &encodedExtenValue
);
183 if ( rv
!= SECSuccess
)
186 rv
= SEC_ASN1DecodeItem (NULL
, &decodedExtenValue
,
187 SEC_ASN1_GET(SEC_GeneralizedTimeTemplate
),
189 if (rv
== SECSuccess
)
190 rv
= DER_GeneralizedTimeToTime(value
, &encodedExtenValue
);
191 PORT_Free (decodedExtenValue
.data
);
192 PORT_Free (encodedExtenValue
.data
);