Changeset 51917 in vbox for trunk/src/VBox/Runtime/tools
- Timestamp:
- Jul 8, 2014 1:36:57 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTSignTool.cpp
r51793 r51917 260 260 enum { kSignType_Windows, kSignType_OSX } enmSignType; 261 261 uint64_t uTimestamp; 262 RTLDRARCH enmLdrArch; 262 263 } VERIFYEXESTATE; 263 264 … … 404 405 } 405 406 407 /** Worker for HandleVerifyExe. */ 408 static RTEXITCODE HandleVerifyExeWorker(VERIFYEXESTATE *pState, const char *pszFilename, PRTERRINFOSTATIC pStaticErrInfo) 409 { 410 /* 411 * Open the executable image and verify it. 412 */ 413 RTLDRMOD hLdrMod; 414 int rc = RTLdrOpen(pszFilename, RTLDR_O_FOR_VALIDATION, pState->enmLdrArch, &hLdrMod); 415 if (RT_FAILURE(rc)) 416 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening executable image '%s': %Rrc", pszFilename, rc); 417 418 419 rc = RTLdrQueryProp(hLdrMod, RTLDRPROP_TIMESTAMP_SECONDS, &pState->uTimestamp, sizeof(pState->uTimestamp)); 420 if (RT_SUCCESS(rc)) 421 { 422 rc = RTLdrVerifySignature(hLdrMod, VerifyExeCallback, pState, RTErrInfoInitStatic(pStaticErrInfo)); 423 if (RT_SUCCESS(rc)) 424 RTMsgInfo("'%s' is valid.\n", pszFilename); 425 else 426 RTMsgError("RTLdrVerifySignature failed on '%s': %Rrc - %s\n", pszFilename, rc, pStaticErrInfo->szMsg); 427 } 428 else 429 RTMsgError("RTLdrQueryProp/RTLDRPROP_TIMESTAMP_SECONDS failed on '%s': %Rrc\n", pszFilename, rc); 430 431 int rc2 = RTLdrClose(hLdrMod); 432 if (RT_FAILURE(rc2)) 433 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTLdrClose failed: %Rrc\n", rc2); 434 if (RT_FAILURE(rc)) 435 return rc != VERR_LDRVI_NOT_SIGNED ? RTEXITCODE_FAILURE : RTEXITCODE_SKIPPED; 436 437 return RTEXITCODE_SUCCESS; 438 } 439 440 406 441 static RTEXITCODE HandleVerifyExe(int cArgs, char **papszArgs) 407 442 { … … 427 462 }; 428 463 429 RTLDRARCH enmLdrArch = RTLDRARCH_WHATEVER; 430 VERIFYEXESTATE State = { NIL_RTCRSTORE, NIL_RTCRSTORE, NIL_RTCRSTORE, false, false, VERIFYEXESTATE::kSignType_Windows }; 464 VERIFYEXESTATE State = 465 { 466 NIL_RTCRSTORE, NIL_RTCRSTORE, NIL_RTCRSTORE, false, false, 467 VERIFYEXESTATE::kSignType_Windows, 0, RTLDRARCH_WHATEVER 468 }; 431 469 int rc = RTCrStoreCreateInMem(&State.hRootStore, 0); 432 470 if (RT_SUCCESS(rc)) … … 524 562 * Do it. 525 563 */ 564 RTEXITCODE rcExit; 526 565 for (;;) 527 566 { 528 /* 529 * Open the executable image and verify it. 530 */ 531 RTLDRMOD hLdrMod; 532 rc = RTLdrOpen(ValueUnion.psz, RTLDR_O_FOR_VALIDATION, enmLdrArch, &hLdrMod); 533 if (RT_FAILURE(rc)) 534 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening executable image '%s': %Rrc", ValueUnion.psz, rc); 535 536 537 rc = RTLdrQueryProp(hLdrMod, RTLDRPROP_TIMESTAMP_SECONDS, &State.uTimestamp, sizeof(State.uTimestamp)); 538 if (RT_SUCCESS(rc)) 539 { 540 rc = RTLdrVerifySignature(hLdrMod, VerifyExeCallback, &State, RTErrInfoInitStatic(&StaticErrInfo)); 541 if (RT_SUCCESS(rc)) 542 RTMsgInfo("'%s' is valid.\n", ValueUnion.psz); 543 else 544 RTMsgError("RTLdrVerifySignature failed on '%s': %Rrc - %s\n", ValueUnion.psz, rc, StaticErrInfo.szMsg); 545 } 546 else 547 RTMsgError("RTLdrQueryProp/RTLDRPROP_TIMESTAMP_SECONDS failed on '%s': %Rrc\n", ValueUnion.psz, rc); 548 549 int rc2 = RTLdrClose(hLdrMod); 550 if (RT_FAILURE(rc2)) 551 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTLdrClose failed: %Rrc\n", rc2); 552 if (RT_FAILURE(rc)) 553 return rc != VERR_LDRVI_NOT_SIGNED ? RTEXITCODE_FAILURE : RTEXITCODE_SKIPPED; 567 rcExit = HandleVerifyExeWorker(&State, ValueUnion.psz, &StaticErrInfo); 568 if (rcExit != RTEXITCODE_SUCCESS) 569 break; 554 570 555 571 /* … … 558 574 ch = RTGetOpt(&GetState, &ValueUnion); 559 575 if (ch == 0) 560 return RTEXITCODE_SUCCESS;576 break; 561 577 if (ch != VINF_GETOPT_NOT_OPTION) 562 return RTGetOptPrintError(ch, &ValueUnion); 563 } 578 { 579 rcExit = RTGetOptPrintError(ch, &ValueUnion); 580 break; 581 } 582 } 583 584 /* 585 * Clean up. 586 */ 587 uint32_t cRefs; 588 cRefs = RTCrStoreRelease(State.hRootStore); Assert(cRefs == 0); 589 cRefs = RTCrStoreRelease(State.hKernelRootStore); Assert(cRefs == 0); 590 cRefs = RTCrStoreRelease(State.hAdditionalStore); Assert(cRefs == 0); 591 592 return rcExit; 564 593 } 565 594
Note:
See TracChangeset
for help on using the changeset viewer.