Changeset 95659 in vbox for trunk/src/VBox/Runtime/tools/RTSignTool.cpp
- Timestamp:
- Jul 15, 2022 10:16:31 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTSignTool.cpp
r95657 r95659 1701 1701 if (RT_FAILURE(rc)) 1702 1702 return RTMsgErrorExitFailure("RTAsn1ObjId_InitFromString/%s failed: %Rrc", pszAlgId, rc); 1703 RTAsn1DynType_SetToNull(&pSpcIndData->DigestInfo.DigestAlgorithm.Parameters); /* ASSUMES RSA or similar */ 1703 1704 1704 1705 rc = RTAsn1ContentDup(&pSpcIndData->DigestInfo.Digest.Asn1Core, abHash, cbHash, &g_RTAsn1DefaultAllocator); … … 1962 1963 else 1963 1964 RTMsgError("Could not locate signature #%u!", iSignature); 1965 1966 /* Delete the signature data. */ 1967 SignToolPkcs7Exe_Delete(&This); 1968 } 1969 return rcExit; 1970 } 1971 1972 1973 /********************************************************************************************************************************* 1974 * The 'extract-exe-signature' command. * 1975 *********************************************************************************************************************************/ 1976 1977 static RTEXITCODE HelpExtractExeSignature(PRTSTREAM pStrm, RTSIGNTOOLHELP enmLevel) 1978 { 1979 RT_NOREF_PV(enmLevel); 1980 RTStrmWrappedPrintf(pStrm, RTSTRMWRAPPED_F_HANGING_INDENT, 1981 "extract-exe-signerature [--exe|-e] <exe> [--output|-o] <outfile.pkcs7>\n"); 1982 return RTEXITCODE_SUCCESS; 1983 } 1984 1985 static RTEXITCODE HandleExtractExeSignature(int cArgs, char **papszArgs) 1986 { 1987 /* 1988 * Parse arguments. 1989 */ 1990 static const RTGETOPTDEF s_aOptions[] = 1991 { 1992 { "--exe", 'e', RTGETOPT_REQ_STRING }, 1993 { "--output", 'o', RTGETOPT_REQ_STRING }, 1994 }; 1995 1996 const char *pszExe = NULL; 1997 const char *pszOut = NULL; 1998 RTLDRARCH enmLdrArch = RTLDRARCH_WHATEVER; 1999 unsigned cVerbosity = 0; 2000 2001 RTGETOPTSTATE GetState; 2002 int rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST); 2003 AssertRCReturn(rc, RTEXITCODE_FAILURE); 2004 RTGETOPTUNION ValueUnion; 2005 int ch; 2006 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 2007 { 2008 switch (ch) 2009 { 2010 case 'e': pszExe = ValueUnion.psz; break; 2011 case 'o': pszOut = ValueUnion.psz; break; 2012 case 'V': return HandleVersion(cArgs, papszArgs); 2013 case 'h': return HelpExtractExeSignerCert(g_pStdOut, RTSIGNTOOLHELP_FULL); 2014 2015 case VINF_GETOPT_NOT_OPTION: 2016 if (!pszExe) 2017 pszExe = ValueUnion.psz; 2018 else if (!pszOut) 2019 pszOut = ValueUnion.psz; 2020 else 2021 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Too many file arguments: %s", ValueUnion.psz); 2022 break; 2023 2024 default: 2025 return RTGetOptPrintError(ch, &ValueUnion); 2026 } 2027 } 2028 if (!pszExe) 2029 return RTMsgErrorExit(RTEXITCODE_FAILURE, "No executable given."); 2030 if (!pszOut) 2031 return RTMsgErrorExit(RTEXITCODE_FAILURE, "No output file given."); 2032 if (RTPathExists(pszOut)) 2033 return RTMsgErrorExit(RTEXITCODE_FAILURE, "The output file '%s' exists.", pszOut); 2034 2035 /* 2036 * Do it. 2037 */ 2038 /* Read & decode the PKCS#7 signature. */ 2039 SIGNTOOLPKCS7EXE This; 2040 RTEXITCODE rcExit = SignToolPkcs7Exe_InitFromFile(&This, pszExe, cVerbosity, enmLdrArch); 2041 if (rcExit == RTEXITCODE_SUCCESS) 2042 { 2043 /* 2044 * Write out the PKCS#7 signature. 2045 */ 2046 RTFILE hFile; 2047 rc = RTFileOpen(&hFile, pszOut, RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_CREATE); 2048 if (RT_SUCCESS(rc)) 2049 { 2050 rc = RTFileWrite(hFile, This.pbBuf, This.cbBuf, NULL); 2051 if (RT_SUCCESS(rc)) 2052 { 2053 rc = RTFileClose(hFile); 2054 if (RT_SUCCESS(rc)) 2055 { 2056 hFile = NIL_RTFILE; 2057 RTMsgInfo("Successfully wrote %u bytes to '%s'", This.cbBuf, pszOut); 2058 rcExit = RTEXITCODE_SUCCESS; 2059 } 2060 else 2061 RTMsgError("RTFileClose failed: %Rrc", rc); 2062 } 2063 else 2064 RTMsgError("RTFileWrite failed: %Rrc", rc); 2065 RTFileClose(hFile); 2066 } 2067 else 2068 RTMsgError("Error opening '%s' for writing: %Rrc", pszOut, rc); 1964 2069 1965 2070 /* Delete the signature data. */ … … 4314 4419 { 4315 4420 { "extract-exe-signer-cert", HandleExtractExeSignerCert, HelpExtractExeSignerCert }, 4421 { "extract-exe-signature", HandleExtractExeSignature, HelpExtractExeSignature }, 4316 4422 { "add-nested-exe-signature", HandleAddNestedExeSignature, HelpAddNestedExeSignature }, 4317 4423 { "add-nested-cat-signature", HandleAddNestedCatSignature, HelpAddNestedCatSignature },
Note:
See TracChangeset
for help on using the changeset viewer.