Changeset 74672 in vbox for trunk/src/VBox
- Timestamp:
- Oct 8, 2018 12:08:51 PM (6 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/VBox/VBoxRTImp.def
r74654 r74672 117 117 RTAsn1Core_SetTagAndFlags 118 118 RTAsn1CursorCheckEnd 119 RTAsn1CursorCheckSeqEnd 120 RTAsn1CursorCheckSetEnd 119 121 RTAsn1CursorGetBitString 120 122 RTAsn1CursorGetBitStringEx -
trunk/src/VBox/Runtime/common/asn1/asn1-cursor.cpp
r74657 r74672 68 68 pPrimaryCursor->Cursor.fFlags = (uint8_t)fFlags; Assert(fFlags <= UINT8_MAX); 69 69 pPrimaryCursor->Cursor.cDepth = 0; 70 pPrimaryCursor->Cursor.cIndefinedRecs = 0;71 70 pPrimaryCursor->Cursor.abReserved[0] = 0; 71 pPrimaryCursor->Cursor.abReserved[1] = 0; 72 72 pPrimaryCursor->Cursor.pPrimary = pPrimaryCursor; 73 73 pPrimaryCursor->Cursor.pUp = NULL; … … 89 89 pChild->cDepth = pParent->cDepth + 1; 90 90 AssertReturn(pChild->cDepth < RTASN1_MAX_NESTING, VERR_ASN1_TOO_DEEPLY_NESTED); 91 pChild->cIndefinedRecs = 0;92 91 pChild->abReserved[0] = 0; 92 pChild->abReserved[1] = 0; 93 93 pChild->pPrimary = pParent->pPrimary; 94 94 pChild->pUp = pParent; … … 114 114 pChild->cDepth = pParent->cDepth + 1; 115 115 AssertReturn(pChild->cDepth < RTASN1_MAX_NESTING, VERR_ASN1_TOO_DEEPLY_NESTED); 116 pChild->cIndefinedRecs = 0;117 116 pChild->abReserved[0] = 0; 117 pChild->abReserved[1] = 0; 118 118 pChild->pPrimary = pParent->pPrimary; 119 119 pChild->pUp = pParent; … … 194 194 if (!(pCursor->fFlags & RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH)) 195 195 return false; 196 /* This isn't quite right. */ 197 if (pCursor->cbLeft > pCursor->cIndefinedRecs * (uint32_t)2) 198 return false; 199 return ASMMemIsZero(pCursor->pbCur, pCursor->cbLeft); 196 return pCursor->cbLeft >= 2 197 && pCursor->pbCur[0] == 0 198 && pCursor->pbCur[1] == 0; 200 199 } 201 200 … … 205 204 if (pCursor->cbLeft == 0) 206 205 return VINF_SUCCESS; 207 if ( (pCursor->fFlags & RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH) 208 && pCursor->cbLeft == pCursor->cIndefinedRecs * (uint32_t)2 209 && ASMMemIsZero(pCursor->pbCur, pCursor->cbLeft)) 210 return VINF_SUCCESS; 206 207 if (pCursor->fFlags & RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH) 208 { 209 /* 210 * If we've got two zeros here we're good. This helps us handle apple code 211 * signatures, where most of the big structures are of indefinite length. 212 * The problem here is when rtCrPkcs7ContentInfo_DecodeExtra works the 213 * octet string, it appears as if there extra padding at the end. 214 * 215 * It is of course possible that ASN.1 assumes we will parse the content of 216 * that octet string as if it were an ASN.1 substructure, looking for the 217 * end-of-content sequence and propage that up. However, this works for now. 218 */ 219 if (pCursor->cbLeft >= 2) 220 { 221 if ( pCursor->pbCur[0] == 0 222 && pCursor->pbCur[1] == 0) 223 return VINF_SUCCESS; 224 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END, 225 "%u (%#x) bytes left over [indef: %.*Rhxs]", 226 pCursor->cbLeft, pCursor->cbLeft, RT_MIN(pCursor->cbLeft, 16), pCursor->pbCur); 227 } 228 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END, 229 "%u (%#x) bytes left over [indef len]", pCursor->cbLeft, pCursor->cbLeft); 230 } 211 231 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END, 212 232 "%u (%#x) bytes left over", pCursor->cbLeft, pCursor->cbLeft); 233 } 234 235 236 /** 237 * Worker for RTAsn1CursorCheckSeqEnd and RTAsn1CursorCheckSetEnd. 238 */ 239 static int rtAsn1CursorCheckSeqOrSetEnd(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core) 240 { 241 if (pCursor->cbLeft == 0) 242 return VINF_SUCCESS; 243 244 if (pAsn1Core->fFlags & RTASN1CORE_F_INDEFINITE_LENGTH) 245 { 246 if (pCursor->cbLeft >= 2) 247 { 248 if ( pCursor->pbCur[0] == 0 249 && pCursor->pbCur[1] == 0) 250 { 251 pAsn1Core->cb = (uint32_t)(pCursor->pbCur - pAsn1Core->uData.pu8); 252 pCursor->cbLeft -= 2; 253 pCursor->pbCur += 2; 254 255 PRTASN1CURSOR pParentCursor = pCursor->pUp; 256 if ( pParentCursor 257 && (pParentCursor->fFlags & RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH)) 258 { 259 pParentCursor->pbCur -= pCursor->cbLeft; 260 pParentCursor->cbLeft += pCursor->cbLeft; 261 return VINF_SUCCESS; 262 } 263 264 if (pCursor->cbLeft == 0) 265 return VINF_SUCCESS; 266 267 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END, 268 "%u (%#x) bytes left over (parent not indefinite length)", pCursor->cbLeft, pCursor->cbLeft); 269 } 270 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END, "%u (%#x) bytes left over [indef: %.*Rhxs]", 271 pCursor->cbLeft, pCursor->cbLeft, RT_MIN(pCursor->cbLeft, 16), pCursor->pbCur); 272 } 273 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END, 274 "1 byte left over, expected two for indefinite length end-of-content sequence"); 275 } 276 277 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END, 278 "%u (%#x) bytes left over", pCursor->cbLeft, pCursor->cbLeft); 279 280 } 281 282 283 RTDECL(int) RTAsn1CursorCheckSeqEnd(PRTASN1CURSOR pCursor, PRTASN1SEQUENCECORE pSeqCore) 284 { 285 return rtAsn1CursorCheckSeqOrSetEnd(pCursor, &pSeqCore->Asn1Core); 286 } 287 288 289 RTDECL(int) RTAsn1CursorCheckSetEnd(PRTASN1CURSOR pCursor, PRTASN1SETCORE pSetCore) 290 { 291 return rtAsn1CursorCheckSeqOrSetEnd(pCursor, &pSetCore->Asn1Core); 213 292 } 214 293 … … 337 416 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_INDEFINITE_LENGTH, 338 417 "%s: Indefinite BER/CER encoding not supported for this tag (uTag=%#x)", pszErrorTag, uTag); 339 else if (pCursor-> cIndefinedRecs > 8)418 else if (pCursor->fFlags & RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH) 340 419 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_INDEFINITE_LENGTH, 341 "%s: Too many indefinite BER/CER encodings. (uTag=%#x)", pszErrorTag, uTag);420 "%s: Nested indefinite BER/CER encoding. (uTag=%#x)", pszErrorTag, uTag); 342 421 else if (pCursor->cbLeft < 2) 343 422 return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_INDEFINITE_LENGTH, … … 345 424 else 346 425 { 347 pCursor->cIndefinedRecs++;348 426 pCursor->fFlags |= RTASN1CURSOR_FLAGS_INDEFINITE_LENGTH; 349 427 pAsn1Core->fFlags |= RTASN1CORE_F_INDEFINITE_LENGTH; 350 cb = pCursor->cbLeft - pCursor->cIndefinedRecs * 2; /* tentatively*/428 cb = pCursor->cbLeft - 2; /* tentatively for sequences and sets, definite for others */ 351 429 } 352 430 } 431 /* else if (cb == 0 && uTag == 0) { end of content } - callers handle this */ 353 432 354 433 /* Check if the length makes sense. */ … … 474 553 RTDECL(int) RTAsn1CursorPeek(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core) 475 554 { 476 uint32_t cbSavedLeft = pCursor->cbLeft; 477 uint8_t const *pbSavedCur = pCursor->pbCur; 478 PRTERRINFO pErrInfo = pCursor->pPrimary->pErrInfo; 555 uint32_t cbSavedLeft = pCursor->cbLeft; 556 uint8_t const *pbSavedCur = pCursor->pbCur; 557 uint8_t const fSavedFlags = pCursor->fFlags; 558 PRTERRINFO const pErrInfo = pCursor->pPrimary->pErrInfo; 479 559 pCursor->pPrimary->pErrInfo = NULL; 480 560 … … 482 562 483 563 pCursor->pPrimary->pErrInfo = pErrInfo; 484 pCursor->pbCur = pbSavedCur; 485 pCursor->cbLeft = cbSavedLeft; 564 pCursor->pbCur = pbSavedCur; 565 pCursor->cbLeft = cbSavedLeft; 566 pCursor->fFlags = fSavedFlags; 486 567 return rc; 487 568 } -
trunk/src/VBox/Runtime/common/crypto/pkcs7-asn1-decoder.cpp
r69111 r74672 90 90 { 91 91 /* 92 * Detect CMS octet string and open the content cursor. 93 * Current we don't have work with any contet which is octet string, 94 * they're all sequences, which make detection so much simpler. 92 * Detect CMS octet string format and open the content cursor. 93 * 94 * Current we don't have any octent string content which, they're all 95 * sequences, which make detection so much simpler. 95 96 */ 96 97 PRTASN1OCTETSTRING pOctetString = &pThis->Content; -
trunk/src/VBox/Runtime/tools/RTSignTool.cpp
r73097 r74672 629 629 if (cVerbosity > 2) 630 630 RTPrintf("PKCS#7 signature: %u bytes\n", cbActual); 631 if (cVerbosity > 3) 632 RTPrintf("%.*Rhxd\n", cbActual, pvBuf); 631 633 632 634 /*
Note:
See TracChangeset
for help on using the changeset viewer.