1 /* $NetBSD: certificate.c,v 1.1.1.2 2010/03/08 02:14:20 lukem Exp $ */ 2 3 /* 4 * certificate.c 5 * "AuthenticationFramework" ASN.1 module encode/decode/extracting/matching/free C src. 6 * This file was generated by modified eSMACC compiler Sat Dec 11 11:22:49 2004 7 * The generated files are supposed to be compiled as a module for OpenLDAP Software 8 */ 9 10 #include "certificate.h" 11 12 BDecComponentCertificateTop( void* mem_op, GenBuf* b, void **v, AsnLen* bytesDecoded,int mode) { 13 AsnTag tag; 14 AsnLen elmtLen; 15 16 tag = BDecTag ( b, bytesDecoded ); 17 elmtLen = BDecLen ( b, bytesDecoded ); 18 if ( elmtLen <= 0 ) return (-1); 19 if ( tag != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE) ) { 20 return (-1); 21 } 22 23 return BDecComponentCertificate( mem_op, b, tag, elmtLen, (ComponentCertificate**)v,(AsnLen*)bytesDecoded, mode ); 24 } 25 26 void init_module_AuthenticationFramework() { 27 /* Register Certificate OID and its decoder */ 28 InstallOidDecoderMapping( "2.5.4.36", NULL, 29 GDecComponentCertificate, 30 BDecComponentCertificateTop, 31 ExtractingComponentCertificate, 32 MatchingComponentCertificate ); 33 InitAnyAuthenticationFramework(); 34 } 35 36 void InitAnyAuthenticationFramework() 37 { 38 AsnOid oid0 ={ 9, "\52\206\110\206\367\15\1\1\4" }; 39 AsnOid oid1 ={ 9, "\52\206\110\206\367\15\1\1\1" }; 40 AsnOid oid2 ={ 9, "\52\206\110\206\367\15\1\1\5" }; 41 AsnOid oid3 ={ 3, "\125\4\3" }; 42 AsnOid oid4 ={ 3, "\125\4\6" }; 43 AsnOid oid5 ={ 3, "\125\4\7" }; 44 AsnOid oid6 ={ 3, "\125\4\10" }; 45 AsnOid oid7 ={ 3, "\125\4\12" }; 46 AsnOid oid8 ={ 3, "\125\4\13" }; 47 AsnOid oid9 ={ 10, "\11\222\46\211\223\362\54\144\1\3" }; 48 AsnOid oid10 ={ 9, "\52\206\110\206\367\15\1\11\1" }; 49 AsnOid oid11 ={ 3, "\125\35\23" }; 50 AsnOid oid12 ={ 9, "\140\206\110\1\206\370\102\1\15" }; 51 AsnOid oid13 ={ 3, "\125\35\16" }; 52 AsnOid oid14 ={ 3, "\125\35\25" }; 53 AsnOid oid15 ={ 3, "\125\35\24" }; 54 AsnOid oid17 ={ 3, "\125\35\34" }; 55 56 57 InstallAnyByComponentOid (nullOid_ANY_ID, &oid0, sizeof (ComponentNull), (EncodeFcn)BEncAsnNull, (gser_decoder_func*)GDecComponentNull, (ber_tag_decoder_func*)BDecComponentNullTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentNull,(FreeFcn)FreeComponentNull, (PrintFcn)NULL); 58 59 InstallAnyByComponentOid (nullOid2_ANY_ID, &oid1, sizeof (ComponentNull), (EncodeFcn)BEncAsnNull, (gser_decoder_func*)GDecComponentNull, (ber_tag_decoder_func*)BDecComponentNullTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentNull,(FreeFcn)FreeComponentNull, (PrintFcn)NULL); 60 61 InstallAnyByComponentOid (nullOid3_ANY_ID, &oid2, sizeof (ComponentNull), (EncodeFcn)BEncAsnNull, (gser_decoder_func*)GDecComponentNull, (ber_tag_decoder_func*)BDecComponentNullTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentNull,(FreeFcn)FreeComponentNull, (PrintFcn)NULL); 62 63 InstallAnyByComponentOid (printableStringOid_ANY_ID, &oid3, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL); 64 65 InstallAnyByComponentOid (printableStringOid2_ANY_ID, &oid4, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL); 66 67 InstallAnyByComponentOid (printableStringOid3_ANY_ID, &oid5, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL); 68 69 InstallAnyByComponentOid (printableStringOid4_ANY_ID, &oid6, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL); 70 71 InstallAnyByComponentOid (printableStringOid5_ANY_ID, &oid7, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL); 72 73 InstallAnyByComponentOid (printableStringOid6_ANY_ID, &oid8, sizeof (ComponentPrintableString), (EncodeFcn)BEncPrintableString, (gser_decoder_func*)GDecComponentPrintableString, (ber_tag_decoder_func*)BDecComponentPrintableStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentPrintableString,(FreeFcn)FreeComponentPrintableString, (PrintFcn)NULL); 74 75 InstallAnyByComponentOid (printableStringOid7_ANY_ID, &oid9, sizeof (ComponentTeletexString), (EncodeFcn)BEncTeletexString, (gser_decoder_func*)GDecComponentTeletexString, (ber_tag_decoder_func*)BDecComponentTeletexStringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentTeletexString,(FreeFcn)FreeComponentTeletexString, (PrintFcn)NULL); 76 77 InstallAnyByComponentOid (iA5StringOid_ANY_ID, &oid10, sizeof (ComponentIA5String), (EncodeFcn)BEncIA5String, (gser_decoder_func*)GDecComponentIA5String, (ber_tag_decoder_func*)BDecComponentIA5StringTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentIA5String,(FreeFcn)FreeComponentIA5String, (PrintFcn)NULL); 78 79 InstallAnyByComponentOid (octetStringOid_ANY_ID, &oid11, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL); 80 81 InstallAnyByComponentOid (octetStringOid2_ANY_ID, &oid12, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL); 82 83 InstallAnyByComponentOid (octetStringOid3_ANY_ID, &oid13, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL); 84 85 InstallAnyByComponentOid (octetStringOid4_ANY_ID, &oid14, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL); 86 87 InstallAnyByComponentOid (octetStringOid5_ANY_ID, &oid15, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL); 88 89 InstallAnyByComponentOid (octetStringOid7_ANY_ID, &oid17, sizeof (ComponentOcts), (EncodeFcn)BEncAsnOcts, (gser_decoder_func*)GDecComponentOcts, (ber_tag_decoder_func*)BDecComponentOctsTag, (ExtractFcn)NULL,(MatchFcn)MatchingComponentOcts,(FreeFcn)FreeComponentOcts, (PrintFcn)NULL); 90 91 } /* InitAnyAuthenticationFramework */ 92 93 int 94 MatchingComponentAlgorithmIdentifier ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 95 int rc; 96 MatchingRule* mr; 97 98 if ( oid ) { 99 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 100 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 101 } 102 103 rc = 1; 104 rc = MatchingComponentOid ( oid, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_attr)->algorithm, (ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_assert)->algorithm ); 105 if ( rc != LDAP_COMPARE_TRUE ) 106 return rc; 107 rc = SetAnyTypeByComponentOid ((ComponentSyntaxInfo*)&((ComponentAlgorithmIdentifier*)csi_attr)->parameters, (&((ComponentAlgorithmIdentifier*)csi_attr)->algorithm)); 108 rc = MatchingComponentAnyDefinedBy ( oid, (ComponentAny*)&((ComponentAlgorithmIdentifier*)csi_attr)->parameters, (ComponentAny*)&((ComponentAlgorithmIdentifier*)csi_assert)->parameters); 109 if ( rc != LDAP_COMPARE_TRUE ) 110 return rc; 111 return LDAP_COMPARE_TRUE; 112 } /* BMatchingComponentAlgorithmIdentifier */ 113 114 void* 115 ExtractingComponentAlgorithmIdentifier ( void* mem_op, ComponentReference* cr, ComponentAlgorithmIdentifier *comp ) 116 { 117 118 if ( ( comp->algorithm.identifier.bv_val && strncmp(comp->algorithm.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->algorithm.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 119 if ( cr->cr_curr->ci_next == NULL ) 120 return &comp->algorithm; 121 else 122 return NULL; 123 } 124 if ( ( comp->parameters.identifier.bv_val && strncmp(comp->parameters.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->parameters.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 125 if ( cr->cr_curr->ci_next == NULL ) 126 return &comp->parameters; 127 else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) { 128 cr->cr_curr = cr->cr_curr->ci_next; 129 return &comp->parameters; 130 } else { 131 return NULL; 132 } 133 } 134 return NULL; 135 } /* ExtractingComponentAlgorithmIdentifier */ 136 137 int 138 BDecComponentAlgorithmIdentifier PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 139 void* mem_op _AND_ 140 GenBuf * b _AND_ 141 AsnTag tagId0 _AND_ 142 AsnLen elmtLen0 _AND_ 143 ComponentAlgorithmIdentifier **v _AND_ 144 AsnLen *bytesDecoded _AND_ 145 int mode) 146 { 147 int seqDone = FALSE; 148 AsnLen totalElmtsLen1 = 0; 149 AsnLen elmtLen1; 150 AsnTag tagId1; 151 int mandatoryElmtCount1 = 0; 152 int old_mode = mode; 153 int rc; 154 ComponentAlgorithmIdentifier *k, *t, c_temp; 155 156 157 if ( !(mode & DEC_ALLOC_MODE_1) ) { 158 memset(&c_temp,0,sizeof(c_temp)); 159 k = &c_temp; 160 } else 161 k = t = *v; 162 mode = DEC_ALLOC_MODE_2; 163 tagId1 = BDecTag (b, &totalElmtsLen1 ); 164 165 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) 166 { 167 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 168 rc = BDecComponentOid (mem_op, b, tagId1, elmtLen1, (&k->algorithm), &totalElmtsLen1, mode); 169 if ( rc != LDAP_SUCCESS ) return rc; 170 (&k->algorithm)->identifier.bv_val = (&k->algorithm)->id_buf; 171 (&k->algorithm)->identifier.bv_len = strlen("algorithm"); 172 strcpy( (&k->algorithm)->identifier.bv_val, "algorithm"); 173 if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0)) 174 seqDone = TRUE; 175 else 176 { 177 tagId1 = BufPeekByte (b); 178 if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID)) 179 { 180 BDecEoc (b, &totalElmtsLen1 ); 181 seqDone = TRUE; 182 } 183 } 184 } 185 else 186 return -1; 187 188 189 190 if (!seqDone) { 191 rc = SetAnyTypeByComponentOid ((&k->parameters), (&k->algorithm)); 192 rc = BDecComponentAnyDefinedBy (mem_op,b, (&k->parameters), &totalElmtsLen1, mode ); 193 if ( rc != LDAP_SUCCESS ) return rc; 194 (&k->parameters)->identifier.bv_val = (&k->parameters)->id_buf; 195 (&k->parameters)->identifier.bv_len = strlen("parameters"); 196 strcpy( (&k->parameters)->identifier.bv_val, "parameters"); 197 seqDone = TRUE; 198 if (elmtLen0 == INDEFINITE_LEN) 199 BDecEoc (b, &totalElmtsLen1 ); 200 else if (totalElmtsLen1 != elmtLen0) 201 return -1; 202 203 } 204 205 206 if (!seqDone) 207 return -1; 208 209 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 210 *v = t = (ComponentAlgorithmIdentifier*) CompAlloc( mem_op, sizeof(ComponentAlgorithmIdentifier) ); 211 if ( !t ) return -1; 212 *t = *k; 213 } 214 t->syntax = (Syntax*)NULL; 215 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 216 if ( !t->comp_desc ) { 217 free ( t ); 218 return -1; 219 } 220 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAlgorithmIdentifier ; 221 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAlgorithmIdentifier ; 222 t->comp_desc->cd_free = (comp_free_func*)NULL; 223 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAlgorithmIdentifier; 224 t->comp_desc->cd_type = ASN_COMPOSITE; 225 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 226 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAlgorithmIdentifier; 227 (*bytesDecoded) += totalElmtsLen1; 228 return LDAP_SUCCESS; 229 } /* BDecAlgorithmIdentifier*/ 230 231 int 232 GDecComponentAlgorithmIdentifier PARAMS (( mem_op,b, v, bytesDecoded, mode), 233 void* mem_op _AND_ 234 GenBuf * b _AND_ 235 ComponentAlgorithmIdentifier **v _AND_ 236 AsnLen *bytesDecoded _AND_ 237 int mode) 238 { 239 char* peek_head,*peek_head2; 240 int i, strLen,strLen2, rc, old_mode = mode; 241 ComponentAlgorithmIdentifier *k,*t, c_temp; 242 243 244 if ( !(mode & DEC_ALLOC_MODE_1) ) { 245 memset(&c_temp,0,sizeof(c_temp)); 246 k = &c_temp; 247 } else 248 k = t = *v; 249 mode = DEC_ALLOC_MODE_2; 250 *bytesDecoded = 0; 251 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 252 Asn1Error("Error during Reading { in encoded data"); 253 return LDAP_PROTOCOL_ERROR; 254 } 255 if(*peek_head != '{'){ 256 Asn1Error("Missing { in encoded data"); 257 return LDAP_PROTOCOL_ERROR; 258 } 259 260 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 261 Asn1Error("Error during Reading identifier"); 262 return LDAP_PROTOCOL_ERROR; 263 } 264 if ( strncmp( peek_head, "algorithm", strlen("algorithm") ) == 0 ) { 265 rc = GDecComponentOid (mem_op, b, (&k->algorithm), bytesDecoded, mode); 266 if ( rc != LDAP_SUCCESS ) return rc; 267 (&k->algorithm)->identifier.bv_val = peek_head; 268 (&k->algorithm)->identifier.bv_len = strLen; 269 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 270 Asn1Error("Error during Reading , "); 271 return LDAP_PROTOCOL_ERROR; 272 } 273 if(*peek_head != ','){ 274 Asn1Error("Missing , in encoding"); 275 return LDAP_PROTOCOL_ERROR; 276 } 277 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 278 Asn1Error("Error during Reading identifier"); 279 return LDAP_PROTOCOL_ERROR; 280 } 281 } 282 if ( strncmp( peek_head, "parameters", strlen("parameters") ) == 0 ) { 283 rc = rc = SetAnyTypeByComponentOid ((&k->parameters), (&k->algorithm)); 284 rc = GDecComponentAnyDefinedBy (mem_op, b, (&k->parameters), bytesDecoded, mode ); 285 if ( rc != LDAP_SUCCESS ) return rc; 286 (&k->parameters)->identifier.bv_val = peek_head; 287 (&k->parameters)->identifier.bv_len = strLen; 288 } 289 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { 290 Asn1Error("Error during Reading } in encoding"); 291 return LDAP_PROTOCOL_ERROR; 292 } 293 if(*peek_head != '}'){ 294 Asn1Error("Missing } in encoding"); 295 return LDAP_PROTOCOL_ERROR; 296 } 297 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 298 *v = t = (ComponentAlgorithmIdentifier*) CompAlloc( mem_op, sizeof(ComponentAlgorithmIdentifier) ); 299 if ( !t ) return -1; 300 *t = *k; 301 } 302 t->syntax = (Syntax*)NULL; 303 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 304 if ( !t->comp_desc ) { 305 free ( t ); 306 return -1; 307 } 308 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAlgorithmIdentifier ; 309 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAlgorithmIdentifier ; 310 t->comp_desc->cd_free = (comp_free_func*)NULL; 311 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAlgorithmIdentifier; 312 t->comp_desc->cd_type = ASN_COMPOSITE; 313 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 314 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAlgorithmIdentifier; 315 return LDAP_SUCCESS; 316 } /* GDecAlgorithmIdentifier*/ 317 318 319 int 320 MatchingComponentTime ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 321 int rc; 322 MatchingRule* mr; 323 ComponentTime *v1, *v2; 324 325 326 v1 = (ComponentTime*)csi_attr; 327 v2 = (ComponentTime*)csi_assert; 328 if ( oid ) { 329 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 330 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 331 } 332 333 if( (v1->choiceId != v2->choiceId ) ) 334 return LDAP_COMPARE_FALSE; 335 switch( v1->choiceId ) 336 { 337 case TIME_UTCTIME : 338 rc = MatchingComponentUTCTime ( oid, (ComponentSyntaxInfo*)(v1->a.utcTime), (ComponentSyntaxInfo*)(v2->a.utcTime) ); 339 break; 340 case TIME_GENERALIZEDTIME : 341 rc = MatchingComponentGeneralizedTime ( oid, (ComponentSyntaxInfo*)(v1->a.generalizedTime), (ComponentSyntaxInfo*)(v2->a.generalizedTime) ); 342 break; 343 default : 344 return LDAP_PROTOCOL_ERROR; 345 } 346 return rc; 347 } /* BMatchingComponentTimeContent */ 348 349 void* 350 ExtractingComponentTime ( void* mem_op, ComponentReference* cr, ComponentTime *comp ) 351 { 352 353 354 if( (comp->choiceId) == TIME_UTCTIME && 355 (( comp->a.utcTime->identifier.bv_val && strncmp(comp->a.utcTime->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || 356 ( strncmp(comp->a.utcTime->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) { 357 if ( cr->cr_curr->ci_next == NULL ) 358 return (comp->a.utcTime); 359 else { 360 cr->cr_curr = cr->cr_curr->ci_next; 361 return ExtractingComponentUTCTime ( mem_op, cr, (comp->a.utcTime) ); 362 }; 363 } 364 if( (comp->choiceId) == TIME_GENERALIZEDTIME && 365 (( comp->a.generalizedTime->identifier.bv_val && strncmp(comp->a.generalizedTime->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || 366 ( strncmp(comp->a.generalizedTime->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) { 367 if ( cr->cr_curr->ci_next == NULL ) 368 return (comp->a.generalizedTime); 369 else { 370 cr->cr_curr = cr->cr_curr->ci_next; 371 return ExtractingComponentGeneralizedTime ( mem_op, cr, (comp->a.generalizedTime) ); 372 }; 373 } 374 return NULL; 375 } /* ExtractingComponentTime */ 376 377 int 378 BDecComponentTime PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 379 void* mem_op _AND_ 380 GenBuf * b _AND_ 381 AsnTag tagId0 _AND_ 382 AsnLen elmtLen0 _AND_ 383 ComponentTime **v _AND_ 384 AsnLen *bytesDecoded _AND_ 385 int mode) 386 { 387 int seqDone = FALSE; 388 AsnLen totalElmtsLen1 = 0; 389 AsnLen elmtLen1; 390 AsnTag tagId1; 391 int mandatoryElmtCount1 = 0; 392 int old_mode = mode; 393 int rc; 394 ComponentTime *k, *t, c_temp; 395 396 397 if ( !(mode & DEC_ALLOC_MODE_1) ) { 398 memset(&c_temp,0,sizeof(c_temp)); 399 k = &c_temp; 400 } else 401 k = t = *v; 402 mode = DEC_ALLOC_MODE_2; 403 switch (tagId0) 404 { 405 case MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE): 406 case MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE): 407 (k->choiceId) = TIME_UTCTIME; 408 rc = BDecComponentUTCTime (mem_op, b, tagId0, elmtLen0, (&k->a.utcTime), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); 409 if ( rc != LDAP_SUCCESS ) return rc; 410 (k->a.utcTime)->identifier.bv_val = (k->a.utcTime)->id_buf; 411 (k->a.utcTime)->identifier.bv_len = strlen("utcTime"); 412 strcpy( (k->a.utcTime)->identifier.bv_val, "utcTime"); 413 break; 414 415 case MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE): 416 case MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE): 417 (k->choiceId) = TIME_GENERALIZEDTIME; 418 rc = BDecComponentGeneralizedTime (mem_op, b, tagId0, elmtLen0, (&k->a.generalizedTime), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); 419 if ( rc != LDAP_SUCCESS ) return rc; 420 (k->a.generalizedTime)->identifier.bv_val = (k->a.generalizedTime)->id_buf; 421 (k->a.generalizedTime)->identifier.bv_len = strlen("generalizedTime"); 422 strcpy( (k->a.generalizedTime)->identifier.bv_val, "generalizedTime"); 423 break; 424 425 default: 426 Asn1Error ("ERROR - unexpected tag in CHOICE\n"); 427 return -1; 428 break; 429 } /* end switch */ 430 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 431 *v = t = (ComponentTime*) CompAlloc( mem_op, sizeof(ComponentTime) ); 432 if ( !t ) return -1; 433 *t = *k; 434 } 435 t->syntax = (Syntax*)NULL; 436 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 437 if ( !t->comp_desc ) { 438 free ( t ); 439 return -1; 440 } 441 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTime ; 442 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTime ; 443 t->comp_desc->cd_free = (comp_free_func*)NULL; 444 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTime; 445 t->comp_desc->cd_type = ASN_COMPOSITE; 446 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 447 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTime; 448 (*bytesDecoded) += totalElmtsLen1; 449 return LDAP_SUCCESS; 450 } /* BDecTimeContent */ 451 452 int 453 GDecComponentTime PARAMS (( mem_op,b, v, bytesDecoded, mode), 454 void* mem_op _AND_ 455 GenBuf * b _AND_ 456 ComponentTime **v _AND_ 457 AsnLen *bytesDecoded _AND_ 458 int mode) 459 { 460 char* peek_head,*peek_head2; 461 int i, strLen,strLen2, rc, old_mode = mode; 462 ComponentTime *k,*t, c_temp; 463 464 465 if ( !(mode & DEC_ALLOC_MODE_1) ) { 466 memset(&c_temp,0,sizeof(c_temp)); 467 k = &c_temp; 468 } else 469 k = t = *v; 470 mode = DEC_ALLOC_MODE_2; 471 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 472 Asn1Error("Error during Reading identifier"); 473 return LDAP_PROTOCOL_ERROR; 474 } 475 if( !(strLen2 = LocateNextGSERToken(mem_op,b,&peek_head2,GSER_NO_COPY)) ){ 476 Asn1Error("Error during Reading identifier"); 477 return LDAP_PROTOCOL_ERROR; 478 } 479 if(*peek_head2 != ':'){ 480 Asn1Error("Missing : in encoded data"); 481 return LDAP_PROTOCOL_ERROR; 482 } 483 if( strncmp("utcTime",peek_head, strlen("utcTime")) == 0){ 484 (k->choiceId) = TIME_UTCTIME; 485 rc = GDecComponentUTCTime (mem_op, b, (&k->a.utcTime), bytesDecoded, DEC_ALLOC_MODE_0 ); 486 if ( rc != LDAP_SUCCESS ) return rc; 487 (k->a.utcTime)->identifier.bv_val = peek_head; 488 (k->a.utcTime)->identifier.bv_len = strLen; 489 } 490 else if( strncmp("generalizedTime",peek_head,strlen("generalizedTime")) == 0){ 491 (k->choiceId) = TIME_GENERALIZEDTIME; 492 rc = GDecComponentGeneralizedTime (mem_op, b, (&k->a.generalizedTime), bytesDecoded, DEC_ALLOC_MODE_0 ); 493 if ( rc != LDAP_SUCCESS ) return rc; 494 (k->a.generalizedTime)->identifier.bv_val = peek_head; 495 (k->a.generalizedTime)->identifier.bv_len = strLen; 496 } 497 else { 498 Asn1Error("Undefined Identifier"); 499 return LDAP_PROTOCOL_ERROR; 500 } 501 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 502 *v = t = (ComponentTime*) CompAlloc( mem_op, sizeof(ComponentTime) ); 503 if ( !t ) return -1; 504 *t = *k; 505 } 506 t->syntax = (Syntax*)NULL; 507 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 508 if ( !t->comp_desc ) { 509 free ( t ); 510 return -1; 511 } 512 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTime ; 513 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTime ; 514 t->comp_desc->cd_free = (comp_free_func*)NULL; 515 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTime; 516 t->comp_desc->cd_type = ASN_COMPOSITE; 517 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 518 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTime; 519 return LDAP_SUCCESS; 520 } /* GDecTimeContent */ 521 522 523 int 524 MatchingComponentExtension ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 525 int rc; 526 MatchingRule* mr; 527 528 if ( oid ) { 529 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 530 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 531 } 532 533 rc = 1; 534 rc = MatchingComponentOid ( oid, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_attr)->extnID, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_assert)->extnID ); 535 if ( rc != LDAP_COMPARE_TRUE ) 536 return rc; 537 rc = MatchingComponentBool ( oid, (ComponentSyntaxInfo*)((ComponentExtension*)csi_attr)->critical, (ComponentSyntaxInfo*)((ComponentExtension*)csi_assert)->critical ); 538 if ( rc != LDAP_COMPARE_TRUE ) 539 return rc; 540 rc = MatchingComponentOcts ( oid, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_attr)->extnValue, (ComponentSyntaxInfo*)&((ComponentExtension*)csi_assert)->extnValue ); 541 if ( rc != LDAP_COMPARE_TRUE ) 542 return rc; 543 return LDAP_COMPARE_TRUE; 544 } /* BMatchingComponentExtension */ 545 546 void* 547 ExtractingComponentExtension ( void* mem_op, ComponentReference* cr, ComponentExtension *comp ) 548 { 549 550 if ( ( comp->extnID.identifier.bv_val && strncmp(comp->extnID.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extnID.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 551 if ( cr->cr_curr->ci_next == NULL ) 552 return &comp->extnID; 553 else 554 return NULL; 555 } 556 if ( ( comp->critical->identifier.bv_val && strncmp(comp->critical->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->critical->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 557 if ( cr->cr_curr->ci_next == NULL ) 558 return comp->critical; 559 else { 560 cr->cr_curr = cr->cr_curr->ci_next; 561 return ExtractingComponentBool ( mem_op, cr, comp->critical ); 562 } 563 } 564 if ( ( comp->extnValue.identifier.bv_val && strncmp(comp->extnValue.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extnValue.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 565 if ( cr->cr_curr->ci_next == NULL ) 566 return &comp->extnValue; 567 else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) { 568 cr->cr_curr = cr->cr_curr->ci_next; 569 return &comp->extnValue; 570 } else { 571 return NULL; 572 } 573 } 574 return NULL; 575 } /* ExtractingComponentExtension */ 576 577 int 578 BDecComponentExtension PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 579 void* mem_op _AND_ 580 GenBuf * b _AND_ 581 AsnTag tagId0 _AND_ 582 AsnLen elmtLen0 _AND_ 583 ComponentExtension **v _AND_ 584 AsnLen *bytesDecoded _AND_ 585 int mode) 586 { 587 int seqDone = FALSE; 588 AsnLen totalElmtsLen1 = 0; 589 AsnLen elmtLen1; 590 AsnTag tagId1; 591 int mandatoryElmtCount1 = 0; 592 int old_mode = mode; 593 int rc; 594 ComponentExtension *k, *t, c_temp; 595 596 597 if ( !(mode & DEC_ALLOC_MODE_1) ) { 598 memset(&c_temp,0,sizeof(c_temp)); 599 k = &c_temp; 600 } else 601 k = t = *v; 602 mode = DEC_ALLOC_MODE_2; 603 tagId1 = BDecTag (b, &totalElmtsLen1 ); 604 605 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) 606 { 607 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 608 rc = BDecComponentOid (mem_op, b, tagId1, elmtLen1, (&k->extnID), &totalElmtsLen1, mode); 609 if ( rc != LDAP_SUCCESS ) return rc; 610 (&k->extnID)->identifier.bv_val = (&k->extnID)->id_buf; 611 (&k->extnID)->identifier.bv_len = strlen("extnID"); 612 strcpy( (&k->extnID)->identifier.bv_val, "extnID"); 613 tagId1 = BDecTag (b, &totalElmtsLen1); 614 } 615 else 616 return -1; 617 618 619 620 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BOOLEAN_TAG_CODE)))) 621 { 622 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 623 rc = BDecComponentBool (mem_op, b, tagId1, elmtLen1, (&k->critical), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); 624 if ( rc != LDAP_SUCCESS ) return rc; 625 (k->critical)->identifier.bv_val = (k->critical)->id_buf; 626 (k->critical)->identifier.bv_len = strlen("critical"); 627 strcpy( (k->critical)->identifier.bv_val, "critical"); 628 tagId1 = BDecTag (b, &totalElmtsLen1); 629 } 630 631 632 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OCTETSTRING_TAG_CODE)) || 633 (tagId1 == MAKE_TAG_ID (UNIV, CONS, OCTETSTRING_TAG_CODE)))) 634 { 635 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 636 rc = BDecComponentOcts (mem_op, b, tagId1, elmtLen1, (&k->extnValue), &totalElmtsLen1, mode); 637 if ( rc != LDAP_SUCCESS ) return rc; 638 (&k->extnValue)->identifier.bv_val = (&k->extnValue)->id_buf; 639 (&k->extnValue)->identifier.bv_len = strlen("extnValue"); 640 strcpy( (&k->extnValue)->identifier.bv_val, "extnValue"); 641 seqDone = TRUE; 642 if (elmtLen0 == INDEFINITE_LEN) 643 BDecEoc (b, &totalElmtsLen1 ); 644 else if (totalElmtsLen1 != elmtLen0) 645 return -1; 646 647 } 648 else 649 return -1; 650 651 652 653 if (!seqDone) 654 return -1; 655 656 if(!COMPONENTNOT_NULL ((k->critical))) 657 { 658 (k->critical) = CompAlloc( mem_op, sizeof(ComponentBool)); 659 (k->critical)->identifier.bv_val = (k->critical)->id_buf; 660 (k->critical)->identifier.bv_len = strlen("critical"); 661 strcpy( (k->critical)->identifier.bv_val, "critical"); 662 (k->critical)->value = 0; 663 } 664 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 665 *v = t = (ComponentExtension*) CompAlloc( mem_op, sizeof(ComponentExtension) ); 666 if ( !t ) return -1; 667 *t = *k; 668 } 669 t->syntax = (Syntax*)NULL; 670 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 671 if ( !t->comp_desc ) { 672 free ( t ); 673 return -1; 674 } 675 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtension ; 676 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtension ; 677 t->comp_desc->cd_free = (comp_free_func*)NULL; 678 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtension; 679 t->comp_desc->cd_type = ASN_COMPOSITE; 680 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 681 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtension; 682 (*bytesDecoded) += totalElmtsLen1; 683 return LDAP_SUCCESS; 684 } /* BDecExtension*/ 685 686 int 687 GDecComponentExtension PARAMS (( mem_op,b, v, bytesDecoded, mode), 688 void* mem_op _AND_ 689 GenBuf * b _AND_ 690 ComponentExtension **v _AND_ 691 AsnLen *bytesDecoded _AND_ 692 int mode) 693 { 694 char* peek_head,*peek_head2; 695 int i, strLen,strLen2, rc, old_mode = mode; 696 ComponentExtension *k,*t, c_temp; 697 698 699 if ( !(mode & DEC_ALLOC_MODE_1) ) { 700 memset(&c_temp,0,sizeof(c_temp)); 701 k = &c_temp; 702 } else 703 k = t = *v; 704 mode = DEC_ALLOC_MODE_2; 705 *bytesDecoded = 0; 706 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 707 Asn1Error("Error during Reading { in encoded data"); 708 return LDAP_PROTOCOL_ERROR; 709 } 710 if(*peek_head != '{'){ 711 Asn1Error("Missing { in encoded data"); 712 return LDAP_PROTOCOL_ERROR; 713 } 714 715 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 716 Asn1Error("Error during Reading identifier"); 717 return LDAP_PROTOCOL_ERROR; 718 } 719 if ( strncmp( peek_head, "extnID", strlen("extnID") ) == 0 ) { 720 rc = GDecComponentOid (mem_op, b, (&k->extnID), bytesDecoded, mode); 721 if ( rc != LDAP_SUCCESS ) return rc; 722 (&k->extnID)->identifier.bv_val = peek_head; 723 (&k->extnID)->identifier.bv_len = strLen; 724 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 725 Asn1Error("Error during Reading , "); 726 return LDAP_PROTOCOL_ERROR; 727 } 728 if(*peek_head != ','){ 729 Asn1Error("Missing , in encoding"); 730 return LDAP_PROTOCOL_ERROR; 731 } 732 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 733 Asn1Error("Error during Reading identifier"); 734 return LDAP_PROTOCOL_ERROR; 735 } 736 } 737 if ( strncmp( peek_head, "critical", strlen("critical") ) == 0 ) { 738 rc = GDecComponentBool (mem_op, b, (&k->critical), bytesDecoded, DEC_ALLOC_MODE_0 ); 739 if ( rc != LDAP_SUCCESS ) return rc; 740 ( k->critical)->identifier.bv_val = peek_head; 741 ( k->critical)->identifier.bv_len = strLen; 742 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 743 Asn1Error("Error during Reading , "); 744 return LDAP_PROTOCOL_ERROR; 745 } 746 if(*peek_head != ','){ 747 Asn1Error("Missing , in encoding"); 748 return LDAP_PROTOCOL_ERROR; 749 } 750 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 751 Asn1Error("Error during Reading identifier"); 752 return LDAP_PROTOCOL_ERROR; 753 } 754 } 755 else { 756 (k->critical) = CompAlloc( mem_op, sizeof(ComponentBool)); 757 (k->critical)->value = 0; 758 } 759 if ( strncmp( peek_head, "extnValue", strlen("extnValue") ) == 0 ) { 760 rc = GDecComponentOcts (mem_op, b, (&k->extnValue), bytesDecoded, mode); 761 if ( rc != LDAP_SUCCESS ) return rc; 762 (&k->extnValue)->identifier.bv_val = peek_head; 763 (&k->extnValue)->identifier.bv_len = strLen; 764 } 765 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { 766 Asn1Error("Error during Reading } in encoding"); 767 return LDAP_PROTOCOL_ERROR; 768 } 769 if(*peek_head != '}'){ 770 Asn1Error("Missing } in encoding"); 771 return LDAP_PROTOCOL_ERROR; 772 } 773 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 774 *v = t = (ComponentExtension*) CompAlloc( mem_op, sizeof(ComponentExtension) ); 775 if ( !t ) return -1; 776 *t = *k; 777 } 778 t->syntax = (Syntax*)NULL; 779 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 780 if ( !t->comp_desc ) { 781 free ( t ); 782 return -1; 783 } 784 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtension ; 785 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtension ; 786 t->comp_desc->cd_free = (comp_free_func*)NULL; 787 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtension; 788 t->comp_desc->cd_type = ASN_COMPOSITE; 789 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 790 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtension; 791 return LDAP_SUCCESS; 792 } /* GDecExtension*/ 793 794 795 int 796 MatchingComponentAttributeTypeAndValue ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 797 int rc; 798 MatchingRule* mr; 799 800 if ( oid ) { 801 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 802 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 803 } 804 805 rc = 1; 806 rc = MatchingComponentAttributeType ( oid, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_attr)->type, (ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_assert)->type ); 807 if ( rc != LDAP_COMPARE_TRUE ) 808 return rc; 809 rc = SetAnyTypeByComponentOid ((ComponentSyntaxInfo*)&((ComponentAttributeTypeAndValue*)csi_attr)->value, (&((ComponentAttributeTypeAndValue*)csi_attr)->type)); 810 rc = MatchingComponentAnyDefinedBy ( oid, (ComponentAny*)&((ComponentAttributeTypeAndValue*)csi_attr)->value, (ComponentAny*)&((ComponentAttributeTypeAndValue*)csi_assert)->value); 811 if ( rc != LDAP_COMPARE_TRUE ) 812 return rc; 813 return LDAP_COMPARE_TRUE; 814 } /* BMatchingComponentAttributeTypeAndValue */ 815 816 void* 817 ExtractingComponentAttributeTypeAndValue ( void* mem_op, ComponentReference* cr, ComponentAttributeTypeAndValue *comp ) 818 { 819 820 if ( ( comp->type.identifier.bv_val && strncmp(comp->type.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->type.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 821 if ( cr->cr_curr->ci_next == NULL ) 822 return &comp->type; 823 else 824 return NULL; 825 } 826 if ( ( comp->value.identifier.bv_val && strncmp(comp->value.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->value.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 827 if ( cr->cr_curr->ci_next == NULL ) 828 return &comp->value; 829 else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_SELECT ) { 830 cr->cr_curr = cr->cr_curr->ci_next; 831 return &comp->value; 832 } else { 833 return NULL; 834 } 835 } 836 return NULL; 837 } /* ExtractingComponentAttributeTypeAndValue */ 838 839 int 840 BDecComponentAttributeTypeAndValue PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 841 void* mem_op _AND_ 842 GenBuf * b _AND_ 843 AsnTag tagId0 _AND_ 844 AsnLen elmtLen0 _AND_ 845 ComponentAttributeTypeAndValue **v _AND_ 846 AsnLen *bytesDecoded _AND_ 847 int mode) 848 { 849 int seqDone = FALSE; 850 AsnLen totalElmtsLen1 = 0; 851 AsnLen elmtLen1; 852 AsnTag tagId1; 853 int mandatoryElmtCount1 = 0; 854 int old_mode = mode; 855 int rc; 856 ComponentAttributeTypeAndValue *k, *t, c_temp; 857 858 859 if ( !(mode & DEC_ALLOC_MODE_1) ) { 860 memset(&c_temp,0,sizeof(c_temp)); 861 k = &c_temp; 862 } else 863 k = t = *v; 864 mode = DEC_ALLOC_MODE_2; 865 tagId1 = BDecTag (b, &totalElmtsLen1 ); 866 867 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, OID_TAG_CODE)))) 868 { 869 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 870 rc = BDecComponentAttributeType (mem_op, b, tagId1, elmtLen1, (&k->type), &totalElmtsLen1, mode); 871 if ( rc != LDAP_SUCCESS ) return rc; 872 (&k->type)->identifier.bv_val = (&k->type)->id_buf; 873 (&k->type)->identifier.bv_len = strlen("type"); 874 strcpy( (&k->type)->identifier.bv_val, "type"); 875 } 876 else 877 return -1; 878 879 880 881 { 882 rc = SetAnyTypeByComponentOid ((&k->value), (&k->type)); 883 rc = BDecComponentAnyDefinedBy (mem_op,b, (&k->value), &totalElmtsLen1, mode ); 884 if ( rc != LDAP_SUCCESS ) return rc; 885 (&k->value)->identifier.bv_val = (&k->value)->id_buf; 886 (&k->value)->identifier.bv_len = strlen("value"); 887 strcpy( (&k->value)->identifier.bv_val, "value"); 888 seqDone = TRUE; 889 if (elmtLen0 == INDEFINITE_LEN) 890 BDecEoc (b, &totalElmtsLen1 ); 891 else if (totalElmtsLen1 != elmtLen0) 892 return -1; 893 894 } 895 896 897 if (!seqDone) 898 return -1; 899 900 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 901 *v = t = (ComponentAttributeTypeAndValue*) CompAlloc( mem_op, sizeof(ComponentAttributeTypeAndValue) ); 902 if ( !t ) return -1; 903 *t = *k; 904 } 905 t->syntax = (Syntax*)NULL; 906 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 907 if ( !t->comp_desc ) { 908 free ( t ); 909 return -1; 910 } 911 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAttributeTypeAndValue ; 912 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAttributeTypeAndValue ; 913 t->comp_desc->cd_free = (comp_free_func*)NULL; 914 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAttributeTypeAndValue; 915 t->comp_desc->cd_type = ASN_COMPOSITE; 916 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 917 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAttributeTypeAndValue; 918 (*bytesDecoded) += totalElmtsLen1; 919 return LDAP_SUCCESS; 920 } /* BDecAttributeTypeAndValue*/ 921 922 int 923 GDecComponentAttributeTypeAndValue PARAMS (( mem_op,b, v, bytesDecoded, mode), 924 void* mem_op _AND_ 925 GenBuf * b _AND_ 926 ComponentAttributeTypeAndValue **v _AND_ 927 AsnLen *bytesDecoded _AND_ 928 int mode) 929 { 930 char* peek_head,*peek_head2; 931 int i, strLen,strLen2, rc, old_mode = mode; 932 ComponentAttributeTypeAndValue *k,*t, c_temp; 933 934 935 if ( !(mode & DEC_ALLOC_MODE_1) ) { 936 memset(&c_temp,0,sizeof(c_temp)); 937 k = &c_temp; 938 } else 939 k = t = *v; 940 mode = DEC_ALLOC_MODE_2; 941 *bytesDecoded = 0; 942 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 943 Asn1Error("Error during Reading { in encoded data"); 944 return LDAP_PROTOCOL_ERROR; 945 } 946 if(*peek_head != '{'){ 947 Asn1Error("Missing { in encoded data"); 948 return LDAP_PROTOCOL_ERROR; 949 } 950 951 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 952 Asn1Error("Error during Reading identifier"); 953 return LDAP_PROTOCOL_ERROR; 954 } 955 if ( strncmp( peek_head, "type", strlen("type") ) == 0 ) { 956 rc = GDecComponentAttributeType (mem_op, b, (&k->type), bytesDecoded, mode); 957 if ( rc != LDAP_SUCCESS ) return rc; 958 (&k->type)->identifier.bv_val = peek_head; 959 (&k->type)->identifier.bv_len = strLen; 960 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 961 Asn1Error("Error during Reading , "); 962 return LDAP_PROTOCOL_ERROR; 963 } 964 if(*peek_head != ','){ 965 Asn1Error("Missing , in encoding"); 966 return LDAP_PROTOCOL_ERROR; 967 } 968 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 969 Asn1Error("Error during Reading identifier"); 970 return LDAP_PROTOCOL_ERROR; 971 } 972 } 973 if ( strncmp( peek_head, "value", strlen("value") ) == 0 ) { 974 rc = rc = SetAnyTypeByComponentOid ((&k->value), (&k->type)); 975 rc = GDecComponentAnyDefinedBy (mem_op, b, (&k->value), bytesDecoded, mode ); 976 if ( rc != LDAP_SUCCESS ) return rc; 977 (&k->value)->identifier.bv_val = peek_head; 978 (&k->value)->identifier.bv_len = strLen; 979 } 980 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { 981 Asn1Error("Error during Reading } in encoding"); 982 return LDAP_PROTOCOL_ERROR; 983 } 984 if(*peek_head != '}'){ 985 Asn1Error("Missing } in encoding"); 986 return LDAP_PROTOCOL_ERROR; 987 } 988 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 989 *v = t = (ComponentAttributeTypeAndValue*) CompAlloc( mem_op, sizeof(ComponentAttributeTypeAndValue) ); 990 if ( !t ) return -1; 991 *t = *k; 992 } 993 t->syntax = (Syntax*)NULL; 994 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 995 if ( !t->comp_desc ) { 996 free ( t ); 997 return -1; 998 } 999 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentAttributeTypeAndValue ; 1000 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentAttributeTypeAndValue ; 1001 t->comp_desc->cd_free = (comp_free_func*)NULL; 1002 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentAttributeTypeAndValue; 1003 t->comp_desc->cd_type = ASN_COMPOSITE; 1004 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 1005 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentAttributeTypeAndValue; 1006 return LDAP_SUCCESS; 1007 } /* GDecAttributeTypeAndValue*/ 1008 1009 1010 int 1011 MatchingComponentValidity ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 1012 int rc; 1013 MatchingRule* mr; 1014 1015 if ( oid ) { 1016 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 1017 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 1018 } 1019 1020 rc = 1; 1021 rc = MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentValidity*)csi_attr)->notBefore, (ComponentSyntaxInfo*)((ComponentValidity*)csi_assert)->notBefore ); 1022 if ( rc != LDAP_COMPARE_TRUE ) 1023 return rc; 1024 rc = MatchingComponentTime ( oid, (ComponentSyntaxInfo*)((ComponentValidity*)csi_attr)->notAfter, (ComponentSyntaxInfo*)((ComponentValidity*)csi_assert)->notAfter ); 1025 if ( rc != LDAP_COMPARE_TRUE ) 1026 return rc; 1027 return LDAP_COMPARE_TRUE; 1028 } /* BMatchingComponentValidity */ 1029 1030 void* 1031 ExtractingComponentValidity ( void* mem_op, ComponentReference* cr, ComponentValidity *comp ) 1032 { 1033 1034 if ( ( comp->notBefore->identifier.bv_val && strncmp(comp->notBefore->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->notBefore->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 1035 if ( cr->cr_curr->ci_next == NULL ) 1036 return comp->notBefore; 1037 else { 1038 cr->cr_curr = cr->cr_curr->ci_next; 1039 return ExtractingComponentTime ( mem_op, cr, comp->notBefore ); 1040 } 1041 } 1042 if ( ( comp->notAfter->identifier.bv_val && strncmp(comp->notAfter->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->notAfter->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 1043 if ( cr->cr_curr->ci_next == NULL ) 1044 return comp->notAfter; 1045 else { 1046 cr->cr_curr = cr->cr_curr->ci_next; 1047 return ExtractingComponentTime ( mem_op, cr, comp->notAfter ); 1048 } 1049 } 1050 return NULL; 1051 } /* ExtractingComponentValidity */ 1052 1053 int 1054 BDecComponentValidity PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 1055 void* mem_op _AND_ 1056 GenBuf * b _AND_ 1057 AsnTag tagId0 _AND_ 1058 AsnLen elmtLen0 _AND_ 1059 ComponentValidity **v _AND_ 1060 AsnLen *bytesDecoded _AND_ 1061 int mode) 1062 { 1063 int seqDone = FALSE; 1064 AsnLen totalElmtsLen1 = 0; 1065 AsnLen elmtLen1; 1066 AsnTag tagId1; 1067 int mandatoryElmtCount1 = 0; 1068 AsnLen totalElmtsLen2 = 0; 1069 AsnLen elmtLen2; 1070 AsnTag tagId2; 1071 int old_mode = mode; 1072 int rc; 1073 ComponentValidity *k, *t, c_temp; 1074 1075 1076 if ( !(mode & DEC_ALLOC_MODE_1) ) { 1077 memset(&c_temp,0,sizeof(c_temp)); 1078 k = &c_temp; 1079 } else 1080 k = t = *v; 1081 mode = DEC_ALLOC_MODE_2; 1082 tagId1 = BDecTag (b, &totalElmtsLen1 ); 1083 1084 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) || 1085 (tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) || 1086 (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))|| 1087 (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE)))) 1088 { 1089 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 1090 rc = BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->notBefore), &totalElmtsLen1, mode); 1091 if ( rc != LDAP_SUCCESS ) return rc; 1092 (k->notBefore)->identifier.bv_val = (k->notBefore)->id_buf; 1093 (k->notBefore)->identifier.bv_len = strlen("notBefore"); 1094 strcpy( (k->notBefore)->identifier.bv_val, "notBefore"); 1095 tagId1 = BDecTag (b, &totalElmtsLen1); 1096 } 1097 else 1098 return -1; 1099 1100 1101 1102 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, UTCTIME_TAG_CODE)) || 1103 (tagId1 == MAKE_TAG_ID (UNIV, CONS, UTCTIME_TAG_CODE)) || 1104 (tagId1 ==MAKE_TAG_ID (UNIV, PRIM, GENERALIZEDTIME_TAG_CODE))|| 1105 (tagId1 == MAKE_TAG_ID (UNIV, CONS, GENERALIZEDTIME_TAG_CODE)))) 1106 { 1107 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 1108 rc = BDecComponentTime (mem_op, b, tagId1, elmtLen1, (&k->notAfter), &totalElmtsLen1, mode); 1109 if ( rc != LDAP_SUCCESS ) return rc; 1110 (k->notAfter)->identifier.bv_val = (k->notAfter)->id_buf; 1111 (k->notAfter)->identifier.bv_len = strlen("notAfter"); 1112 strcpy( (k->notAfter)->identifier.bv_val, "notAfter"); 1113 seqDone = TRUE; 1114 if (elmtLen0 == INDEFINITE_LEN) 1115 BDecEoc (b, &totalElmtsLen1 ); 1116 else if (totalElmtsLen1 != elmtLen0) 1117 return -1; 1118 1119 } 1120 else 1121 return -1; 1122 1123 1124 1125 if (!seqDone) 1126 return -1; 1127 1128 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 1129 *v = t = (ComponentValidity*) CompAlloc( mem_op, sizeof(ComponentValidity) ); 1130 if ( !t ) return -1; 1131 *t = *k; 1132 } 1133 t->syntax = (Syntax*)NULL; 1134 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1135 if ( !t->comp_desc ) { 1136 free ( t ); 1137 return -1; 1138 } 1139 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentValidity ; 1140 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentValidity ; 1141 t->comp_desc->cd_free = (comp_free_func*)NULL; 1142 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentValidity; 1143 t->comp_desc->cd_type = ASN_COMPOSITE; 1144 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 1145 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentValidity; 1146 (*bytesDecoded) += totalElmtsLen1; 1147 return LDAP_SUCCESS; 1148 } /* BDecValidity*/ 1149 1150 int 1151 GDecComponentValidity PARAMS (( mem_op,b, v, bytesDecoded, mode), 1152 void* mem_op _AND_ 1153 GenBuf * b _AND_ 1154 ComponentValidity **v _AND_ 1155 AsnLen *bytesDecoded _AND_ 1156 int mode) 1157 { 1158 char* peek_head,*peek_head2; 1159 int i, strLen,strLen2, rc, old_mode = mode; 1160 ComponentValidity *k,*t, c_temp; 1161 1162 1163 if ( !(mode & DEC_ALLOC_MODE_1) ) { 1164 memset(&c_temp,0,sizeof(c_temp)); 1165 k = &c_temp; 1166 } else 1167 k = t = *v; 1168 mode = DEC_ALLOC_MODE_2; 1169 *bytesDecoded = 0; 1170 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 1171 Asn1Error("Error during Reading { in encoded data"); 1172 return LDAP_PROTOCOL_ERROR; 1173 } 1174 if(*peek_head != '{'){ 1175 Asn1Error("Missing { in encoded data"); 1176 return LDAP_PROTOCOL_ERROR; 1177 } 1178 1179 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 1180 Asn1Error("Error during Reading identifier"); 1181 return LDAP_PROTOCOL_ERROR; 1182 } 1183 if ( strncmp( peek_head, "notBefore", strlen("notBefore") ) == 0 ) { 1184 rc = GDecComponentTime (mem_op, b, (&k->notBefore), bytesDecoded, mode); 1185 if ( rc != LDAP_SUCCESS ) return rc; 1186 ( k->notBefore)->identifier.bv_val = peek_head; 1187 ( k->notBefore)->identifier.bv_len = strLen; 1188 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 1189 Asn1Error("Error during Reading , "); 1190 return LDAP_PROTOCOL_ERROR; 1191 } 1192 if(*peek_head != ','){ 1193 Asn1Error("Missing , in encoding"); 1194 return LDAP_PROTOCOL_ERROR; 1195 } 1196 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 1197 Asn1Error("Error during Reading identifier"); 1198 return LDAP_PROTOCOL_ERROR; 1199 } 1200 } 1201 if ( strncmp( peek_head, "notAfter", strlen("notAfter") ) == 0 ) { 1202 rc = GDecComponentTime (mem_op, b, (&k->notAfter), bytesDecoded, mode); 1203 if ( rc != LDAP_SUCCESS ) return rc; 1204 ( k->notAfter)->identifier.bv_val = peek_head; 1205 ( k->notAfter)->identifier.bv_len = strLen; 1206 } 1207 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { 1208 Asn1Error("Error during Reading } in encoding"); 1209 return LDAP_PROTOCOL_ERROR; 1210 } 1211 if(*peek_head != '}'){ 1212 Asn1Error("Missing } in encoding"); 1213 return LDAP_PROTOCOL_ERROR; 1214 } 1215 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 1216 *v = t = (ComponentValidity*) CompAlloc( mem_op, sizeof(ComponentValidity) ); 1217 if ( !t ) return -1; 1218 *t = *k; 1219 } 1220 t->syntax = (Syntax*)NULL; 1221 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1222 if ( !t->comp_desc ) { 1223 free ( t ); 1224 return -1; 1225 } 1226 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentValidity ; 1227 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentValidity ; 1228 t->comp_desc->cd_free = (comp_free_func*)NULL; 1229 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentValidity; 1230 t->comp_desc->cd_type = ASN_COMPOSITE; 1231 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 1232 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentValidity; 1233 return LDAP_SUCCESS; 1234 } /* GDecValidity*/ 1235 1236 1237 int 1238 MatchingComponentSubjectPublicKeyInfo ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 1239 int rc; 1240 MatchingRule* mr; 1241 1242 if ( oid ) { 1243 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 1244 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 1245 } 1246 1247 rc = 1; 1248 rc = MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentSubjectPublicKeyInfo*)csi_attr)->algorithm, (ComponentSyntaxInfo*)((ComponentSubjectPublicKeyInfo*)csi_assert)->algorithm ); 1249 if ( rc != LDAP_COMPARE_TRUE ) 1250 return rc; 1251 rc = MatchingComponentBits ( oid, (ComponentSyntaxInfo*)&((ComponentSubjectPublicKeyInfo*)csi_attr)->subjectPublicKey, (ComponentSyntaxInfo*)&((ComponentSubjectPublicKeyInfo*)csi_assert)->subjectPublicKey ); 1252 if ( rc != LDAP_COMPARE_TRUE ) 1253 return rc; 1254 return LDAP_COMPARE_TRUE; 1255 } /* BMatchingComponentSubjectPublicKeyInfo */ 1256 1257 void* 1258 ExtractingComponentSubjectPublicKeyInfo ( void* mem_op, ComponentReference* cr, ComponentSubjectPublicKeyInfo *comp ) 1259 { 1260 1261 if ( ( comp->algorithm->identifier.bv_val && strncmp(comp->algorithm->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->algorithm->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 1262 if ( cr->cr_curr->ci_next == NULL ) 1263 return comp->algorithm; 1264 else { 1265 cr->cr_curr = cr->cr_curr->ci_next; 1266 return ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->algorithm ); 1267 } 1268 } 1269 if ( ( comp->subjectPublicKey.identifier.bv_val && strncmp(comp->subjectPublicKey.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectPublicKey.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 1270 if ( cr->cr_curr->ci_next == NULL ) 1271 return &comp->subjectPublicKey; 1272 else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) { 1273 cr->cr_curr = cr->cr_curr->ci_next; 1274 return &comp->subjectPublicKey; 1275 } else { 1276 return NULL; 1277 } 1278 } 1279 return NULL; 1280 } /* ExtractingComponentSubjectPublicKeyInfo */ 1281 1282 int 1283 BDecComponentSubjectPublicKeyInfo PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 1284 void* mem_op _AND_ 1285 GenBuf * b _AND_ 1286 AsnTag tagId0 _AND_ 1287 AsnLen elmtLen0 _AND_ 1288 ComponentSubjectPublicKeyInfo **v _AND_ 1289 AsnLen *bytesDecoded _AND_ 1290 int mode) 1291 { 1292 int seqDone = FALSE; 1293 AsnLen totalElmtsLen1 = 0; 1294 AsnLen elmtLen1; 1295 AsnTag tagId1; 1296 int mandatoryElmtCount1 = 0; 1297 int old_mode = mode; 1298 int rc; 1299 ComponentSubjectPublicKeyInfo *k, *t, c_temp; 1300 1301 1302 if ( !(mode & DEC_ALLOC_MODE_1) ) { 1303 memset(&c_temp,0,sizeof(c_temp)); 1304 k = &c_temp; 1305 } else 1306 k = t = *v; 1307 mode = DEC_ALLOC_MODE_2; 1308 tagId1 = BDecTag (b, &totalElmtsLen1 ); 1309 1310 if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) 1311 { 1312 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 1313 rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->algorithm), &totalElmtsLen1, mode); 1314 if ( rc != LDAP_SUCCESS ) return rc; 1315 (k->algorithm)->identifier.bv_val = (k->algorithm)->id_buf; 1316 (k->algorithm)->identifier.bv_len = strlen("algorithm"); 1317 strcpy( (k->algorithm)->identifier.bv_val, "algorithm"); 1318 tagId1 = BDecTag (b, &totalElmtsLen1); 1319 } 1320 else 1321 return -1; 1322 1323 1324 1325 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE)) || 1326 (tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE)))) 1327 { 1328 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 1329 rc = BDecComponentBits (mem_op, b, tagId1, elmtLen1, (&k->subjectPublicKey), &totalElmtsLen1, mode); 1330 if ( rc != LDAP_SUCCESS ) return rc; 1331 (&k->subjectPublicKey)->identifier.bv_val = (&k->subjectPublicKey)->id_buf; 1332 (&k->subjectPublicKey)->identifier.bv_len = strlen("subjectPublicKey"); 1333 strcpy( (&k->subjectPublicKey)->identifier.bv_val, "subjectPublicKey"); 1334 seqDone = TRUE; 1335 if (elmtLen0 == INDEFINITE_LEN) 1336 BDecEoc (b, &totalElmtsLen1 ); 1337 else if (totalElmtsLen1 != elmtLen0) 1338 return -1; 1339 1340 } 1341 else 1342 return -1; 1343 1344 1345 1346 if (!seqDone) 1347 return -1; 1348 1349 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 1350 *v = t = (ComponentSubjectPublicKeyInfo*) CompAlloc( mem_op, sizeof(ComponentSubjectPublicKeyInfo) ); 1351 if ( !t ) return -1; 1352 *t = *k; 1353 } 1354 t->syntax = (Syntax*)NULL; 1355 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1356 if ( !t->comp_desc ) { 1357 free ( t ); 1358 return -1; 1359 } 1360 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentSubjectPublicKeyInfo ; 1361 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentSubjectPublicKeyInfo ; 1362 t->comp_desc->cd_free = (comp_free_func*)NULL; 1363 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentSubjectPublicKeyInfo; 1364 t->comp_desc->cd_type = ASN_COMPOSITE; 1365 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 1366 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentSubjectPublicKeyInfo; 1367 (*bytesDecoded) += totalElmtsLen1; 1368 return LDAP_SUCCESS; 1369 } /* BDecSubjectPublicKeyInfo*/ 1370 1371 int 1372 GDecComponentSubjectPublicKeyInfo PARAMS (( mem_op,b, v, bytesDecoded, mode), 1373 void* mem_op _AND_ 1374 GenBuf * b _AND_ 1375 ComponentSubjectPublicKeyInfo **v _AND_ 1376 AsnLen *bytesDecoded _AND_ 1377 int mode) 1378 { 1379 char* peek_head,*peek_head2; 1380 int i, strLen,strLen2, rc, old_mode = mode; 1381 ComponentSubjectPublicKeyInfo *k,*t, c_temp; 1382 1383 1384 if ( !(mode & DEC_ALLOC_MODE_1) ) { 1385 memset(&c_temp,0,sizeof(c_temp)); 1386 k = &c_temp; 1387 } else 1388 k = t = *v; 1389 mode = DEC_ALLOC_MODE_2; 1390 *bytesDecoded = 0; 1391 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 1392 Asn1Error("Error during Reading { in encoded data"); 1393 return LDAP_PROTOCOL_ERROR; 1394 } 1395 if(*peek_head != '{'){ 1396 Asn1Error("Missing { in encoded data"); 1397 return LDAP_PROTOCOL_ERROR; 1398 } 1399 1400 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 1401 Asn1Error("Error during Reading identifier"); 1402 return LDAP_PROTOCOL_ERROR; 1403 } 1404 if ( strncmp( peek_head, "algorithm", strlen("algorithm") ) == 0 ) { 1405 rc = GDecComponentAlgorithmIdentifier (mem_op, b, (&k->algorithm), bytesDecoded, mode); 1406 if ( rc != LDAP_SUCCESS ) return rc; 1407 ( k->algorithm)->identifier.bv_val = peek_head; 1408 ( k->algorithm)->identifier.bv_len = strLen; 1409 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 1410 Asn1Error("Error during Reading , "); 1411 return LDAP_PROTOCOL_ERROR; 1412 } 1413 if(*peek_head != ','){ 1414 Asn1Error("Missing , in encoding"); 1415 return LDAP_PROTOCOL_ERROR; 1416 } 1417 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 1418 Asn1Error("Error during Reading identifier"); 1419 return LDAP_PROTOCOL_ERROR; 1420 } 1421 } 1422 if ( strncmp( peek_head, "subjectPublicKey", strlen("subjectPublicKey") ) == 0 ) { 1423 rc = GDecComponentBits (mem_op, b, (&k->subjectPublicKey), bytesDecoded, mode); 1424 if ( rc != LDAP_SUCCESS ) return rc; 1425 (&k->subjectPublicKey)->identifier.bv_val = peek_head; 1426 (&k->subjectPublicKey)->identifier.bv_len = strLen; 1427 } 1428 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { 1429 Asn1Error("Error during Reading } in encoding"); 1430 return LDAP_PROTOCOL_ERROR; 1431 } 1432 if(*peek_head != '}'){ 1433 Asn1Error("Missing } in encoding"); 1434 return LDAP_PROTOCOL_ERROR; 1435 } 1436 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 1437 *v = t = (ComponentSubjectPublicKeyInfo*) CompAlloc( mem_op, sizeof(ComponentSubjectPublicKeyInfo) ); 1438 if ( !t ) return -1; 1439 *t = *k; 1440 } 1441 t->syntax = (Syntax*)NULL; 1442 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1443 if ( !t->comp_desc ) { 1444 free ( t ); 1445 return -1; 1446 } 1447 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentSubjectPublicKeyInfo ; 1448 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentSubjectPublicKeyInfo ; 1449 t->comp_desc->cd_free = (comp_free_func*)NULL; 1450 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentSubjectPublicKeyInfo; 1451 t->comp_desc->cd_type = ASN_COMPOSITE; 1452 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 1453 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentSubjectPublicKeyInfo; 1454 return LDAP_SUCCESS; 1455 } /* GDecSubjectPublicKeyInfo*/ 1456 1457 1458 int 1459 MatchingComponentExtensions ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 1460 int rc; 1461 MatchingRule* mr; 1462 void* component1, *component2; 1463 AsnList *v1, *v2, t_list; 1464 1465 1466 if ( oid ) { 1467 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 1468 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 1469 } 1470 1471 v1 = &((ComponentExtensions*)csi_attr)->comp_list; 1472 v2 = &((ComponentExtensions*)csi_assert)->comp_list; 1473 FOR_EACH_LIST_PAIR_ELMT(component1, component2, v1, v2) 1474 { 1475 if( MatchingComponentExtension(oid, (ComponentSyntaxInfo*)component1, (ComponentSyntaxInfo*)component2) == LDAP_COMPARE_FALSE) { 1476 return LDAP_COMPARE_FALSE; 1477 } 1478 } /* end of for */ 1479 1480 AsnListFirst( v1 ); 1481 AsnListFirst( v2 ); 1482 if( (!component1 && component2) || (component1 && !component2)) 1483 return LDAP_COMPARE_FALSE; 1484 else 1485 return LDAP_COMPARE_TRUE; 1486 } /* BMatchingComponentExtensionsContent */ 1487 1488 void* 1489 ExtractingComponentExtensions ( void* mem_op, ComponentReference* cr, ComponentExtensions *comp ) 1490 { 1491 int count = 0; 1492 int total; 1493 AsnList *v = &comp->comp_list; 1494 ComponentInt *k; 1495 ComponentExtension *component; 1496 1497 1498 switch ( cr->cr_curr->ci_type ) { 1499 case LDAP_COMPREF_FROM_BEGINNING : 1500 count = cr->cr_curr->ci_val.ci_from_beginning; 1501 FOR_EACH_LIST_ELMT( component , v ) { 1502 if( --count == 0 ) { 1503 if( cr->cr_curr->ci_next == NULL ) 1504 return component; 1505 else { 1506 cr->cr_curr = cr->cr_curr->ci_next; 1507 return ExtractingComponentExtension ( mem_op, cr, component ); 1508 } 1509 } 1510 } 1511 break; 1512 case LDAP_COMPREF_FROM_END : 1513 total = AsnListCount ( v ); 1514 count = cr->cr_curr->ci_val.ci_from_end; 1515 count = total + count +1; 1516 FOR_EACH_LIST_ELMT ( component, v ) { 1517 if( --count == 0 ) { 1518 if( cr->cr_curr->ci_next == NULL ) 1519 return component; 1520 else { 1521 cr->cr_curr = cr->cr_curr->ci_next; 1522 return ExtractingComponentExtension ( mem_op, cr, component ); 1523 } 1524 } 1525 } 1526 break; 1527 case LDAP_COMPREF_ALL : 1528 return comp; 1529 case LDAP_COMPREF_COUNT : 1530 k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt)); 1531 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1532 k->comp_desc->cd_tag = (-1); 1533 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; 1534 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; 1535 k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL; 1536 k->comp_desc->cd_type = ASN_BASIC; 1537 k->comp_desc->cd_type_id = BASICTYPE_INTEGER; 1538 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt; 1539 k->value = AsnListCount(v); 1540 return k; 1541 default : 1542 return NULL; 1543 } 1544 } /* ExtractingComponentExtensions */ 1545 1546 int 1547 BDecComponentExtensions PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 1548 void* mem_op _AND_ 1549 GenBuf * b _AND_ 1550 AsnTag tagId0 _AND_ 1551 AsnLen elmtLen0 _AND_ 1552 ComponentExtensions **v _AND_ 1553 AsnLen *bytesDecoded _AND_ 1554 int mode) 1555 { 1556 int seqDone = FALSE; 1557 AsnLen totalElmtsLen1 = 0; 1558 AsnLen elmtLen1; 1559 AsnTag tagId1; 1560 int mandatoryElmtCount1 = 0; 1561 int old_mode = mode; 1562 int rc; 1563 ComponentExtensions *k, *t, c_temp; 1564 1565 1566 if ( !(mode & DEC_ALLOC_MODE_1) ) { 1567 memset(&c_temp,0,sizeof(c_temp)); 1568 k = &c_temp; 1569 } else 1570 k = t = *v; 1571 mode = DEC_ALLOC_MODE_2; 1572 AsnListInit(&k->comp_list,sizeof(ComponentExtension)); 1573 for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);) 1574 { 1575 ComponentExtension **tmpVar; 1576 tagId1 = BDecTag (b, &totalElmtsLen1 ); 1577 1578 if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN)) 1579 { 1580 BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) 1581 break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/ 1582 } 1583 if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))) 1584 { 1585 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 1586 tmpVar = (ComponentExtension**) CompAsnListAppend (mem_op,&k->comp_list); 1587 rc = BDecComponentExtension (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); 1588 if ( rc != LDAP_SUCCESS ) return rc; 1589 } /* end of tag check if */ 1590 else /* wrong tag */ 1591 { 1592 Asn1Error ("Unexpected Tag\n"); 1593 return -1; 1594 } 1595 } /* end of for */ 1596 1597 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 1598 *v = t = (ComponentExtensions*) CompAlloc( mem_op, sizeof(ComponentExtensions) ); 1599 if ( !t ) return -1; 1600 *t = *k; 1601 } 1602 t->syntax = (Syntax*)NULL; 1603 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1604 if ( !t->comp_desc ) { 1605 free ( t ); 1606 return -1; 1607 } 1608 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtensions ; 1609 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtensions ; 1610 t->comp_desc->cd_free = (comp_free_func*)NULL; 1611 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtensions; 1612 t->comp_desc->cd_type = ASN_COMPOSITE; 1613 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 1614 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtensions; 1615 (*bytesDecoded) += totalElmtsLen1; 1616 return LDAP_SUCCESS; 1617 } /* BDecExtensionsContent */ 1618 1619 int 1620 GDecComponentExtensions PARAMS (( mem_op,b, v, bytesDecoded, mode), 1621 void* mem_op _AND_ 1622 GenBuf * b _AND_ 1623 ComponentExtensions **v _AND_ 1624 AsnLen *bytesDecoded _AND_ 1625 int mode) 1626 { 1627 char* peek_head,*peek_head2; 1628 int i, strLen,strLen2, rc, old_mode = mode; 1629 ComponentExtensions *k,*t, c_temp; 1630 1631 1632 int ElmtsLen1; 1633 if ( !(mode & DEC_ALLOC_MODE_1) ) { 1634 memset(&c_temp,0,sizeof(c_temp)); 1635 k = &c_temp; 1636 } else 1637 k = t = *v; 1638 mode = DEC_ALLOC_MODE_2; 1639 AsnListInit( &k->comp_list, sizeof( ComponentExtension ) ); 1640 *bytesDecoded = 0; 1641 if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){ 1642 Asn1Error("Error during Reading { in encoding"); 1643 return LDAP_PROTOCOL_ERROR; 1644 } 1645 if(*peek_head != '{'){ 1646 Asn1Error("Missing { in encoded data"); 1647 return LDAP_PROTOCOL_ERROR; 1648 } 1649 1650 for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) 1651 { 1652 ComponentExtension **tmpVar; 1653 if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){ 1654 Asn1Error("Error during Reading{ in encoding"); 1655 return LDAP_PROTOCOL_ERROR; 1656 } 1657 if(*peek_head == '}') break; 1658 if( !(*peek_head == '{' || *peek_head ==',') ) { 1659 return LDAP_PROTOCOL_ERROR; 1660 } 1661 tmpVar = (ComponentExtension**) CompAsnListAppend (mem_op, &k->comp_list); 1662 if ( tmpVar == NULL ) { 1663 Asn1Error("Error during Reading{ in encoding"); 1664 return LDAP_PROTOCOL_ERROR; 1665 } 1666 rc = GDecComponentExtension (mem_op, b, tmpVar, bytesDecoded, mode); 1667 if ( rc != LDAP_SUCCESS ) return rc; 1668 } /* end of for */ 1669 1670 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 1671 *v = t = (ComponentExtensions*) CompAlloc( mem_op, sizeof(ComponentExtensions) ); 1672 if ( !t ) return -1; 1673 *t = *k; 1674 } 1675 t->syntax = (Syntax*)NULL; 1676 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1677 if ( !t->comp_desc ) { 1678 free ( t ); 1679 return -1; 1680 } 1681 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentExtensions ; 1682 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentExtensions ; 1683 t->comp_desc->cd_free = (comp_free_func*)NULL; 1684 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentExtensions; 1685 t->comp_desc->cd_type = ASN_COMPOSITE; 1686 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 1687 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentExtensions; 1688 return LDAP_SUCCESS; 1689 } /* GDecExtensionsContent */ 1690 1691 1692 int 1693 MatchingComponentRelativeDistinguishedName ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 1694 int rc; 1695 MatchingRule* mr; 1696 void* component1, *component2; 1697 AsnList *v1, *v2, t_list; 1698 1699 1700 if ( oid ) { 1701 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 1702 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 1703 } 1704 1705 v1 = &((ComponentRelativeDistinguishedName*)csi_attr)->comp_list; 1706 v2 = &((ComponentRelativeDistinguishedName*)csi_assert)->comp_list; 1707 AsnListInit( &t_list, 0 ); 1708 if( AsnListCount( v1 ) != AsnListCount( v2 ) ) 1709 return LDAP_COMPARE_FALSE; 1710 FOR_EACH_LIST_ELMT (component1, v1) 1711 { 1712 FOR_EACH_LIST_ELMT(component2, v2) 1713 { 1714 if( MatchingComponentAttributeTypeAndValue(oid, (ComponentSyntaxInfo*)component1,(ComponentSyntaxInfo*)component2) == LDAP_COMPARE_TRUE ) { 1715 AsnElmtMove( v2, &t_list ); 1716 break; 1717 } 1718 } /* end of inner for */ 1719 } /* end of outer for */ 1720 1721 if( AsnListCount( v2 ) == 0 ) 1722 rc = LDAP_COMPARE_TRUE; 1723 else 1724 rc = LDAP_COMPARE_FALSE; 1725 AsnListMove( &t_list, v2 ); 1726 AsnListFirst( v1 ); 1727 AsnListFirst( v2 ); 1728 return rc; 1729 } /* BMatchingComponentRelativeDistinguishedNameContent */ 1730 1731 void* 1732 ExtractingComponentRelativeDistinguishedName ( void* mem_op, ComponentReference* cr, ComponentRelativeDistinguishedName *comp ) 1733 { 1734 int count = 0; 1735 int total; 1736 AsnList *v = &comp->comp_list; 1737 ComponentInt *k; 1738 ComponentAttributeTypeAndValue *component; 1739 1740 1741 switch ( cr->cr_curr->ci_type ) { 1742 case LDAP_COMPREF_FROM_BEGINNING : 1743 count = cr->cr_curr->ci_val.ci_from_beginning; 1744 FOR_EACH_LIST_ELMT( component , v ) { 1745 if( --count == 0 ) { 1746 if( cr->cr_curr->ci_next == NULL ) 1747 return component; 1748 else { 1749 cr->cr_curr = cr->cr_curr->ci_next; 1750 return ExtractingComponentAttributeTypeAndValue ( mem_op, cr, component ); 1751 } 1752 } 1753 } 1754 break; 1755 case LDAP_COMPREF_FROM_END : 1756 total = AsnListCount ( v ); 1757 count = cr->cr_curr->ci_val.ci_from_end; 1758 count = total + count +1; 1759 FOR_EACH_LIST_ELMT ( component, v ) { 1760 if( --count == 0 ) { 1761 if( cr->cr_curr->ci_next == NULL ) 1762 return component; 1763 else { 1764 cr->cr_curr = cr->cr_curr->ci_next; 1765 return ExtractingComponentAttributeTypeAndValue ( mem_op, cr, component ); 1766 } 1767 } 1768 } 1769 break; 1770 case LDAP_COMPREF_ALL : 1771 return comp; 1772 case LDAP_COMPREF_COUNT : 1773 k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt)); 1774 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1775 k->comp_desc->cd_tag = (-1); 1776 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; 1777 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; 1778 k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL; 1779 k->comp_desc->cd_type = ASN_BASIC; 1780 k->comp_desc->cd_type_id = BASICTYPE_INTEGER; 1781 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt; 1782 k->value = AsnListCount(v); 1783 return k; 1784 default : 1785 return NULL; 1786 } 1787 } /* ExtractingComponentRelativeDistinguishedName */ 1788 1789 int 1790 BDecComponentRelativeDistinguishedName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 1791 void* mem_op _AND_ 1792 GenBuf * b _AND_ 1793 AsnTag tagId0 _AND_ 1794 AsnLen elmtLen0 _AND_ 1795 ComponentRelativeDistinguishedName **v _AND_ 1796 AsnLen *bytesDecoded _AND_ 1797 int mode) 1798 { 1799 int seqDone = FALSE; 1800 AsnLen totalElmtsLen1 = 0; 1801 AsnLen elmtLen1; 1802 AsnTag tagId1; 1803 int mandatoryElmtCount1 = 0; 1804 int old_mode = mode; 1805 int rc; 1806 ComponentRelativeDistinguishedName *k, *t, c_temp; 1807 1808 1809 if ( !(mode & DEC_ALLOC_MODE_1) ) { 1810 memset(&c_temp,0,sizeof(c_temp)); 1811 k = &c_temp; 1812 } else 1813 k = t = *v; 1814 mode = DEC_ALLOC_MODE_2; 1815 AsnListInit(&k->comp_list,sizeof(ComponentAttributeTypeAndValue)); 1816 for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);) 1817 { 1818 ComponentAttributeTypeAndValue **tmpVar; 1819 tagId1 = BDecTag (b, &totalElmtsLen1 ); 1820 1821 if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN)) 1822 { 1823 BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) 1824 break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/ 1825 } 1826 if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE))) 1827 { 1828 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 1829 tmpVar = (ComponentAttributeTypeAndValue**) CompAsnListAppend (mem_op,&k->comp_list); 1830 rc = BDecComponentAttributeTypeAndValue (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); 1831 if ( rc != LDAP_SUCCESS ) return rc; 1832 } /* end of tag check if */ 1833 else /* wrong tag */ 1834 { 1835 Asn1Error ("Unexpected Tag\n"); 1836 return -1; 1837 } 1838 } /* end of for */ 1839 1840 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 1841 *v = t = (ComponentRelativeDistinguishedName*) CompAlloc( mem_op, sizeof(ComponentRelativeDistinguishedName) ); 1842 if ( !t ) return -1; 1843 *t = *k; 1844 } 1845 t->syntax = (Syntax*)NULL; 1846 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1847 if ( !t->comp_desc ) { 1848 free ( t ); 1849 return -1; 1850 } 1851 1852 t->comp_desc->cd_gser_encoder = (encoder_func*)NULL; 1853 t->comp_desc->cd_ber_encoder = (encoder_func*)NULL; 1854 t->comp_desc->cd_ldap_encoder = (encoder_func*)ConvertRDN2RFC2253; 1855 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeDistinguishedName ; 1856 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeDistinguishedName ; 1857 t->comp_desc->cd_free = (comp_free_func*)NULL; 1858 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName; 1859 t->comp_desc->cd_type = ASN_COMPOSITE; 1860 t->comp_desc->cd_type_id = RelativeDistinguishedName; 1861 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeDistinguishedName; 1862 (*bytesDecoded) += totalElmtsLen1; 1863 return LDAP_SUCCESS; 1864 } /* BDecRelativeDistinguishedNameContent */ 1865 1866 int 1867 GDecComponentRelativeDistinguishedName PARAMS (( mem_op,b, v, bytesDecoded, mode), 1868 void* mem_op _AND_ 1869 GenBuf * b _AND_ 1870 ComponentRelativeDistinguishedName **v _AND_ 1871 AsnLen *bytesDecoded _AND_ 1872 int mode) 1873 { 1874 char* peek_head,*peek_head2; 1875 int i, strLen,strLen2, rc, old_mode = mode; 1876 ComponentRelativeDistinguishedName *k,*t, c_temp; 1877 1878 1879 int ElmtsLen1; 1880 if ( !(mode & DEC_ALLOC_MODE_1) ) { 1881 memset(&c_temp,0,sizeof(c_temp)); 1882 k = &c_temp; 1883 } else 1884 k = t = *v; 1885 mode = DEC_ALLOC_MODE_2; 1886 AsnListInit( &k->comp_list, sizeof( ComponentAttributeTypeAndValue ) ); 1887 *bytesDecoded = 0; 1888 if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){ 1889 Asn1Error("Error during Reading { in encoding"); 1890 return LDAP_PROTOCOL_ERROR; 1891 } 1892 if(*peek_head != '{'){ 1893 Asn1Error("Missing { in encoded data"); 1894 return LDAP_PROTOCOL_ERROR; 1895 } 1896 1897 for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) 1898 { 1899 ComponentAttributeTypeAndValue **tmpVar; 1900 if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){ 1901 Asn1Error("Error during Reading{ in encoding"); 1902 return LDAP_PROTOCOL_ERROR; 1903 } 1904 if(*peek_head == '}') break; 1905 if( !(*peek_head == '{' || *peek_head ==',') ) { 1906 return LDAP_PROTOCOL_ERROR; 1907 } 1908 tmpVar = (ComponentAttributeTypeAndValue**) CompAsnListAppend (mem_op, &k->comp_list); 1909 if ( tmpVar == NULL ) { 1910 Asn1Error("Error during Reading{ in encoding"); 1911 return LDAP_PROTOCOL_ERROR; 1912 } 1913 rc = GDecComponentAttributeTypeAndValue (mem_op, b, tmpVar, bytesDecoded, mode); 1914 if ( rc != LDAP_SUCCESS ) return rc; 1915 } /* end of for */ 1916 1917 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 1918 *v = t = (ComponentRelativeDistinguishedName*) CompAlloc( mem_op, sizeof(ComponentRelativeDistinguishedName) ); 1919 if ( !t ) return -1; 1920 *t = *k; 1921 } 1922 t->syntax = (Syntax*)NULL; 1923 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 1924 if ( !t->comp_desc ) { 1925 free ( t ); 1926 return -1; 1927 } 1928 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRelativeDistinguishedName ; 1929 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRelativeDistinguishedName ; 1930 t->comp_desc->cd_free = (comp_free_func*)NULL; 1931 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRelativeDistinguishedName; 1932 t->comp_desc->cd_type = ASN_COMPOSITE; 1933 t->comp_desc->cd_type_id = RelativeDistinguishedName; 1934 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRelativeDistinguishedName; 1935 return LDAP_SUCCESS; 1936 } /* GDecRelativeDistinguishedNameContent */ 1937 1938 1939 int 1940 MatchingComponentRDNSequence ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 1941 int rc; 1942 MatchingRule* mr; 1943 void* component1, *component2; 1944 AsnList *v1, *v2, t_list; 1945 1946 1947 if ( oid ) { 1948 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 1949 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 1950 } 1951 1952 v1 = &((ComponentRDNSequence*)csi_attr)->comp_list; 1953 v2 = &((ComponentRDNSequence*)csi_assert)->comp_list; 1954 FOR_EACH_LIST_PAIR_ELMT(component1, component2, v1, v2) 1955 { 1956 if( MatchingComponentRelativeDistinguishedName(oid, (ComponentSyntaxInfo*)component1, (ComponentSyntaxInfo*)component2) == LDAP_COMPARE_FALSE) { 1957 return LDAP_COMPARE_FALSE; 1958 } 1959 } /* end of for */ 1960 1961 AsnListFirst( v1 ); 1962 AsnListFirst( v2 ); 1963 if( (!component1 && component2) || (component1 && !component2)) 1964 return LDAP_COMPARE_FALSE; 1965 else 1966 return LDAP_COMPARE_TRUE; 1967 } /* BMatchingComponentRDNSequenceContent */ 1968 1969 void* 1970 ExtractingComponentRDNSequence ( void* mem_op, ComponentReference* cr, ComponentRDNSequence *comp ) 1971 { 1972 int count = 0; 1973 int total; 1974 AsnList *v = &comp->comp_list; 1975 ComponentInt *k; 1976 ComponentRelativeDistinguishedName *component; 1977 1978 1979 switch ( cr->cr_curr->ci_type ) { 1980 case LDAP_COMPREF_FROM_BEGINNING : 1981 count = cr->cr_curr->ci_val.ci_from_beginning; 1982 FOR_EACH_LIST_ELMT( component , v ) { 1983 if( --count == 0 ) { 1984 if( cr->cr_curr->ci_next == NULL ) 1985 return component; 1986 else { 1987 cr->cr_curr = cr->cr_curr->ci_next; 1988 return ExtractingComponentRelativeDistinguishedName ( mem_op, cr, component ); 1989 } 1990 } 1991 } 1992 break; 1993 case LDAP_COMPREF_FROM_END : 1994 total = AsnListCount ( v ); 1995 count = cr->cr_curr->ci_val.ci_from_end; 1996 count = total + count +1; 1997 FOR_EACH_LIST_ELMT ( component, v ) { 1998 if( --count == 0 ) { 1999 if( cr->cr_curr->ci_next == NULL ) 2000 return component; 2001 else { 2002 cr->cr_curr = cr->cr_curr->ci_next; 2003 return ExtractingComponentRelativeDistinguishedName ( mem_op, cr, component ); 2004 } 2005 } 2006 } 2007 break; 2008 case LDAP_COMPREF_ALL : 2009 return comp; 2010 case LDAP_COMPREF_COUNT : 2011 k = (ComponentInt*)CompAlloc( mem_op, sizeof(ComponentInt)); 2012 k->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 2013 k->comp_desc->cd_tag = (-1); 2014 k->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentInt; 2015 k->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentInt; 2016 k->comp_desc->cd_extract_i = (extract_component_from_id_func*)NULL; 2017 k->comp_desc->cd_type = ASN_BASIC; 2018 k->comp_desc->cd_type_id = BASICTYPE_INTEGER; 2019 k->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentInt; 2020 k->value = AsnListCount(v); 2021 return k; 2022 default : 2023 return NULL; 2024 } 2025 } /* ExtractingComponentRDNSequence */ 2026 2027 int 2028 BDecComponentRDNSequence PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 2029 void* mem_op _AND_ 2030 GenBuf * b _AND_ 2031 AsnTag tagId0 _AND_ 2032 AsnLen elmtLen0 _AND_ 2033 ComponentRDNSequence **v _AND_ 2034 AsnLen *bytesDecoded _AND_ 2035 int mode) 2036 { 2037 int seqDone = FALSE; 2038 AsnLen totalElmtsLen1 = 0; 2039 AsnLen elmtLen1; 2040 AsnTag tagId1; 2041 int mandatoryElmtCount1 = 0; 2042 int old_mode = mode; 2043 int rc; 2044 ComponentRDNSequence *k, *t, c_temp; 2045 2046 2047 if ( !(mode & DEC_ALLOC_MODE_1) ) { 2048 memset(&c_temp,0,sizeof(c_temp)); 2049 k = &c_temp; 2050 } else 2051 k = t = *v; 2052 mode = DEC_ALLOC_MODE_2; 2053 AsnListInit(&k->comp_list,sizeof(ComponentRelativeDistinguishedName)); 2054 for (totalElmtsLen1 = 0; (totalElmtsLen1 < elmtLen0) || (elmtLen0 == INDEFINITE_LEN);) 2055 { 2056 ComponentRelativeDistinguishedName **tmpVar; 2057 tagId1 = BDecTag (b, &totalElmtsLen1 ); 2058 2059 if ((tagId1 == EOC_TAG_ID) && (elmtLen0 == INDEFINITE_LEN)) 2060 { 2061 BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) 2062 break; /* got EOC so can exit this SET OF/SEQ OF's for loop*/ 2063 } 2064 if ((tagId1 == MAKE_TAG_ID (UNIV, CONS, SET_TAG_CODE))) 2065 { 2066 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2067 tmpVar = (ComponentRelativeDistinguishedName**) CompAsnListAppend (mem_op,&k->comp_list); 2068 rc = BDecComponentRelativeDistinguishedName (mem_op, b, tagId1, elmtLen1, tmpVar, &totalElmtsLen1, mode); 2069 if ( rc != LDAP_SUCCESS ) return rc; 2070 } /* end of tag check if */ 2071 else /* wrong tag */ 2072 { 2073 Asn1Error ("Unexpected Tag\n"); 2074 return -1; 2075 } 2076 } /* end of for */ 2077 2078 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 2079 *v = t = (ComponentRDNSequence*) CompAlloc( mem_op, sizeof(ComponentRDNSequence) ); 2080 if ( !t ) return -1; 2081 *t = *k; 2082 } 2083 t->syntax = (Syntax*)NULL; 2084 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 2085 if ( !t->comp_desc ) { 2086 free ( t ); 2087 return -1; 2088 } 2089 2090 t->comp_desc->cd_gser_encoder = (encoder_func*)NULL; 2091 t->comp_desc->cd_ber_encoder = (encoder_func*)NULL; 2092 t->comp_desc->cd_ldap_encoder = (encoder_func*) ConvertRDNSequence2RFC2253; 2093 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRDNSequence ; 2094 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRDNSequence ; 2095 t->comp_desc->cd_free = (comp_free_func*)NULL; 2096 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence; 2097 t->comp_desc->cd_type = ASN_COMPOSITE; 2098 t->comp_desc->cd_type_id = RDNSequence; 2099 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRDNSequence; 2100 (*bytesDecoded) += totalElmtsLen1; 2101 return LDAP_SUCCESS; 2102 } /* BDecRDNSequenceContent */ 2103 2104 int 2105 GDecComponentRDNSequence PARAMS (( mem_op,b, v, bytesDecoded, mode), 2106 void* mem_op _AND_ 2107 GenBuf * b _AND_ 2108 ComponentRDNSequence **v _AND_ 2109 AsnLen *bytesDecoded _AND_ 2110 int mode) 2111 { 2112 char* peek_head,*peek_head2; 2113 int i, strLen,strLen2, rc, old_mode = mode; 2114 ComponentRDNSequence *k,*t, c_temp; 2115 2116 2117 int ElmtsLen1; 2118 if ( !(mode & DEC_ALLOC_MODE_1) ) { 2119 memset(&c_temp,0,sizeof(c_temp)); 2120 k = &c_temp; 2121 } else 2122 k = t = *v; 2123 mode = DEC_ALLOC_MODE_2; 2124 AsnListInit( &k->comp_list, sizeof( ComponentRelativeDistinguishedName ) ); 2125 *bytesDecoded = 0; 2126 if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_PEEK)) ){ 2127 Asn1Error("Error during Reading { in encoding"); 2128 return LDAP_PROTOCOL_ERROR; 2129 } 2130 if(*peek_head != '{'){ 2131 Asn1Error("Missing { in encoded data"); 2132 return LDAP_PROTOCOL_ERROR; 2133 } 2134 2135 for (ElmtsLen1 = 0; ElmtsLen1 >= INDEFINITE_LEN; ElmtsLen1++) 2136 { 2137 ComponentRelativeDistinguishedName **tmpVar; 2138 if( !(strLen = LocateNextGSERToken(mem_op,b, &peek_head, GSER_NO_COPY)) ){ 2139 Asn1Error("Error during Reading{ in encoding"); 2140 return LDAP_PROTOCOL_ERROR; 2141 } 2142 if(*peek_head == '}') break; 2143 if( !(*peek_head == '{' || *peek_head ==',') ) { 2144 return LDAP_PROTOCOL_ERROR; 2145 } 2146 tmpVar = (ComponentRelativeDistinguishedName**) CompAsnListAppend (mem_op, &k->comp_list); 2147 if ( tmpVar == NULL ) { 2148 Asn1Error("Error during Reading{ in encoding"); 2149 return LDAP_PROTOCOL_ERROR; 2150 } 2151 rc = GDecComponentRelativeDistinguishedName (mem_op, b, tmpVar, bytesDecoded, mode); 2152 if ( rc != LDAP_SUCCESS ) return rc; 2153 } /* end of for */ 2154 2155 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 2156 *v = t = (ComponentRDNSequence*) CompAlloc( mem_op, sizeof(ComponentRDNSequence) ); 2157 if ( !t ) return -1; 2158 *t = *k; 2159 } 2160 t->syntax = (Syntax*)NULL; 2161 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 2162 if ( !t->comp_desc ) { 2163 free ( t ); 2164 return -1; 2165 } 2166 t->comp_desc->cd_gser_encoder = (encoder_func*)NULL; 2167 t->comp_desc->cd_ber_encoder = (encoder_func*)NULL; 2168 t->comp_desc->cd_ldap_encoder = (encoder_func*)ConvertRDNSequence2RFC2253; 2169 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentRDNSequence ; 2170 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentRDNSequence ; 2171 t->comp_desc->cd_free = (comp_free_func*)NULL; 2172 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentRDNSequence; 2173 t->comp_desc->cd_type = ASN_COMPOSITE; 2174 t->comp_desc->cd_type_id = RDNSequence ; 2175 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentRDNSequence; 2176 return LDAP_SUCCESS; 2177 } /* GDecRDNSequenceContent */ 2178 2179 2180 int 2181 MatchingComponentName ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 2182 int rc; 2183 MatchingRule* mr; 2184 ComponentName *v1, *v2; 2185 2186 2187 v1 = (ComponentName*)csi_attr; 2188 v2 = (ComponentName*)csi_assert; 2189 if ( oid ) { 2190 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 2191 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 2192 } 2193 2194 if( (v1->choiceId != v2->choiceId ) ) 2195 return LDAP_COMPARE_FALSE; 2196 switch( v1->choiceId ) 2197 { 2198 case NAME_RDNSEQUENCE : 2199 rc = MatchingComponentRDNSequence ( oid, (ComponentSyntaxInfo*)(v1->a.rdnSequence), (ComponentSyntaxInfo*)(v2->a.rdnSequence) ); 2200 break; 2201 default : 2202 return LDAP_PROTOCOL_ERROR; 2203 } 2204 return rc; 2205 } /* BMatchingComponentNameContent */ 2206 2207 void* 2208 ExtractingComponentName ( void* mem_op, ComponentReference* cr, ComponentName *comp ) 2209 { 2210 2211 2212 if( (comp->choiceId) == NAME_RDNSEQUENCE && 2213 (( comp->a.rdnSequence->identifier.bv_val && strncmp(comp->a.rdnSequence->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0) || 2214 ( strncmp(comp->a.rdnSequence->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0))) { 2215 if ( cr->cr_curr->ci_next == NULL ) 2216 return (comp->a.rdnSequence); 2217 else { 2218 cr->cr_curr = cr->cr_curr->ci_next; 2219 return ExtractingComponentRDNSequence ( mem_op, cr, (comp->a.rdnSequence) ); 2220 }; 2221 } 2222 return NULL; 2223 } /* ExtractingComponentName */ 2224 2225 int 2226 BDecComponentName PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 2227 void* mem_op _AND_ 2228 GenBuf * b _AND_ 2229 AsnTag tagId0 _AND_ 2230 AsnLen elmtLen0 _AND_ 2231 ComponentName **v _AND_ 2232 AsnLen *bytesDecoded _AND_ 2233 int mode) 2234 { 2235 int seqDone = FALSE; 2236 AsnLen totalElmtsLen1 = 0; 2237 AsnLen elmtLen1; 2238 AsnTag tagId1; 2239 int mandatoryElmtCount1 = 0; 2240 int old_mode = mode; 2241 int rc; 2242 ComponentName *k, *t, c_temp; 2243 2244 2245 if ( !(mode & DEC_ALLOC_MODE_1) ) { 2246 memset(&c_temp,0,sizeof(c_temp)); 2247 k = &c_temp; 2248 } else 2249 k = t = *v; 2250 mode = DEC_ALLOC_MODE_2; 2251 switch (tagId0) 2252 { 2253 case MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE): 2254 (k->choiceId) = NAME_RDNSEQUENCE; 2255 rc = BDecComponentRDNSequence (mem_op, b, tagId0, elmtLen0, (&k->a.rdnSequence), &totalElmtsLen1, mode); 2256 if ( rc != LDAP_SUCCESS ) return rc; 2257 (k->a.rdnSequence)->identifier.bv_val = (k->a.rdnSequence)->id_buf; 2258 (k->a.rdnSequence)->identifier.bv_len = strlen("rdnSequence"); 2259 strcpy( (k->a.rdnSequence)->identifier.bv_val, "rdnSequence"); 2260 break; 2261 2262 default: 2263 Asn1Error ("ERROR - unexpected tag in CHOICE\n"); 2264 return -1; 2265 break; 2266 } /* end switch */ 2267 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 2268 *v = t = (ComponentName*) CompAlloc( mem_op, sizeof(ComponentName) ); 2269 if ( !t ) return -1; 2270 *t = *k; 2271 } 2272 t->syntax = (Syntax*)NULL; 2273 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 2274 if ( !t->comp_desc ) { 2275 free ( t ); 2276 return -1; 2277 } 2278 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentName ; 2279 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentName ; 2280 t->comp_desc->cd_free = (comp_free_func*)NULL; 2281 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentName; 2282 t->comp_desc->cd_type = ASN_COMPOSITE; 2283 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 2284 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentName; 2285 (*bytesDecoded) += totalElmtsLen1; 2286 return LDAP_SUCCESS; 2287 } /* BDecNameContent */ 2288 2289 int 2290 GDecComponentName PARAMS (( mem_op,b, v, bytesDecoded, mode), 2291 void* mem_op _AND_ 2292 GenBuf * b _AND_ 2293 ComponentName **v _AND_ 2294 AsnLen *bytesDecoded _AND_ 2295 int mode) 2296 { 2297 char* peek_head,*peek_head2; 2298 int i, strLen,strLen2, rc, old_mode = mode; 2299 ComponentName *k,*t, c_temp; 2300 2301 2302 if ( !(mode & DEC_ALLOC_MODE_1) ) { 2303 memset(&c_temp,0,sizeof(c_temp)); 2304 k = &c_temp; 2305 } else 2306 k = t = *v; 2307 mode = DEC_ALLOC_MODE_2; 2308 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2309 Asn1Error("Error during Reading identifier"); 2310 return LDAP_PROTOCOL_ERROR; 2311 } 2312 if( !(strLen2 = LocateNextGSERToken(mem_op,b,&peek_head2,GSER_NO_COPY)) ){ 2313 Asn1Error("Error during Reading identifier"); 2314 return LDAP_PROTOCOL_ERROR; 2315 } 2316 if(*peek_head2 != ':'){ 2317 Asn1Error("Missing : in encoded data"); 2318 return LDAP_PROTOCOL_ERROR; 2319 } 2320 if( strncmp("rdnSequence",peek_head, strlen("rdnSequence")) == 0){ 2321 (k->choiceId) = NAME_RDNSEQUENCE; 2322 rc = GDecComponentRDNSequence (mem_op, b, (&k->a.rdnSequence), bytesDecoded, mode); 2323 if ( rc != LDAP_SUCCESS ) return rc; 2324 (k->a.rdnSequence)->identifier.bv_val = peek_head; 2325 (k->a.rdnSequence)->identifier.bv_len = strLen; 2326 } 2327 else { 2328 Asn1Error("Undefined Identifier"); 2329 return LDAP_PROTOCOL_ERROR; 2330 } 2331 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 2332 *v = t = (ComponentName*) CompAlloc( mem_op, sizeof(ComponentName) ); 2333 if ( !t ) return -1; 2334 *t = *k; 2335 } 2336 t->syntax = (Syntax*)NULL; 2337 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 2338 if ( !t->comp_desc ) { 2339 free ( t ); 2340 return -1; 2341 } 2342 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentName ; 2343 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentName ; 2344 t->comp_desc->cd_free = (comp_free_func*)NULL; 2345 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentName; 2346 t->comp_desc->cd_type = ASN_COMPOSITE; 2347 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 2348 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentName; 2349 return LDAP_SUCCESS; 2350 } /* GDecNameContent */ 2351 2352 2353 int 2354 MatchingComponentTBSCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 2355 int rc; 2356 MatchingRule* mr; 2357 2358 if ( oid ) { 2359 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 2360 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 2361 } 2362 2363 rc = 1; 2364 rc = MatchingComponentVersion ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->version, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->version ); 2365 if ( rc != LDAP_COMPARE_TRUE ) 2366 return rc; 2367 rc = MatchingComponentCertificateSerialNumber ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->serialNumber, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->serialNumber ); 2368 if ( rc != LDAP_COMPARE_TRUE ) 2369 return rc; 2370 rc = MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->signature, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->signature ); 2371 if ( rc != LDAP_COMPARE_TRUE ) 2372 return rc; 2373 rc = MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->issuer, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->issuer ); 2374 if ( rc != LDAP_COMPARE_TRUE ) 2375 return rc; 2376 rc = MatchingComponentValidity ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->validity, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->validity ); 2377 if ( rc != LDAP_COMPARE_TRUE ) 2378 return rc; 2379 rc = MatchingComponentName ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->subject, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->subject ); 2380 if ( rc != LDAP_COMPARE_TRUE ) 2381 return rc; 2382 rc = MatchingComponentSubjectPublicKeyInfo ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->subjectPublicKeyInfo, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->subjectPublicKeyInfo ); 2383 if ( rc != LDAP_COMPARE_TRUE ) 2384 return rc; 2385 rc = MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->issuerUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->issuerUniqueIdentifier ); 2386 if ( rc != LDAP_COMPARE_TRUE ) 2387 return rc; 2388 rc = MatchingComponentUniqueIdentifier ( oid, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_attr)->subjectUniqueIdentifier, (ComponentSyntaxInfo*)&((ComponentTBSCertificate*)csi_assert)->subjectUniqueIdentifier ); 2389 if ( rc != LDAP_COMPARE_TRUE ) 2390 return rc; 2391 if(COMPONENTNOT_NULL( ((ComponentTBSCertificate*)csi_attr)->extensions ) ) { 2392 rc = MatchingComponentExtensions ( oid, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_attr)->extensions, (ComponentSyntaxInfo*)((ComponentTBSCertificate*)csi_assert)->extensions ); 2393 if ( rc != LDAP_COMPARE_TRUE ) 2394 return rc; 2395 } 2396 return LDAP_COMPARE_TRUE; 2397 } /* BMatchingComponentTBSCertificate */ 2398 2399 void* 2400 ExtractingComponentTBSCertificate ( void* mem_op, ComponentReference* cr, ComponentTBSCertificate *comp ) 2401 { 2402 2403 if ( ( comp->version->identifier.bv_val && strncmp(comp->version->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->version->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2404 if ( cr->cr_curr->ci_next == NULL ) 2405 return comp->version; 2406 else { 2407 cr->cr_curr = cr->cr_curr->ci_next; 2408 return ExtractingComponentVersion ( mem_op, cr, comp->version ); 2409 } 2410 } 2411 if ( ( comp->serialNumber.identifier.bv_val && strncmp(comp->serialNumber.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->serialNumber.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2412 if ( cr->cr_curr->ci_next == NULL ) 2413 return &comp->serialNumber; 2414 else 2415 return NULL; 2416 } 2417 if ( ( comp->signature->identifier.bv_val && strncmp(comp->signature->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signature->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2418 if ( cr->cr_curr->ci_next == NULL ) 2419 return comp->signature; 2420 else { 2421 cr->cr_curr = cr->cr_curr->ci_next; 2422 return ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signature ); 2423 } 2424 } 2425 if ( ( comp->issuer->identifier.bv_val && strncmp(comp->issuer->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->issuer->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2426 if ( cr->cr_curr->ci_next == NULL ) 2427 return comp->issuer; 2428 else { 2429 cr->cr_curr = cr->cr_curr->ci_next; 2430 return ExtractingComponentName ( mem_op, cr, comp->issuer ); 2431 } 2432 } 2433 if ( ( comp->validity->identifier.bv_val && strncmp(comp->validity->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->validity->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2434 if ( cr->cr_curr->ci_next == NULL ) 2435 return comp->validity; 2436 else { 2437 cr->cr_curr = cr->cr_curr->ci_next; 2438 return ExtractingComponentValidity ( mem_op, cr, comp->validity ); 2439 } 2440 } 2441 if ( ( comp->subject->identifier.bv_val && strncmp(comp->subject->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subject->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2442 if ( cr->cr_curr->ci_next == NULL ) 2443 return comp->subject; 2444 else { 2445 cr->cr_curr = cr->cr_curr->ci_next; 2446 return ExtractingComponentName ( mem_op, cr, comp->subject ); 2447 } 2448 } 2449 if ( ( comp->subjectPublicKeyInfo->identifier.bv_val && strncmp(comp->subjectPublicKeyInfo->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectPublicKeyInfo->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2450 if ( cr->cr_curr->ci_next == NULL ) 2451 return comp->subjectPublicKeyInfo; 2452 else { 2453 cr->cr_curr = cr->cr_curr->ci_next; 2454 return ExtractingComponentSubjectPublicKeyInfo ( mem_op, cr, comp->subjectPublicKeyInfo ); 2455 } 2456 } 2457 if ( ( comp->issuerUniqueIdentifier.identifier.bv_val && strncmp(comp->issuerUniqueIdentifier.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->issuerUniqueIdentifier.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2458 if ( cr->cr_curr->ci_next == NULL ) 2459 return &comp->issuerUniqueIdentifier; 2460 else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) { 2461 cr->cr_curr = cr->cr_curr->ci_next; 2462 return &comp->issuerUniqueIdentifier; 2463 } else { 2464 return NULL; 2465 } 2466 } 2467 if ( ( comp->subjectUniqueIdentifier.identifier.bv_val && strncmp(comp->subjectUniqueIdentifier.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->subjectUniqueIdentifier.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2468 if ( cr->cr_curr->ci_next == NULL ) 2469 return &comp->subjectUniqueIdentifier; 2470 else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) { 2471 cr->cr_curr = cr->cr_curr->ci_next; 2472 return &comp->subjectUniqueIdentifier; 2473 } else { 2474 return NULL; 2475 } 2476 } 2477 if ( ( comp->extensions->identifier.bv_val && strncmp(comp->extensions->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->extensions->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 2478 if ( cr->cr_curr->ci_next == NULL ) 2479 return comp->extensions; 2480 else { 2481 cr->cr_curr = cr->cr_curr->ci_next; 2482 return ExtractingComponentExtensions ( mem_op, cr, comp->extensions ); 2483 } 2484 } 2485 return NULL; 2486 } /* ExtractingComponentTBSCertificate */ 2487 2488 int 2489 BDecComponentTBSCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 2490 void* mem_op _AND_ 2491 GenBuf * b _AND_ 2492 AsnTag tagId0 _AND_ 2493 AsnLen elmtLen0 _AND_ 2494 ComponentTBSCertificate **v _AND_ 2495 AsnLen *bytesDecoded _AND_ 2496 int mode) 2497 { 2498 int seqDone = FALSE; 2499 AsnLen totalElmtsLen1 = 0; 2500 AsnLen elmtLen1; 2501 AsnTag tagId1; 2502 int mandatoryElmtCount1 = 0; 2503 AsnLen totalElmtsLen2 = 0; 2504 AsnLen elmtLen2; 2505 AsnTag tagId2; 2506 int old_mode = mode; 2507 int rc; 2508 ComponentTBSCertificate *k, *t, c_temp; 2509 2510 2511 if ( !(mode & DEC_ALLOC_MODE_1) ) { 2512 memset(&c_temp,0,sizeof(c_temp)); 2513 k = &c_temp; 2514 } else 2515 k = t = *v; 2516 mode = DEC_ALLOC_MODE_2; 2517 tagId1 = BDecTag (b, &totalElmtsLen1 ); 2518 2519 if (((tagId1 == MAKE_TAG_ID (CNTX, CONS, 0)))) 2520 { 2521 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2522 tagId2 = BDecTag (b, &totalElmtsLen1 ); 2523 2524 if (tagId2 != MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)) 2525 { 2526 Asn1Error ("Unexpected Tag\n"); 2527 return -1; 2528 } 2529 2530 elmtLen2 = BDecLen (b, &totalElmtsLen1 ); 2531 rc = BDecComponentVersion (mem_op, b, tagId2, elmtLen2, (&k->version), &totalElmtsLen1, DEC_ALLOC_MODE_0 ); 2532 if ( rc != LDAP_SUCCESS ) return rc; 2533 (k->version)->identifier.bv_val = (k->version)->id_buf; 2534 (k->version)->identifier.bv_len = strlen("version"); 2535 strcpy( (k->version)->identifier.bv_val, "version"); 2536 if (elmtLen1 == INDEFINITE_LEN) 2537 BDecEoc (b, &totalElmtsLen1 ); 2538 tagId1 = BDecTag (b, &totalElmtsLen1); 2539 } 2540 2541 2542 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, INTEGER_TAG_CODE)))) 2543 { 2544 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2545 rc = BDecComponentCertificateSerialNumber (mem_op, b, tagId1, elmtLen1, (&k->serialNumber), &totalElmtsLen1, mode); 2546 if ( rc != LDAP_SUCCESS ) return rc; 2547 (&k->serialNumber)->identifier.bv_val = (&k->serialNumber)->id_buf; 2548 (&k->serialNumber)->identifier.bv_len = strlen("serialNumber"); 2549 strcpy( (&k->serialNumber)->identifier.bv_val, "serialNumber"); 2550 tagId1 = BDecTag (b, &totalElmtsLen1); 2551 } 2552 else 2553 return -1; 2554 2555 2556 2557 if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) 2558 { 2559 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2560 rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode); 2561 if ( rc != LDAP_SUCCESS ) return rc; 2562 (k->signature)->identifier.bv_val = (k->signature)->id_buf; 2563 (k->signature)->identifier.bv_len = strlen("signature"); 2564 strcpy( (k->signature)->identifier.bv_val, "signature"); 2565 tagId1 = BDecTag (b, &totalElmtsLen1); 2566 } 2567 else 2568 return -1; 2569 2570 2571 2572 if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) 2573 { 2574 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2575 rc = BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->issuer), &totalElmtsLen1, mode); 2576 if ( rc != LDAP_SUCCESS ) return rc; 2577 (k->issuer)->identifier.bv_val = (k->issuer)->id_buf; 2578 (k->issuer)->identifier.bv_len = strlen("issuer"); 2579 strcpy( (k->issuer)->identifier.bv_val, "issuer"); 2580 tagId1 = BDecTag (b, &totalElmtsLen1); 2581 } 2582 else 2583 return -1; 2584 2585 2586 2587 if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) 2588 { 2589 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2590 rc = BDecComponentValidity (mem_op, b, tagId1, elmtLen1, (&k->validity), &totalElmtsLen1, mode); 2591 if ( rc != LDAP_SUCCESS ) return rc; 2592 (k->validity)->identifier.bv_val = (k->validity)->id_buf; 2593 (k->validity)->identifier.bv_len = strlen("validity"); 2594 strcpy( (k->validity)->identifier.bv_val, "validity"); 2595 tagId1 = BDecTag (b, &totalElmtsLen1); 2596 } 2597 else 2598 return -1; 2599 2600 2601 2602 if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) 2603 { 2604 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2605 rc = BDecComponentName (mem_op, b, tagId1, elmtLen1, (&k->subject), &totalElmtsLen1, mode); 2606 if ( rc != LDAP_SUCCESS ) return rc; 2607 (k->subject)->identifier.bv_val = (k->subject)->id_buf; 2608 (k->subject)->identifier.bv_len = strlen("subject"); 2609 strcpy( (k->subject)->identifier.bv_val, "subject"); 2610 tagId1 = BDecTag (b, &totalElmtsLen1); 2611 } 2612 else 2613 return -1; 2614 2615 2616 2617 if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) 2618 { 2619 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2620 rc = BDecComponentSubjectPublicKeyInfo (mem_op, b, tagId1, elmtLen1, (&k->subjectPublicKeyInfo), &totalElmtsLen1, mode); 2621 if ( rc != LDAP_SUCCESS ) return rc; 2622 (k->subjectPublicKeyInfo)->identifier.bv_val = (k->subjectPublicKeyInfo)->id_buf; 2623 (k->subjectPublicKeyInfo)->identifier.bv_len = strlen("subjectPublicKeyInfo"); 2624 strcpy( (k->subjectPublicKeyInfo)->identifier.bv_val, "subjectPublicKeyInfo"); 2625 if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0)) 2626 seqDone = TRUE; 2627 else 2628 { 2629 tagId1 = BDecTag (b, &totalElmtsLen1 ); 2630 2631 if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID)) 2632 { 2633 BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) 2634 seqDone = TRUE; 2635 } 2636 } 2637 } 2638 else 2639 return -1; 2640 2641 2642 2643 if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, PRIM, 1)) || 2644 (tagId1 == MAKE_TAG_ID (CNTX, CONS, 1)))) 2645 { 2646 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2647 rc = BDecComponentUniqueIdentifier (mem_op, b, tagId1, elmtLen1, (&k->issuerUniqueIdentifier), &totalElmtsLen1, mode); 2648 if ( rc != LDAP_SUCCESS ) return rc; 2649 (&k->issuerUniqueIdentifier)->identifier.bv_val = (&k->issuerUniqueIdentifier)->id_buf; 2650 (&k->issuerUniqueIdentifier)->identifier.bv_len = strlen("issuerUniqueIdentifier"); 2651 strcpy( (&k->issuerUniqueIdentifier)->identifier.bv_val, "issuerUniqueIdentifier"); 2652 if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0)) 2653 seqDone = TRUE; 2654 else 2655 { 2656 tagId1 = BDecTag (b, &totalElmtsLen1 ); 2657 2658 if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID)) 2659 { 2660 BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) 2661 seqDone = TRUE; 2662 } 2663 } 2664 } 2665 2666 2667 if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, PRIM, 2)) || 2668 (tagId1 == MAKE_TAG_ID (CNTX, CONS, 2)))) 2669 { 2670 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2671 rc = BDecComponentUniqueIdentifier (mem_op, b, tagId1, elmtLen1, (&k->subjectUniqueIdentifier), &totalElmtsLen1, mode); 2672 if ( rc != LDAP_SUCCESS ) return rc; 2673 (&k->subjectUniqueIdentifier)->identifier.bv_val = (&k->subjectUniqueIdentifier)->id_buf; 2674 (&k->subjectUniqueIdentifier)->identifier.bv_len = strlen("subjectUniqueIdentifier"); 2675 strcpy( (&k->subjectUniqueIdentifier)->identifier.bv_val, "subjectUniqueIdentifier"); 2676 if ((elmtLen0 != INDEFINITE_LEN) && (totalElmtsLen1 == elmtLen0)) 2677 seqDone = TRUE; 2678 else 2679 { 2680 tagId1 = BDecTag (b, &totalElmtsLen1 ); 2681 2682 if ((elmtLen0 == INDEFINITE_LEN) && (tagId1 == EOC_TAG_ID)) 2683 { 2684 BDEC_2ND_EOC_OCTET (b, &totalElmtsLen1 ) 2685 seqDone = TRUE; 2686 } 2687 } 2688 } 2689 2690 2691 if ((!seqDone) && ((tagId1 == MAKE_TAG_ID (CNTX, CONS, 3)))) 2692 { 2693 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 2694 tagId2 = BDecTag (b, &totalElmtsLen1 ); 2695 2696 if (tagId2 != MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)) 2697 { 2698 Asn1Error ("Unexpected Tag\n"); 2699 return -1; 2700 } 2701 2702 elmtLen2 = BDecLen (b, &totalElmtsLen1 ); 2703 rc = BDecComponentExtensions (mem_op, b, tagId2, elmtLen2, (&k->extensions), &totalElmtsLen1, mode); 2704 if ( rc != LDAP_SUCCESS ) return rc; 2705 (k->extensions)->identifier.bv_val = (k->extensions)->id_buf; 2706 (k->extensions)->identifier.bv_len = strlen("extensions"); 2707 strcpy( (k->extensions)->identifier.bv_val, "extensions"); 2708 if (elmtLen1 == INDEFINITE_LEN) 2709 BDecEoc (b, &totalElmtsLen1 ); 2710 seqDone = TRUE; 2711 if (elmtLen0 == INDEFINITE_LEN) 2712 BDecEoc (b, &totalElmtsLen1 ); 2713 else if (totalElmtsLen1 != elmtLen0) 2714 return -1; 2715 2716 } 2717 2718 2719 if (!seqDone) 2720 return -1; 2721 2722 if(!COMPONENTNOT_NULL ((k->version))) 2723 { 2724 (k->version) = CompAlloc( mem_op, sizeof(ComponentVersion)); 2725 (k->version)->identifier.bv_val = (k->version)->id_buf; 2726 (k->version)->identifier.bv_len = strlen("version"); 2727 strcpy( (k->version)->identifier.bv_val, "version"); 2728 (k->version)->value = 0; 2729 } 2730 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 2731 *v = t = (ComponentTBSCertificate*) CompAlloc( mem_op, sizeof(ComponentTBSCertificate) ); 2732 if ( !t ) return -1; 2733 *t = *k; 2734 } 2735 t->syntax = (Syntax*)NULL; 2736 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 2737 if ( !t->comp_desc ) { 2738 free ( t ); 2739 return -1; 2740 } 2741 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertificate ; 2742 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertificate ; 2743 t->comp_desc->cd_free = (comp_free_func*)NULL; 2744 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate; 2745 t->comp_desc->cd_type = ASN_COMPOSITE; 2746 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 2747 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertificate; 2748 (*bytesDecoded) += totalElmtsLen1; 2749 return LDAP_SUCCESS; 2750 } /* BDecTBSCertificate*/ 2751 2752 int 2753 GDecComponentTBSCertificate PARAMS (( mem_op,b, v, bytesDecoded, mode), 2754 void* mem_op _AND_ 2755 GenBuf * b _AND_ 2756 ComponentTBSCertificate **v _AND_ 2757 AsnLen *bytesDecoded _AND_ 2758 int mode) 2759 { 2760 char* peek_head,*peek_head2; 2761 int i, strLen,strLen2, rc, old_mode = mode; 2762 ComponentTBSCertificate *k,*t, c_temp; 2763 2764 2765 if ( !(mode & DEC_ALLOC_MODE_1) ) { 2766 memset(&c_temp,0,sizeof(c_temp)); 2767 k = &c_temp; 2768 } else 2769 k = t = *v; 2770 mode = DEC_ALLOC_MODE_2; 2771 *bytesDecoded = 0; 2772 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2773 Asn1Error("Error during Reading { in encoded data"); 2774 return LDAP_PROTOCOL_ERROR; 2775 } 2776 if(*peek_head != '{'){ 2777 Asn1Error("Missing { in encoded data"); 2778 return LDAP_PROTOCOL_ERROR; 2779 } 2780 2781 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2782 Asn1Error("Error during Reading identifier"); 2783 return LDAP_PROTOCOL_ERROR; 2784 } 2785 if ( strncmp( peek_head, "version", strlen("version") ) == 0 ) { 2786 rc = GDecComponentVersion (mem_op, b, (&k->version), bytesDecoded, DEC_ALLOC_MODE_0 ); 2787 if ( rc != LDAP_SUCCESS ) return rc; 2788 ( k->version)->identifier.bv_val = peek_head; 2789 ( k->version)->identifier.bv_len = strLen; 2790 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2791 Asn1Error("Error during Reading , "); 2792 return LDAP_PROTOCOL_ERROR; 2793 } 2794 if(*peek_head != ','){ 2795 Asn1Error("Missing , in encoding"); 2796 return LDAP_PROTOCOL_ERROR; 2797 } 2798 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2799 Asn1Error("Error during Reading identifier"); 2800 return LDAP_PROTOCOL_ERROR; 2801 } 2802 } 2803 else { 2804 (k->version) = CompAlloc( mem_op, sizeof(ComponentVersion)); 2805 (k->version)->value = 0; 2806 } 2807 if ( strncmp( peek_head, "serialNumber", strlen("serialNumber") ) == 0 ) { 2808 rc = GDecComponentCertificateSerialNumber (mem_op, b, (&k->serialNumber), bytesDecoded, mode); 2809 if ( rc != LDAP_SUCCESS ) return rc; 2810 (&k->serialNumber)->identifier.bv_val = peek_head; 2811 (&k->serialNumber)->identifier.bv_len = strLen; 2812 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2813 Asn1Error("Error during Reading , "); 2814 return LDAP_PROTOCOL_ERROR; 2815 } 2816 if(*peek_head != ','){ 2817 Asn1Error("Missing , in encoding"); 2818 return LDAP_PROTOCOL_ERROR; 2819 } 2820 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2821 Asn1Error("Error during Reading identifier"); 2822 return LDAP_PROTOCOL_ERROR; 2823 } 2824 } 2825 if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) { 2826 rc = GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signature), bytesDecoded, mode); 2827 if ( rc != LDAP_SUCCESS ) return rc; 2828 ( k->signature)->identifier.bv_val = peek_head; 2829 ( k->signature)->identifier.bv_len = strLen; 2830 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2831 Asn1Error("Error during Reading , "); 2832 return LDAP_PROTOCOL_ERROR; 2833 } 2834 if(*peek_head != ','){ 2835 Asn1Error("Missing , in encoding"); 2836 return LDAP_PROTOCOL_ERROR; 2837 } 2838 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2839 Asn1Error("Error during Reading identifier"); 2840 return LDAP_PROTOCOL_ERROR; 2841 } 2842 } 2843 if ( strncmp( peek_head, "issuer", strlen("issuer") ) == 0 ) { 2844 rc = GDecComponentName (mem_op, b, (&k->issuer), bytesDecoded, mode); 2845 if ( rc != LDAP_SUCCESS ) return rc; 2846 ( k->issuer)->identifier.bv_val = peek_head; 2847 ( k->issuer)->identifier.bv_len = strLen; 2848 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2849 Asn1Error("Error during Reading , "); 2850 return LDAP_PROTOCOL_ERROR; 2851 } 2852 if(*peek_head != ','){ 2853 Asn1Error("Missing , in encoding"); 2854 return LDAP_PROTOCOL_ERROR; 2855 } 2856 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2857 Asn1Error("Error during Reading identifier"); 2858 return LDAP_PROTOCOL_ERROR; 2859 } 2860 } 2861 if ( strncmp( peek_head, "validity", strlen("validity") ) == 0 ) { 2862 rc = GDecComponentValidity (mem_op, b, (&k->validity), bytesDecoded, mode); 2863 if ( rc != LDAP_SUCCESS ) return rc; 2864 ( k->validity)->identifier.bv_val = peek_head; 2865 ( k->validity)->identifier.bv_len = strLen; 2866 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2867 Asn1Error("Error during Reading , "); 2868 return LDAP_PROTOCOL_ERROR; 2869 } 2870 if(*peek_head != ','){ 2871 Asn1Error("Missing , in encoding"); 2872 return LDAP_PROTOCOL_ERROR; 2873 } 2874 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2875 Asn1Error("Error during Reading identifier"); 2876 return LDAP_PROTOCOL_ERROR; 2877 } 2878 } 2879 if ( strncmp( peek_head, "subject", strlen("subject") ) == 0 ) { 2880 rc = GDecComponentName (mem_op, b, (&k->subject), bytesDecoded, mode); 2881 if ( rc != LDAP_SUCCESS ) return rc; 2882 ( k->subject)->identifier.bv_val = peek_head; 2883 ( k->subject)->identifier.bv_len = strLen; 2884 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2885 Asn1Error("Error during Reading , "); 2886 return LDAP_PROTOCOL_ERROR; 2887 } 2888 if(*peek_head != ','){ 2889 Asn1Error("Missing , in encoding"); 2890 return LDAP_PROTOCOL_ERROR; 2891 } 2892 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2893 Asn1Error("Error during Reading identifier"); 2894 return LDAP_PROTOCOL_ERROR; 2895 } 2896 } 2897 if ( strncmp( peek_head, "subjectPublicKeyInfo", strlen("subjectPublicKeyInfo") ) == 0 ) { 2898 rc = GDecComponentSubjectPublicKeyInfo (mem_op, b, (&k->subjectPublicKeyInfo), bytesDecoded, mode); 2899 if ( rc != LDAP_SUCCESS ) return rc; 2900 ( k->subjectPublicKeyInfo)->identifier.bv_val = peek_head; 2901 ( k->subjectPublicKeyInfo)->identifier.bv_len = strLen; 2902 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2903 Asn1Error("Error during Reading , "); 2904 return LDAP_PROTOCOL_ERROR; 2905 } 2906 if(*peek_head != ','){ 2907 Asn1Error("Missing , in encoding"); 2908 return LDAP_PROTOCOL_ERROR; 2909 } 2910 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2911 Asn1Error("Error during Reading identifier"); 2912 return LDAP_PROTOCOL_ERROR; 2913 } 2914 } 2915 if ( strncmp( peek_head, "issuerUniqueIdentifier", strlen("issuerUniqueIdentifier") ) == 0 ) { 2916 rc = GDecComponentUniqueIdentifier (mem_op, b, (&k->issuerUniqueIdentifier), bytesDecoded, mode); 2917 if ( rc != LDAP_SUCCESS ) return rc; 2918 (&k->issuerUniqueIdentifier)->identifier.bv_val = peek_head; 2919 (&k->issuerUniqueIdentifier)->identifier.bv_len = strLen; 2920 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2921 Asn1Error("Error during Reading , "); 2922 return LDAP_PROTOCOL_ERROR; 2923 } 2924 if(*peek_head != ','){ 2925 Asn1Error("Missing , in encoding"); 2926 return LDAP_PROTOCOL_ERROR; 2927 } 2928 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2929 Asn1Error("Error during Reading identifier"); 2930 return LDAP_PROTOCOL_ERROR; 2931 } 2932 } 2933 if ( strncmp( peek_head, "subjectUniqueIdentifier", strlen("subjectUniqueIdentifier") ) == 0 ) { 2934 rc = GDecComponentUniqueIdentifier (mem_op, b, (&k->subjectUniqueIdentifier), bytesDecoded, mode); 2935 if ( rc != LDAP_SUCCESS ) return rc; 2936 (&k->subjectUniqueIdentifier)->identifier.bv_val = peek_head; 2937 (&k->subjectUniqueIdentifier)->identifier.bv_len = strLen; 2938 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2939 Asn1Error("Error during Reading , "); 2940 return LDAP_PROTOCOL_ERROR; 2941 } 2942 if(*peek_head != ','){ 2943 Asn1Error("Missing , in encoding"); 2944 return LDAP_PROTOCOL_ERROR; 2945 } 2946 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 2947 Asn1Error("Error during Reading identifier"); 2948 return LDAP_PROTOCOL_ERROR; 2949 } 2950 } 2951 if ( strncmp( peek_head, "extensions", strlen("extensions") ) == 0 ) { 2952 rc = GDecComponentExtensions (mem_op, b, (&k->extensions), bytesDecoded, mode); 2953 if ( rc != LDAP_SUCCESS ) return rc; 2954 ( k->extensions)->identifier.bv_val = peek_head; 2955 ( k->extensions)->identifier.bv_len = strLen; 2956 } 2957 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { 2958 Asn1Error("Error during Reading } in encoding"); 2959 return LDAP_PROTOCOL_ERROR; 2960 } 2961 if(*peek_head != '}'){ 2962 Asn1Error("Missing } in encoding"); 2963 return LDAP_PROTOCOL_ERROR; 2964 } 2965 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 2966 *v = t = (ComponentTBSCertificate*) CompAlloc( mem_op, sizeof(ComponentTBSCertificate) ); 2967 if ( !t ) return -1; 2968 *t = *k; 2969 } 2970 t->syntax = (Syntax*)NULL; 2971 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 2972 if ( !t->comp_desc ) { 2973 free ( t ); 2974 return -1; 2975 } 2976 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentTBSCertificate ; 2977 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentTBSCertificate ; 2978 t->comp_desc->cd_free = (comp_free_func*)NULL; 2979 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentTBSCertificate; 2980 t->comp_desc->cd_type = ASN_COMPOSITE; 2981 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 2982 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentTBSCertificate; 2983 return LDAP_SUCCESS; 2984 } /* GDecTBSCertificate*/ 2985 2986 2987 int 2988 MatchingComponentCertificate ( char* oid, ComponentSyntaxInfo* csi_attr, ComponentSyntaxInfo* csi_assert ) { 2989 int rc; 2990 MatchingRule* mr; 2991 2992 if ( oid ) { 2993 mr = retrieve_matching_rule( oid, csi_attr->csi_comp_desc->cd_type_id); 2994 if ( mr ) return component_value_match( mr, csi_attr, csi_assert ); 2995 } 2996 2997 rc = 1; 2998 rc = MatchingComponentTBSCertificate ( oid, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_attr)->toBeSigned, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_assert)->toBeSigned ); 2999 if ( rc != LDAP_COMPARE_TRUE ) 3000 return rc; 3001 rc = MatchingComponentAlgorithmIdentifier ( oid, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_attr)->signatureAlgorithm, (ComponentSyntaxInfo*)((ComponentCertificate*)csi_assert)->signatureAlgorithm ); 3002 if ( rc != LDAP_COMPARE_TRUE ) 3003 return rc; 3004 rc = MatchingComponentBits ( oid, (ComponentSyntaxInfo*)&((ComponentCertificate*)csi_attr)->signature, (ComponentSyntaxInfo*)&((ComponentCertificate*)csi_assert)->signature ); 3005 if ( rc != LDAP_COMPARE_TRUE ) 3006 return rc; 3007 return LDAP_COMPARE_TRUE; 3008 } /* BMatchingComponentCertificate */ 3009 3010 void* 3011 ExtractingComponentCertificate ( void* mem_op, ComponentReference* cr, ComponentCertificate *comp ) 3012 { 3013 3014 if ( ( comp->toBeSigned->identifier.bv_val && strncmp(comp->toBeSigned->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->toBeSigned->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 3015 if ( cr->cr_curr->ci_next == NULL ) 3016 return comp->toBeSigned; 3017 else { 3018 cr->cr_curr = cr->cr_curr->ci_next; 3019 return ExtractingComponentTBSCertificate ( mem_op, cr, comp->toBeSigned ); 3020 } 3021 } 3022 if ( ( comp->signatureAlgorithm->identifier.bv_val && strncmp(comp->signatureAlgorithm->identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signatureAlgorithm->id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 3023 if ( cr->cr_curr->ci_next == NULL ) 3024 return comp->signatureAlgorithm; 3025 else { 3026 cr->cr_curr = cr->cr_curr->ci_next; 3027 return ExtractingComponentAlgorithmIdentifier ( mem_op, cr, comp->signatureAlgorithm ); 3028 } 3029 } 3030 if ( ( comp->signature.identifier.bv_val && strncmp(comp->signature.identifier.bv_val, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) || ( strncmp(comp->signature.id_buf, cr->cr_curr->ci_val.ci_identifier.bv_val,cr->cr_curr->ci_val.ci_identifier.bv_len) == 0 ) ) { 3031 if ( cr->cr_curr->ci_next == NULL ) 3032 return &comp->signature; 3033 else if ( cr->cr_curr->ci_next->ci_type == LDAP_COMPREF_CONTENT) { 3034 cr->cr_curr = cr->cr_curr->ci_next; 3035 return &comp->signature; 3036 } else { 3037 return NULL; 3038 } 3039 } 3040 return NULL; 3041 } /* ExtractingComponentCertificate */ 3042 3043 int 3044 BDecComponentCertificate PARAMS ((b, tagId0, elmtLen0, v, bytesDecoded, mode), 3045 void* mem_op _AND_ 3046 GenBuf * b _AND_ 3047 AsnTag tagId0 _AND_ 3048 AsnLen elmtLen0 _AND_ 3049 ComponentCertificate **v _AND_ 3050 AsnLen *bytesDecoded _AND_ 3051 int mode) 3052 { 3053 int seqDone = FALSE; 3054 AsnLen totalElmtsLen1 = 0; 3055 AsnLen elmtLen1; 3056 AsnTag tagId1; 3057 int mandatoryElmtCount1 = 0; 3058 int old_mode = mode; 3059 int rc; 3060 ComponentCertificate *k, *t, c_temp; 3061 3062 3063 if ( !(mode & DEC_ALLOC_MODE_1) ) { 3064 memset(&c_temp,0,sizeof(c_temp)); 3065 k = &c_temp; 3066 } else 3067 k = t = *v; 3068 mode = DEC_ALLOC_MODE_2; 3069 tagId1 = BDecTag (b, &totalElmtsLen1 ); 3070 3071 if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) 3072 { 3073 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 3074 rc = BDecComponentTBSCertificate (mem_op, b, tagId1, elmtLen1, (&k->toBeSigned), &totalElmtsLen1, mode); 3075 if ( rc != LDAP_SUCCESS ) return rc; 3076 (k->toBeSigned)->identifier.bv_val = (k->toBeSigned)->id_buf; 3077 (k->toBeSigned)->identifier.bv_len = strlen("toBeSigned"); 3078 strcpy( (k->toBeSigned)->identifier.bv_val, "toBeSigned"); 3079 tagId1 = BDecTag (b, &totalElmtsLen1); 3080 } 3081 else 3082 return -1; 3083 3084 3085 3086 if (((tagId1 == MAKE_TAG_ID (UNIV, CONS, SEQ_TAG_CODE)))) 3087 { 3088 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 3089 rc = BDecComponentAlgorithmIdentifier (mem_op, b, tagId1, elmtLen1, (&k->signatureAlgorithm), &totalElmtsLen1, mode); 3090 if ( rc != LDAP_SUCCESS ) return rc; 3091 (k->signatureAlgorithm)->identifier.bv_val = (k->signatureAlgorithm)->id_buf; 3092 (k->signatureAlgorithm)->identifier.bv_len = strlen("signatureAlgorithm"); 3093 strcpy( (k->signatureAlgorithm)->identifier.bv_val, "signatureAlgorithm"); 3094 tagId1 = BDecTag (b, &totalElmtsLen1); 3095 } 3096 else 3097 return -1; 3098 3099 3100 3101 if (((tagId1 == MAKE_TAG_ID (UNIV, PRIM, BITSTRING_TAG_CODE)) || 3102 (tagId1 == MAKE_TAG_ID (UNIV, CONS, BITSTRING_TAG_CODE)))) 3103 { 3104 elmtLen1 = BDecLen (b, &totalElmtsLen1 ); 3105 rc = BDecComponentBits (mem_op, b, tagId1, elmtLen1, (&k->signature), &totalElmtsLen1, mode); 3106 if ( rc != LDAP_SUCCESS ) return rc; 3107 (&k->signature)->identifier.bv_val = (&k->signature)->id_buf; 3108 (&k->signature)->identifier.bv_len = strlen("signature"); 3109 strcpy( (&k->signature)->identifier.bv_val, "signature"); 3110 seqDone = TRUE; 3111 if (elmtLen0 == INDEFINITE_LEN) 3112 BDecEoc (b, &totalElmtsLen1 ); 3113 else if (totalElmtsLen1 != elmtLen0) 3114 return -1; 3115 3116 } 3117 else 3118 return -1; 3119 3120 3121 3122 if (!seqDone) 3123 return -1; 3124 3125 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 3126 *v = t = (ComponentCertificate*) CompAlloc( mem_op, sizeof(ComponentCertificate) ); 3127 if ( !t ) return -1; 3128 *t = *k; 3129 } 3130 t->syntax = (Syntax*)NULL; 3131 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 3132 if ( !t->comp_desc ) { 3133 free ( t ); 3134 return -1; 3135 } 3136 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificate ; 3137 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificate ; 3138 t->comp_desc->cd_free = (comp_free_func*)NULL; 3139 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate; 3140 t->comp_desc->cd_type = ASN_COMPOSITE; 3141 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 3142 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificate; 3143 (*bytesDecoded) += totalElmtsLen1; 3144 return LDAP_SUCCESS; 3145 } /* BDecCertificate*/ 3146 3147 int 3148 GDecComponentCertificate PARAMS (( mem_op,b, v, bytesDecoded, mode), 3149 void* mem_op _AND_ 3150 GenBuf * b _AND_ 3151 ComponentCertificate **v _AND_ 3152 AsnLen *bytesDecoded _AND_ 3153 int mode) 3154 { 3155 char* peek_head,*peek_head2; 3156 int i, strLen,strLen2, rc, old_mode = mode; 3157 ComponentCertificate *k,*t, c_temp; 3158 3159 3160 if ( !(mode & DEC_ALLOC_MODE_1) ) { 3161 memset(&c_temp,0,sizeof(c_temp)); 3162 k = &c_temp; 3163 } else 3164 k = t = *v; 3165 mode = DEC_ALLOC_MODE_2; 3166 *bytesDecoded = 0; 3167 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 3168 Asn1Error("Error during Reading { in encoded data"); 3169 return LDAP_PROTOCOL_ERROR; 3170 } 3171 if(*peek_head != '{'){ 3172 Asn1Error("Missing { in encoded data"); 3173 return LDAP_PROTOCOL_ERROR; 3174 } 3175 3176 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 3177 Asn1Error("Error during Reading identifier"); 3178 return LDAP_PROTOCOL_ERROR; 3179 } 3180 if ( strncmp( peek_head, "toBeSigned", strlen("toBeSigned") ) == 0 ) { 3181 rc = GDecComponentTBSCertificate (mem_op, b, (&k->toBeSigned), bytesDecoded, mode); 3182 if ( rc != LDAP_SUCCESS ) return rc; 3183 ( k->toBeSigned)->identifier.bv_val = peek_head; 3184 ( k->toBeSigned)->identifier.bv_len = strLen; 3185 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 3186 Asn1Error("Error during Reading , "); 3187 return LDAP_PROTOCOL_ERROR; 3188 } 3189 if(*peek_head != ','){ 3190 Asn1Error("Missing , in encoding"); 3191 return LDAP_PROTOCOL_ERROR; 3192 } 3193 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 3194 Asn1Error("Error during Reading identifier"); 3195 return LDAP_PROTOCOL_ERROR; 3196 } 3197 } 3198 if ( strncmp( peek_head, "signatureAlgorithm", strlen("signatureAlgorithm") ) == 0 ) { 3199 rc = GDecComponentAlgorithmIdentifier (mem_op, b, (&k->signatureAlgorithm), bytesDecoded, mode); 3200 if ( rc != LDAP_SUCCESS ) return rc; 3201 ( k->signatureAlgorithm)->identifier.bv_val = peek_head; 3202 ( k->signatureAlgorithm)->identifier.bv_len = strLen; 3203 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 3204 Asn1Error("Error during Reading , "); 3205 return LDAP_PROTOCOL_ERROR; 3206 } 3207 if(*peek_head != ','){ 3208 Asn1Error("Missing , in encoding"); 3209 return LDAP_PROTOCOL_ERROR; 3210 } 3211 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ){ 3212 Asn1Error("Error during Reading identifier"); 3213 return LDAP_PROTOCOL_ERROR; 3214 } 3215 } 3216 if ( strncmp( peek_head, "signature", strlen("signature") ) == 0 ) { 3217 rc = GDecComponentBits (mem_op, b, (&k->signature), bytesDecoded, mode); 3218 if ( rc != LDAP_SUCCESS ) return rc; 3219 (&k->signature)->identifier.bv_val = peek_head; 3220 (&k->signature)->identifier.bv_len = strLen; 3221 } 3222 if( !(strLen = LocateNextGSERToken(mem_op,b,&peek_head,GSER_NO_COPY)) ) { 3223 Asn1Error("Error during Reading } in encoding"); 3224 return LDAP_PROTOCOL_ERROR; 3225 } 3226 if(*peek_head != '}'){ 3227 Asn1Error("Missing } in encoding"); 3228 return LDAP_PROTOCOL_ERROR; 3229 } 3230 if( !(old_mode & DEC_ALLOC_MODE_1) ) { 3231 *v = t = (ComponentCertificate*) CompAlloc( mem_op, sizeof(ComponentCertificate) ); 3232 if ( !t ) return -1; 3233 *t = *k; 3234 } 3235 t->syntax = (Syntax*)NULL; 3236 t->comp_desc = CompAlloc( mem_op, sizeof( ComponentDesc ) ); 3237 if ( !t->comp_desc ) { 3238 free ( t ); 3239 return -1; 3240 } 3241 t->comp_desc->cd_gser_decoder = (gser_decoder_func*)GDecComponentCertificate ; 3242 t->comp_desc->cd_ber_decoder = (ber_decoder_func*)BDecComponentCertificate ; 3243 t->comp_desc->cd_free = (comp_free_func*)NULL; 3244 t->comp_desc->cd_extract_i = (extract_component_from_id_func*)ExtractingComponentCertificate; 3245 t->comp_desc->cd_type = ASN_COMPOSITE; 3246 t->comp_desc->cd_type_id = COMPOSITE_ASN1_TYPE; 3247 t->comp_desc->cd_all_match = (allcomponent_matching_func*)MatchingComponentCertificate; 3248 return LDAP_SUCCESS; 3249 } /* GDecCertificate*/ 3250 3251 3252