Changeset 74672 in vbox
- Timestamp:
- Oct 8, 2018 12:08:51 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
-
include/iprt/asn1-generator-pass.h (modified) (1 diff)
-
include/iprt/asn1.h (modified) (2 diffs)
-
include/iprt/mangling.h (modified) (1 diff)
-
include/iprt/types.h (modified) (4 diffs)
-
src/VBox/Runtime/VBox/VBoxRTImp.def (modified) (1 diff)
-
src/VBox/Runtime/common/asn1/asn1-cursor.cpp (modified) (9 diffs)
-
src/VBox/Runtime/common/crypto/pkcs7-asn1-decoder.cpp (modified) (1 diff)
-
src/VBox/Runtime/tools/RTSignTool.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asn1-generator-pass.h
r69105 r74672 490 490 491 491 # define RTASN1TMPL_END_SEQCORE() \ 492 if (RT_SUCCESS(rc)) \ 493 rc = RTAsn1CursorCheckEnd(&ThisCursor); \ 494 if (RT_SUCCESS(rc)) \ 495 return VINF_SUCCESS; \ 496 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \ 497 RTASN1TMPL_END_COMMON() 498 # define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_SEQCORE() 499 492 if (RT_SUCCESS(rc)) \ 493 rc = RTAsn1CursorCheckSeqEnd(&ThisCursor, &pThis->SeqCore); \ 494 if (RT_SUCCESS(rc)) \ 495 return VINF_SUCCESS; \ 496 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \ 497 RTASN1TMPL_END_COMMON() 498 # define RTASN1TMPL_END_SETCORE() \ 499 if (RT_SUCCESS(rc)) \ 500 rc = RTAsn1CursorCheckSetEnd(&ThisCursor, &pThis->SetCore); \ 501 if (RT_SUCCESS(rc)) \ 502 return VINF_SUCCESS; \ 503 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \ 504 RTASN1TMPL_END_COMMON() 500 505 501 506 # define RTASN1TMPL_BEGIN_PCHOICE() \ -
trunk/include/iprt/asn1.h
r74657 r74672 1649 1649 /** The cursor depth. */ 1650 1650 uint8_t cDepth; 1651 /** Number of pending indefinite length records. */1652 uint8_t cIndefinedRecs;1653 1651 /** Two bytes reserved for future tricks. */ 1654 uint8_t abReserved[ 1];1652 uint8_t abReserved[2]; 1655 1653 /** Pointer to the primary cursor. */ 1656 1654 struct RTASN1CURSORPRIMARY *pPrimary; … … 1790 1788 RTDECL(int) RTAsn1CursorCheckEnd(PRTASN1CURSOR pCursor); 1791 1789 1790 /** 1791 * Specialization of RTAsn1CursorCheckEnd for handling indefinite length sequences. 1792 * 1793 * Makes sure we've reached the end of the data for the cursor, and in case of a 1794 * an indefinite length sequence it may adjust sequence length and the parent 1795 * cursor. 1796 * 1797 * @returns IPRT status code. 1798 * @param pCursor The cursor we're decoding from. 1799 * @param pSeqCore The sequence core record. 1800 */ 1801 RTDECL(int) RTAsn1CursorCheckSeqEnd(PRTASN1CURSOR pCursor, PRTASN1SEQUENCECORE pSeqCore); 1802 1803 /** 1804 * Specialization of RTAsn1CursorCheckEnd for handling indefinite length sets. 1805 * 1806 * Makes sure we've reached the end of the data for the cursor, and in case of a 1807 * an indefinite length sets it may adjust set length and the parent cursor. 1808 * 1809 * @returns IPRT status code. 1810 * @param pCursor The cursor we're decoding from. 1811 * @param pSetCore The set core record. 1812 */ 1813 RTDECL(int) RTAsn1CursorCheckSetEnd(PRTASN1CURSOR pCursor, PRTASN1SETCORE pSetCore); 1792 1814 1793 1815 /** -
trunk/include/iprt/mangling.h
r74654 r74672 2741 2741 # define RTAsn1VtDelete RT_MANGLER(RTAsn1VtDelete) 2742 2742 # define RTAsn1CursorCheckEnd RT_MANGLER(RTAsn1CursorCheckEnd) 2743 # define RTAsn1CursorCheckSeqEnd RT_MANGLER(RTAsn1CursorCheckSeqEnd) 2744 # define RTAsn1CursorCheckSetEnd RT_MANGLER(RTAsn1CursorCheckSetEnd) 2743 2745 # define RTAsn1CursorGetBitString RT_MANGLER(RTAsn1CursorGetBitString) 2744 2746 # define RTAsn1CursorGetBitStringEx RT_MANGLER(RTAsn1CursorGetBitStringEx) -
trunk/include/iprt/types.h
r74638 r74672 2991 2991 intptr_t i; 2992 2992 /** As an unsigned integer. */ 2993 intptr_tu;2993 uintptr_t u; 2994 2994 /** Pointer to char value. */ 2995 2995 char RT_FAR *pch; … … 3038 3038 intptr_t i; 3039 3039 /** As an unsigned integer. */ 3040 intptr_tu;3040 uintptr_t u; 3041 3041 /** Pointer to char value. */ 3042 3042 char const RT_FAR *pch; … … 3085 3085 intptr_t i; 3086 3086 /** As an unsigned integer. */ 3087 intptr_tu;3087 uintptr_t u; 3088 3088 /** Pointer to char value. */ 3089 3089 char volatile RT_FAR *pch; … … 3132 3132 intptr_t i; 3133 3133 /** As an unsigned integer. */ 3134 intptr_tu;3134 uintptr_t u; 3135 3135 /** Pointer to char value. */ 3136 3136 char const volatile RT_FAR *pch; -
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.

