Back to index

lightning-sunbird  0.9+nobinonly
crlv2.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /*
00038  * Code for dealing with x.509 v3 crl and crl entries extensions.
00039  *
00040  * $Id: crlv2.c,v 1.4 2005/06/30 20:53:57 wtchang%redhat.com Exp $
00041  */
00042 
00043 #include "cert.h"
00044 #include "secitem.h"
00045 #include "secoid.h"
00046 #include "secoidt.h"
00047 #include "secder.h"
00048 #include "secasn1.h"
00049 #include "certxutl.h"
00050 
00051 SECStatus
00052 CERT_FindCRLExtensionByOID(CERTCrl *crl, SECItem *oid, SECItem *value)
00053 {
00054     return (cert_FindExtensionByOID (crl->extensions, oid, value));
00055 }
00056     
00057 
00058 SECStatus
00059 CERT_FindCRLExtension(CERTCrl *crl, int tag, SECItem *value)
00060 {
00061     return (cert_FindExtension (crl->extensions, tag, value));
00062 }
00063 
00064 
00065 /* Callback to set extensions and adjust verison */
00066 static void
00067 SetCrlExts(void *object, CERTCertExtension **exts)
00068 {
00069     CERTCrl *crl = (CERTCrl *)object;
00070 
00071     crl->extensions = exts;
00072     DER_SetUInteger (crl->arena, &crl->version, SEC_CRL_VERSION_2);
00073 }
00074 
00075 void *
00076 CERT_StartCRLExtensions(CERTCrl *crl)
00077 {
00078     return (cert_StartExtensions ((void *)crl, crl->arena, SetCrlExts));
00079 }
00080 
00081 static void
00082 SetCrlEntryExts(void *object, CERTCertExtension **exts)
00083 {
00084     CERTCrlEntry *crlEntry = (CERTCrlEntry *)object;
00085 
00086     crlEntry->extensions = exts;
00087 }
00088 
00089 void *
00090 CERT_StartCRLEntryExtensions(CERTCrl *crl, CERTCrlEntry *entry)
00091 {
00092     return (cert_StartExtensions (entry, crl->arena, SetCrlEntryExts));
00093 }
00094 
00095 SECStatus CERT_FindCRLNumberExten (CERTCrl *crl, CERTCrlNumber *value)
00096 {
00097     SECItem encodedExtenValue;
00098     SECStatus rv;
00099 
00100     encodedExtenValue.data = NULL;
00101     encodedExtenValue.len = 0;
00102 
00103     rv = cert_FindExtension
00104         (crl->extensions, SEC_OID_X509_CRL_NUMBER, &encodedExtenValue);
00105     if ( rv != SECSuccess )
00106        return (rv);
00107 
00108     rv = SEC_ASN1DecodeItem (NULL, value, SEC_IntegerTemplate,
00109                           &encodedExtenValue);
00110     PORT_Free (encodedExtenValue.data);
00111     return (rv);
00112 }
00113 
00114 SECStatus CERT_FindCRLReasonExten (CERTCrl *crl, SECItem *value)
00115 {
00116     return (CERT_FindBitStringExtension
00117            (crl->extensions, SEC_OID_X509_REASON_CODE, value));    
00118 }
00119 
00120 SECStatus CERT_FindInvalidDateExten (CERTCrl *crl, int64 *value)
00121 {
00122     SECItem encodedExtenValue;
00123     SECItem decodedExtenValue = {siBuffer,0};
00124     SECStatus rv;
00125 
00126     encodedExtenValue.data = decodedExtenValue.data = NULL;
00127     encodedExtenValue.len = decodedExtenValue.len = 0;
00128 
00129     rv = cert_FindExtension
00130         (crl->extensions, SEC_OID_X509_INVALID_DATE, &encodedExtenValue);
00131     if ( rv != SECSuccess )
00132        return (rv);
00133 
00134     rv = SEC_ASN1DecodeItem (NULL, &decodedExtenValue,
00135                           SEC_GeneralizedTimeTemplate, &encodedExtenValue);
00136     if (rv == SECSuccess)
00137        rv = DER_GeneralizedTimeToTime(value, &encodedExtenValue);
00138     PORT_Free (decodedExtenValue.data);
00139     PORT_Free (encodedExtenValue.data);
00140     return (rv);
00141 }