void SODParser::ParseSodEncapsulatedContent(const CByteArray & contents){ ASN1_ITEM xLev0Item; ASN1_ITEM xLev1Item; ASN1_ITEM xLev2Item; ASN1_ITEM xLev3Item; ASN1_ITEM xLev4Item; xLev0Item.p_data = (unsigned char*)contents.GetBytes(); xLev0Item.l_data = contents.Size(); if ((asn1_next_item(&xLev0Item, &xLev1Item)!= 0) ||(xLev1Item.tag != ASN_SEQUENCE)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); if ((xLev1Item.l_data < 2)|| (asn1_next_item(&xLev1Item, &xLev2Item)!= 0) ||(xLev2Item.tag != ASN_INTEGER)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); if (bin2int(xLev2Item.p_data, xLev2Item.l_data)!=0) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_VALUE); if ((xLev1Item.l_data < 2)|| (asn1_next_item(&xLev1Item, &xLev2Item)!= 0) ||(xLev2Item.tag != ASN_SEQUENCE)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); if ((xLev2Item.l_data < 2)|| (asn1_next_item(&xLev2Item, &xLev3Item)!= 0) ||(xLev3Item.tag != ASN_OID)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); // martinho: not the intended way, but for now it will do just fine. if (memcmp(xLev3Item.p_data, OID_SHA256_ALGORITHM, xLev3Item.l_data) != 0) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ALGO_OID); if ((xLev2Item.l_data < 2)|| (asn1_next_item(&xLev2Item, &xLev3Item)!= 0) ||(xLev3Item.tag != ASN_NULL)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); if ((xLev1Item.l_data < 2)|| (asn1_next_item(&xLev1Item, &xLev2Item)!= 0) ||(xLev2Item.tag != ASN_SEQUENCE)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); attr = new SODAttributes(); int i=0; while(xLev2Item.l_data > 0){ if ((xLev2Item.l_data < 2)|| (asn1_next_item(&xLev2Item, &xLev3Item)!= 0) ||(xLev3Item.tag != ASN_SEQUENCE)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); if ((xLev3Item.l_data < 2)|| (asn1_next_item(&xLev3Item, &xLev4Item)!= 0) ||(xLev4Item.tag != ASN_INTEGER)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); if (bin2int(xLev4Item.p_data, xLev4Item.l_data)!=(i+1)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_VALUE); if ((xLev3Item.l_data < 2)|| (asn1_next_item(&xLev3Item, &xLev4Item)!= 0) ||(xLev4Item.tag != ASN_OCTET_STRING)) throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG); attr->hashes[i].Append(xLev4Item.p_data,xLev4Item.l_data); i++; } }
static plist_t profile_get_embedded_plist(plist_t profile) { if (plist_get_node_type(profile) != PLIST_DATA) { fprintf(stderr, "%s: unexpected plist node type for profile (PLIST_DATA expected)\n", __FUNCTION__); return NULL; } char* bbuf = NULL; uint64_t blen = 0; plist_get_data_val(profile, &bbuf, &blen); if (!bbuf) { fprintf(stderr, "%s: could not get data value from plist node\n", __FUNCTION__); return NULL; } unsigned char* pp = (unsigned char*)bbuf; if (*pp != ASN1_SEQUENCE) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (0)\n", __FUNCTION__); return NULL; } uint16_t slen = asn1_item_get_size(pp); if (slen+4 != (uint16_t)blen) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (1)\n", __FUNCTION__); return NULL; } asn1_next_item(&pp); if (*pp != ASN1_OBJECT_IDENTIFIER) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (2)\n", __FUNCTION__); return NULL; } asn1_skip_item(&pp); if (*pp != ASN1_CONTAINER) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (3)\n", __FUNCTION__); return NULL; } asn1_next_item(&pp); if (*pp != ASN1_SEQUENCE) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (4)\n", __FUNCTION__); return NULL; } asn1_next_item(&pp); int k = 0; // go to the 3rd element (skip 2) while (k < 2) { asn1_skip_item(&pp); k++; } if (*pp != ASN1_SEQUENCE) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (5)\n", __FUNCTION__); return NULL; } asn1_next_item(&pp); if (*pp != ASN1_OBJECT_IDENTIFIER) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (6)\n", __FUNCTION__); return NULL; } asn1_skip_item(&pp); if (*pp != ASN1_CONTAINER) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (7)\n", __FUNCTION__); return NULL; } asn1_next_item(&pp); if (*pp != ASN1_OCTET_STRING) { free(bbuf); fprintf(stderr, "%s: unexpected profile data (8)\n", __FUNCTION__); return NULL; } slen = asn1_item_get_size(pp); asn1_next_item(&pp); plist_t pl = NULL; plist_from_xml((char*)pp, slen, &pl); free(bbuf); return pl; }