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.5 2007/05/25 07:28:32 alexei.volkov.bugs%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
, SEC_IntegerTemplate
,
121 PORT_Free (encodedExtenValue
.data
);
122 if (rv
== SECFailure
) {
123 PORT_ArenaRelease(arena
, mark
);
125 PORT_ArenaUnmark(arena
, mark
);
130 SECStatus
CERT_FindCRLEntryReasonExten (CERTCrlEntry
*crlEntry
,
131 CERTCRLEntryReasonCode
*value
)
133 SECItem wrapperItem
= {siBuffer
,0};
134 SECItem tmpItem
= {siBuffer
,0};
136 PRArenaPool
*arena
= NULL
;
138 arena
= PORT_NewArena(DER_DEFAULT_CHUNKSIZE
);
143 rv
= cert_FindExtension(crlEntry
->extensions
, SEC_OID_X509_REASON_CODE
,
145 if ( rv
!= SECSuccess
) {
149 rv
= SEC_QuickDERDecodeItem(arena
, &tmpItem
, SEC_EnumeratedTemplate
,
152 if ( rv
!= SECSuccess
) {
156 *value
= (CERTCRLEntryReasonCode
) DER_GetInteger(&tmpItem
);
160 PORT_FreeArena(arena
, PR_FALSE
);
163 if ( wrapperItem
.data
) {
164 PORT_Free(wrapperItem
.data
);
170 SECStatus
CERT_FindInvalidDateExten (CERTCrl
*crl
, int64
*value
)
172 SECItem encodedExtenValue
;
173 SECItem decodedExtenValue
= {siBuffer
,0};
176 encodedExtenValue
.data
= decodedExtenValue
.data
= NULL
;
177 encodedExtenValue
.len
= decodedExtenValue
.len
= 0;
179 rv
= cert_FindExtension
180 (crl
->extensions
, SEC_OID_X509_INVALID_DATE
, &encodedExtenValue
);
181 if ( rv
!= SECSuccess
)
184 rv
= SEC_ASN1DecodeItem (NULL
, &decodedExtenValue
,
185 SEC_GeneralizedTimeTemplate
, &encodedExtenValue
);
186 if (rv
== SECSuccess
)
187 rv
= DER_GeneralizedTimeToTime(value
, &encodedExtenValue
);
188 PORT_Free (decodedExtenValue
.data
);
189 PORT_Free (encodedExtenValue
.data
);