| OLD | NEW |
| (Empty) |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
| 4 | |
| 5 /* | |
| 6 * Code for dealing with x.509 v3 crl and crl entries extensions. | |
| 7 * | |
| 8 * $Id: crlv2.c,v 1.7 2012/04/25 14:49:27 gerv%gerv.net Exp $ | |
| 9 */ | |
| 10 | |
| 11 #include "cert.h" | |
| 12 #include "secitem.h" | |
| 13 #include "secoid.h" | |
| 14 #include "secoidt.h" | |
| 15 #include "secder.h" | |
| 16 #include "secasn1.h" | |
| 17 #include "certxutl.h" | |
| 18 | |
| 19 SECStatus | |
| 20 CERT_FindCRLExtensionByOID(CERTCrl *crl, SECItem *oid, SECItem *value) | |
| 21 { | |
| 22 return (cert_FindExtensionByOID (crl->extensions, oid, value)); | |
| 23 } | |
| 24 | |
| 25 | |
| 26 SECStatus | |
| 27 CERT_FindCRLExtension(CERTCrl *crl, int tag, SECItem *value) | |
| 28 { | |
| 29 return (cert_FindExtension (crl->extensions, tag, value)); | |
| 30 } | |
| 31 | |
| 32 | |
| 33 /* Callback to set extensions and adjust verison */ | |
| 34 static void | |
| 35 SetCrlExts(void *object, CERTCertExtension **exts) | |
| 36 { | |
| 37 CERTCrl *crl = (CERTCrl *)object; | |
| 38 | |
| 39 crl->extensions = exts; | |
| 40 DER_SetUInteger (crl->arena, &crl->version, SEC_CRL_VERSION_2); | |
| 41 } | |
| 42 | |
| 43 void * | |
| 44 CERT_StartCRLExtensions(CERTCrl *crl) | |
| 45 { | |
| 46 return (cert_StartExtensions ((void *)crl, crl->arena, SetCrlExts)); | |
| 47 } | |
| 48 | |
| 49 static void | |
| 50 SetCrlEntryExts(void *object, CERTCertExtension **exts) | |
| 51 { | |
| 52 CERTCrlEntry *crlEntry = (CERTCrlEntry *)object; | |
| 53 | |
| 54 crlEntry->extensions = exts; | |
| 55 } | |
| 56 | |
| 57 void * | |
| 58 CERT_StartCRLEntryExtensions(CERTCrl *crl, CERTCrlEntry *entry) | |
| 59 { | |
| 60 return (cert_StartExtensions (entry, crl->arena, SetCrlEntryExts)); | |
| 61 } | |
| 62 | |
| 63 SECStatus CERT_FindCRLNumberExten (PRArenaPool *arena, CERTCrl *crl, | |
| 64 SECItem *value) | |
| 65 { | |
| 66 SECItem encodedExtenValue; | |
| 67 SECItem *tmpItem = NULL; | |
| 68 SECStatus rv; | |
| 69 void *mark = NULL; | |
| 70 | |
| 71 encodedExtenValue.data = NULL; | |
| 72 encodedExtenValue.len = 0; | |
| 73 | |
| 74 rv = cert_FindExtension(crl->extensions, SEC_OID_X509_CRL_NUMBER, | |
| 75 &encodedExtenValue); | |
| 76 if ( rv != SECSuccess ) | |
| 77 return (rv); | |
| 78 | |
| 79 mark = PORT_ArenaMark(arena); | |
| 80 | |
| 81 tmpItem = SECITEM_ArenaDupItem(arena, &encodedExtenValue); | |
| 82 if (tmpItem) { | |
| 83 rv = SEC_QuickDERDecodeItem (arena, value, | |
| 84 SEC_ASN1_GET(SEC_IntegerTemplate), | |
| 85 tmpItem); | |
| 86 } else { | |
| 87 rv = SECFailure; | |
| 88 } | |
| 89 | |
| 90 PORT_Free (encodedExtenValue.data); | |
| 91 if (rv == SECFailure) { | |
| 92 PORT_ArenaRelease(arena, mark); | |
| 93 } else { | |
| 94 PORT_ArenaUnmark(arena, mark); | |
| 95 } | |
| 96 return (rv); | |
| 97 } | |
| 98 | |
| 99 SECStatus CERT_FindCRLEntryReasonExten (CERTCrlEntry *crlEntry, | |
| 100 CERTCRLEntryReasonCode *value) | |
| 101 { | |
| 102 SECItem wrapperItem = {siBuffer,0}; | |
| 103 SECItem tmpItem = {siBuffer,0}; | |
| 104 SECStatus rv; | |
| 105 PRArenaPool *arena = NULL; | |
| 106 | |
| 107 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); | |
| 108 if ( ! arena ) { | |
| 109 return(SECFailure); | |
| 110 } | |
| 111 | |
| 112 rv = cert_FindExtension(crlEntry->extensions, SEC_OID_X509_REASON_CODE, | |
| 113 &wrapperItem); | |
| 114 if ( rv != SECSuccess ) { | |
| 115 goto loser; | |
| 116 } | |
| 117 | |
| 118 rv = SEC_QuickDERDecodeItem(arena, &tmpItem, | |
| 119 SEC_ASN1_GET(SEC_EnumeratedTemplate), | |
| 120 &wrapperItem); | |
| 121 | |
| 122 if ( rv != SECSuccess ) { | |
| 123 goto loser; | |
| 124 } | |
| 125 | |
| 126 *value = (CERTCRLEntryReasonCode) DER_GetInteger(&tmpItem); | |
| 127 | |
| 128 loser: | |
| 129 if ( arena ) { | |
| 130 PORT_FreeArena(arena, PR_FALSE); | |
| 131 } | |
| 132 | |
| 133 if ( wrapperItem.data ) { | |
| 134 PORT_Free(wrapperItem.data); | |
| 135 } | |
| 136 | |
| 137 return (rv); | |
| 138 } | |
| 139 | |
| 140 SECStatus CERT_FindInvalidDateExten (CERTCrl *crl, int64 *value) | |
| 141 { | |
| 142 SECItem encodedExtenValue; | |
| 143 SECItem decodedExtenValue = {siBuffer,0}; | |
| 144 SECStatus rv; | |
| 145 | |
| 146 encodedExtenValue.data = decodedExtenValue.data = NULL; | |
| 147 encodedExtenValue.len = decodedExtenValue.len = 0; | |
| 148 | |
| 149 rv = cert_FindExtension | |
| 150 (crl->extensions, SEC_OID_X509_INVALID_DATE, &encodedExtenValue); | |
| 151 if ( rv != SECSuccess ) | |
| 152 return (rv); | |
| 153 | |
| 154 rv = SEC_ASN1DecodeItem (NULL, &decodedExtenValue, | |
| 155 SEC_ASN1_GET(SEC_GeneralizedTimeTemplate), | |
| 156 &encodedExtenValue); | |
| 157 if (rv == SECSuccess) | |
| 158 rv = DER_GeneralizedTimeToTime(value, &encodedExtenValue); | |
| 159 PORT_Free (decodedExtenValue.data); | |
| 160 PORT_Free (encodedExtenValue.data); | |
| 161 return (rv); | |
| 162 } | |
| OLD | NEW |