VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTLdrVerifyPeImage.cpp@ 91472

Last change on this file since 91472 was 86549, checked in by vboxsync, 4 years ago

SUPHardNt,IPRT: If there are nested signatures (i.e. more than one signature), don't get grumpy if there are time or cert path issues with some of them, as long as one or more checks out perfectly. (Mind, all the signature data must check out, it's just the cert path or signing time we're relaxing here.) ticketref:19743 bugref:3103

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: tstRTLdrVerifyPeImage.cpp 86549 2020-10-12 23:59:53Z vboxsync $ */
2/** @file
3 * SUP Testcase - Testing the Authenticode signature verification code.
4 */
5
6/*
7 * Copyright (C) 2014-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/ldr.h>
32
33#include <iprt/errcore.h>
34#include <iprt/mem.h>
35#include <iprt/path.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38#include <iprt/test.h>
39
40
41/*********************************************************************************************************************************
42* Global Variables *
43*********************************************************************************************************************************/
44static int g_iDummy = 0;
45
46
47static DECLCALLBACK(int) TestCallback(RTLDRMOD hLdrMod, PCRTLDRSIGNATUREINFO pInfo, PRTERRINFO pErrInfo, void *pvUser)
48{
49 RT_NOREF(hLdrMod, pInfo, pErrInfo, pvUser);
50 return VINF_SUCCESS;
51}
52
53
54int main(int argc, char **argv)
55{
56 RTTEST hTest;
57 RTEXITCODE rcExit = RTTestInitAndCreate("tstAuthenticode", &hTest);
58 if (rcExit != RTEXITCODE_SUCCESS)
59 return rcExit;
60 RTTestBanner(hTest);
61
62 /*
63 * Process input.
64 */
65 for (int i = 1; i < argc; i++)
66 {
67 const char *pszFullName = argv[i];
68 const char *pszFilename = RTPathFilename(pszFullName);
69 RTTestSub(hTest, pszFilename);
70
71 RTLDRMOD hLdrMod;
72 int rc = RTLdrOpen(pszFullName, RTLDR_O_FOR_VALIDATION, RTLDRARCH_WHATEVER, &hLdrMod);
73 if (RT_SUCCESS(rc))
74 {
75 char szDigest[512];
76
77 RTTESTI_CHECK_RC(rc = RTLdrHashImage(hLdrMod, RTDIGESTTYPE_MD5, szDigest, sizeof(szDigest)), VINF_SUCCESS);
78 if (RT_SUCCESS(rc))
79 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "md5=%s\n", szDigest);
80 RTTESTI_CHECK_RC(rc = RTLdrHashImage(hLdrMod, RTDIGESTTYPE_SHA1, szDigest, sizeof(szDigest)), VINF_SUCCESS);
81 if (RT_SUCCESS(rc))
82 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "sha1=%s\n", szDigest);
83 RTTESTI_CHECK_RC(rc = RTLdrHashImage(hLdrMod, RTDIGESTTYPE_SHA256, szDigest, sizeof(szDigest)), VINF_SUCCESS);
84 if (RT_SUCCESS(rc))
85 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "sha256=%s\n", szDigest);
86 RTTESTI_CHECK_RC(rc = RTLdrHashImage(hLdrMod, RTDIGESTTYPE_SHA512, szDigest, sizeof(szDigest)), VINF_SUCCESS);
87 if (RT_SUCCESS(rc))
88 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "sha512=%s\n", szDigest);
89
90 if (rc != VERR_NOT_SUPPORTED)
91 {
92 RTERRINFOSTATIC ErrInfo;
93 RTErrInfoInitStatic(&ErrInfo);
94 rc = RTLdrVerifySignature(hLdrMod, TestCallback, &g_iDummy, &ErrInfo.Core);
95 if (RT_FAILURE(rc))
96 RTTestFailed(hTest, "%s: %s (rc=%Rrc)", pszFilename, ErrInfo.Core.pszMsg, rc);
97 }
98 RTLdrClose(hLdrMod);
99 }
100 else
101 RTTestFailed(hTest, "Error opening '%s': %Rrc\n", pszFullName, rc);
102 }
103
104 return RTTestSummaryAndDestroy(hTest);
105}
106
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette