VirtualBox

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

Last change on this file since 76553 was 76553, checked in by vboxsync, 5 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: tstRTLdrVerifyPeImage.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * SUP Testcase - Testing the Authenticode signature verification code.
4 */
5
6/*
7 * Copyright (C) 2014-2019 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
46static DECLCALLBACK(int) TestCallback(RTLDRMOD hLdrMod, RTLDRSIGNATURETYPE enmSignature,
47 void const *pvSignature, size_t cbSignature,
48 void const *pvExternalData, size_t cbExternalData,
49 PRTERRINFO pErrInfo, void *pvUser)
50{
51 RT_NOREF_PV(hLdrMod); RT_NOREF_PV(enmSignature); RT_NOREF_PV(pvSignature); RT_NOREF_PV(cbSignature);
52 RT_NOREF_PV(pErrInfo); RT_NOREF_PV(pvUser); RT_NOREF_PV(pvExternalData); RT_NOREF_PV(cbExternalData);
53 return VINF_SUCCESS;
54}
55
56
57
58int main(int argc, char **argv)
59{
60 RTTEST hTest;
61 RTEXITCODE rcExit = RTTestInitAndCreate("tstAuthenticode", &hTest);
62 if (rcExit != RTEXITCODE_SUCCESS)
63 return rcExit;
64 RTTestBanner(hTest);
65
66 /*
67 * Process input.
68 */
69 for (int i = 1; i < argc; i++)
70 {
71 const char *pszFullName = argv[i];
72 const char *pszFilename = RTPathFilename(pszFullName);
73 RTTestSub(hTest, pszFilename);
74
75 RTLDRMOD hLdrMod;
76 int rc = RTLdrOpen(pszFullName, RTLDR_O_FOR_VALIDATION, RTLDRARCH_WHATEVER, &hLdrMod);
77 if (RT_SUCCESS(rc))
78 {
79 char szDigest[512];
80
81 RTTESTI_CHECK_RC(rc = RTLdrHashImage(hLdrMod, RTDIGESTTYPE_MD5, szDigest, sizeof(szDigest)), VINF_SUCCESS);
82 if (RT_SUCCESS(rc))
83 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "md5=%s\n", szDigest);
84 RTTESTI_CHECK_RC(rc = RTLdrHashImage(hLdrMod, RTDIGESTTYPE_SHA1, szDigest, sizeof(szDigest)), VINF_SUCCESS);
85 if (RT_SUCCESS(rc))
86 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "sha1=%s\n", szDigest);
87 RTTESTI_CHECK_RC(rc = RTLdrHashImage(hLdrMod, RTDIGESTTYPE_SHA256, szDigest, sizeof(szDigest)), VINF_SUCCESS);
88 if (RT_SUCCESS(rc))
89 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "sha256=%s\n", szDigest);
90 RTTESTI_CHECK_RC(rc = RTLdrHashImage(hLdrMod, RTDIGESTTYPE_SHA512, szDigest, sizeof(szDigest)), VINF_SUCCESS);
91 if (RT_SUCCESS(rc))
92 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "sha512=%s\n", szDigest);
93
94 if (rc != VERR_NOT_SUPPORTED)
95 {
96 RTERRINFOSTATIC ErrInfo;
97 RTErrInfoInitStatic(&ErrInfo);
98 rc = RTLdrVerifySignature(hLdrMod, TestCallback, &g_iDummy, &ErrInfo.Core);
99 if (RT_FAILURE(rc))
100 RTTestFailed(hTest, "%s: %s (rc=%Rrc)", pszFilename, ErrInfo.Core.pszMsg, rc);
101 }
102 RTLdrClose(hLdrMod);
103 }
104 else
105 RTTestFailed(hTest, "Error opening '%s': %Rrc\n", pszFullName, rc);
106 }
107
108 return RTTestSummaryAndDestroy(hTest);
109}
110
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use