Changeset 95583 in vbox
- Timestamp:
- Jul 10, 2022 2:06:53 PM (2 years ago)
- File:
-
- 1 edited
-
trunk/src/VBox/Runtime/tools/RTSignTool.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTSignTool.cpp
r93115 r95583 130 130 static RTEXITCODE HelpHelp(PRTSTREAM pStrm, RTSIGNTOOLHELP enmLevel); 131 131 static RTEXITCODE HandleVersion(int cArgs, char **papszArgs); 132 static int HandleShowExeWorkerPkcs7DisplaySignerInfo(PSHOWEXEPKCS7 pThis, size_t offPrefix, PCRTCRPKCS7SIGNERINFO pSignerInfo); 132 133 static int HandleShowExeWorkerPkcs7Display(PSHOWEXEPKCS7 pThis, PRTCRPKCS7SIGNEDDATA pSignedData, size_t offPrefix, 133 134 PCRTCRPKCS7CONTENTINFO pContentInfo); … … 1852 1853 /* Counter signatures (PKCS \#9), use pCounterSignatures. */ 1853 1854 case RTCRPKCS7ATTRIBUTETYPE_COUNTER_SIGNATURES: 1854 RTPrintf("%sTODO: RTCRPKCS7ATTRIBUTETYPE_COUNTER_SIGNATURES! %u bytes\n", 1855 pThis->szPrefix, pAttr->uValues.pCounterSignatures->SetCore.Asn1Core.cb); 1855 RTPrintf("%s%u counter signatures, %u bytes in total\n", pThis->szPrefix, 1856 pAttr->uValues.pCounterSignatures->cItems, pAttr->uValues.pCounterSignatures->SetCore.Asn1Core.cb); 1857 for (uint32_t i = 0; i < pAttr->uValues.pCounterSignatures->cItems; i++) 1858 { 1859 size_t offPrefix2 = offPrefix; 1860 if (pAttr->uValues.pContentInfos->cItems > 1) 1861 offPrefix2 += RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix, "CounterSig[%u]: ", i); 1862 else 1863 offPrefix2 += RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix, " "); 1864 1865 int rc2 = HandleShowExeWorkerPkcs7DisplaySignerInfo(pThis, offPrefix2, 1866 pAttr->uValues.pCounterSignatures->papItems[i]); 1867 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 1868 rc = rc2; 1869 } 1856 1870 break; 1857 1871 … … 1954 1968 1955 1969 /** 1970 * Displays a SignerInfo structure. 1971 * 1972 * @returns IPRT status code. 1973 * @param pThis The show exe instance data. 1974 * @param offPrefix The current prefix offset. 1975 * @param pSignerInfo The structure to display. 1976 */ 1977 static int HandleShowExeWorkerPkcs7DisplaySignerInfo(PSHOWEXEPKCS7 pThis, size_t offPrefix, PCRTCRPKCS7SIGNERINFO pSignerInfo) 1978 { 1979 int rc = RTAsn1Integer_ToString(&pSignerInfo->IssuerAndSerialNumber.SerialNumber, 1980 pThis->szTmp, sizeof(pThis->szTmp), 0 /*fFlags*/, NULL); 1981 if (RT_FAILURE(rc)) 1982 RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc); 1983 RTPrintf("%s Serial No: %s\n", pThis->szPrefix, pThis->szTmp); 1984 1985 rc = RTCrX509Name_FormatAsString(&pSignerInfo->IssuerAndSerialNumber.Name, pThis->szTmp, sizeof(pThis->szTmp), NULL); 1986 if (RT_FAILURE(rc)) 1987 RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc); 1988 RTPrintf("%s Issuer: %s\n", pThis->szPrefix, pThis->szTmp); 1989 1990 const char *pszType = RTCrDigestTypeToName(RTCrX509AlgorithmIdentifier_QueryDigestType(&pSignerInfo->DigestAlgorithm)); 1991 if (!pszType) 1992 pszType = pSignerInfo->DigestAlgorithm.Algorithm.szObjId; 1993 RTPrintf("%s Digest Algorithm: %s", pThis->szPrefix, pszType); 1994 if (pThis->cVerbosity > 1) 1995 RTPrintf(" (%s)\n", pSignerInfo->DigestAlgorithm.Algorithm.szObjId); 1996 else 1997 RTPrintf("\n"); 1998 1999 HandleShowExeWorkerDisplayObjId(pThis, &pSignerInfo->DigestEncryptionAlgorithm.Algorithm, 2000 "Digest Encryption Algorithm: ", "\n"); 2001 2002 if (pSignerInfo->AuthenticatedAttributes.cItems == 0) 2003 RTPrintf("%s Authenticated Attributes: none\n", pThis->szPrefix); 2004 else 2005 { 2006 RTPrintf("%s Authenticated Attributes: %u item%s\n", pThis->szPrefix, 2007 pSignerInfo->AuthenticatedAttributes.cItems, pSignerInfo->AuthenticatedAttributes.cItems > 1 ? "s" : ""); 2008 for (unsigned j = 0; j < pSignerInfo->AuthenticatedAttributes.cItems; j++) 2009 { 2010 PRTCRPKCS7ATTRIBUTE pAttr = pSignerInfo->AuthenticatedAttributes.papItems[j]; 2011 size_t offPrefix3 = offPrefix+ RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix, 2012 " AuthAttrib[%u]: ", j); 2013 HandleShowExeWorkerPkcs7DisplayAttrib(pThis, offPrefix3, pAttr); 2014 } 2015 pThis->szPrefix[offPrefix] = '\0'; 2016 } 2017 2018 if (pSignerInfo->UnauthenticatedAttributes.cItems == 0) 2019 RTPrintf("%s Unauthenticated Attributes: none\n", pThis->szPrefix); 2020 else 2021 { 2022 RTPrintf("%s Unauthenticated Attributes: %u item%s\n", pThis->szPrefix, 2023 pSignerInfo->UnauthenticatedAttributes.cItems, pSignerInfo->UnauthenticatedAttributes.cItems > 1 ? "s" : ""); 2024 for (unsigned j = 0; j < pSignerInfo->UnauthenticatedAttributes.cItems; j++) 2025 { 2026 PRTCRPKCS7ATTRIBUTE pAttr = pSignerInfo->UnauthenticatedAttributes.papItems[j]; 2027 size_t offPrefix3 = offPrefix + RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix, 2028 " UnauthAttrib[%u]: ", j); 2029 HandleShowExeWorkerPkcs7DisplayAttrib(pThis, offPrefix3, pAttr); 2030 } 2031 pThis->szPrefix[offPrefix] = '\0'; 2032 } 2033 2034 /** @todo show the encrypted stuff (EncryptedDigest)? */ 2035 return rc; 2036 } 2037 2038 2039 /** 1956 2040 * Displays a Microsoft SPC indirect data structure. 1957 2041 * … … 2182 2266 { 2183 2267 RTPrintf("%s Certificates: %u\n", pThis->szPrefix, pSignedData->Certificates.cItems); 2184 if (pThis->cVerbosity >= 2) 2185 { 2186 for (uint32_t i = 0; i < pSignedData->Certificates.cItems; i++) 2187 { 2188 if (i != 0) 2189 RTPrintf("\n"); 2190 RTPrintf("%s Certificate #%u:\n", pThis->szPrefix, i); 2268 for (uint32_t i = 0; i < pSignedData->Certificates.cItems; i++) 2269 { 2270 PCRTCRPKCS7CERT pCert = pSignedData->Certificates.papItems[i]; 2271 if (i != 0 && pThis->cVerbosity >= 2) 2272 RTPrintf("\n"); 2273 switch (pCert->enmChoice) 2274 { 2275 case RTCRPKCS7CERTCHOICE_X509: 2276 { 2277 PCRTCRX509CERTIFICATE pX509Cert = pCert->u.pX509Cert; 2278 int rc2 = RTAsn1QueryObjIdName(&pX509Cert->SignatureAlgorithm.Algorithm, pThis->szTmp, sizeof(pThis->szTmp)); 2279 RTPrintf("%s Certificate #%u: %s\n", pThis->szPrefix, i, 2280 RT_SUCCESS(rc2) ? pThis->szTmp : pX509Cert->SignatureAlgorithm.Algorithm.szObjId); 2281 2282 rc2 = RTCrX509Name_FormatAsString(&pX509Cert->TbsCertificate.Subject, 2283 pThis->szTmp, sizeof(pThis->szTmp), NULL); 2284 if (RT_FAILURE(rc2)) 2285 RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc2); 2286 RTPrintf("%s Subject: %s\n", pThis->szPrefix, pThis->szTmp); 2287 2288 rc2 = RTCrX509Name_FormatAsString(&pX509Cert->TbsCertificate.Issuer, 2289 pThis->szTmp, sizeof(pThis->szTmp), NULL); 2290 if (RT_FAILURE(rc2)) 2291 RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc2); 2292 RTPrintf("%s Issuer: %s\n", pThis->szPrefix, pThis->szTmp); 2293 2294 2295 char szNotAfter[RTTIME_STR_LEN]; 2296 RTPrintf("%s Valid: %s thru %s\n", pThis->szPrefix, 2297 RTTimeToString(&pX509Cert->TbsCertificate.Validity.NotBefore.Time, 2298 pThis->szTmp, sizeof(pThis->szTmp)), 2299 RTTimeToString(&pX509Cert->TbsCertificate.Validity.NotAfter.Time, 2300 szNotAfter, sizeof(szNotAfter))); 2301 break; 2302 } 2303 2304 default: 2305 RTPrintf("%s Certificate #%u: Unsupported type\n", pThis->szPrefix, i); 2306 break; 2307 } 2308 2309 2310 if (pThis->cVerbosity >= 2) 2191 2311 RTAsn1Dump(RTCrPkcs7Cert_GetAsn1Core(pSignedData->Certificates.papItems[i]), 0, 2192 2312 ((uint32_t)offPrefix + 9) / 2, RTStrmDumpPrintfV, g_pStdOut); 2193 }2194 } 2313 } 2314 2195 2315 /** @todo display certificates properly. */ 2196 2316 } … … 2207 2327 else 2208 2328 RTPrintf("%s SignerInfos:\n", pThis->szPrefix); 2329 int rc = VINF_SUCCESS; 2209 2330 for (unsigned i = 0; i < cSigInfos; i++) 2210 2331 { 2211 PRTCRPKCS7SIGNERINFO pSigInfo = pSignedData->SignerInfos.papItems[i];2212 2332 size_t offPrefix2 = offPrefix; 2213 2333 if (cSigInfos != 1) 2214 2334 offPrefix2 += RTStrPrintf(&pThis->szPrefix[offPrefix], sizeof(pThis->szPrefix) - offPrefix, "SignerInfo[%u]: ", i); 2215 2335 2216 int rc = RTAsn1Integer_ToString(&pSigInfo->IssuerAndSerialNumber.SerialNumber, 2217 pThis->szTmp, sizeof(pThis->szTmp), 0 /*fFlags*/, NULL); 2218 if (RT_FAILURE(rc)) 2219 RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc); 2220 RTPrintf("%s Serial No: %s\n", pThis->szPrefix, pThis->szTmp); 2221 2222 rc = RTCrX509Name_FormatAsString(&pSigInfo->IssuerAndSerialNumber.Name, pThis->szTmp, sizeof(pThis->szTmp), NULL); 2223 if (RT_FAILURE(rc)) 2224 RTStrPrintf(pThis->szTmp, sizeof(pThis->szTmp), "%Rrc", rc); 2225 RTPrintf("%s Issuer: %s\n", pThis->szPrefix, pThis->szTmp); 2226 2227 const char *pszType = RTCrDigestTypeToName(RTCrX509AlgorithmIdentifier_QueryDigestType(&pSigInfo->DigestAlgorithm)); 2228 if (!pszType) 2229 pszType = pSigInfo->DigestAlgorithm.Algorithm.szObjId; 2230 RTPrintf("%s Digest Algorithm: %s", pThis->szPrefix, pszType); 2231 if (pThis->cVerbosity > 1) 2232 RTPrintf(" (%s)\n", pSigInfo->DigestAlgorithm.Algorithm.szObjId); 2233 else 2234 RTPrintf("\n"); 2235 2236 HandleShowExeWorkerDisplayObjId(pThis, &pSigInfo->DigestEncryptionAlgorithm.Algorithm, 2237 "Digest Encryption Algorithm: ", "\n"); 2238 2239 if (pSigInfo->AuthenticatedAttributes.cItems == 0) 2240 RTPrintf("%s Authenticated Attributes: none\n", pThis->szPrefix); 2241 else 2242 { 2243 RTPrintf("%s Authenticated Attributes: %u item%s\n", pThis->szPrefix, 2244 pSigInfo->AuthenticatedAttributes.cItems, pSigInfo->AuthenticatedAttributes.cItems > 1 ? "s" : ""); 2245 for (unsigned j = 0; j < pSigInfo->AuthenticatedAttributes.cItems; j++) 2246 { 2247 PRTCRPKCS7ATTRIBUTE pAttr = pSigInfo->AuthenticatedAttributes.papItems[j]; 2248 size_t offPrefix3 = offPrefix2 + RTStrPrintf(&pThis->szPrefix[offPrefix2], sizeof(pThis->szPrefix) - offPrefix2, 2249 " AuthAttrib[%u]: ", j); 2250 HandleShowExeWorkerPkcs7DisplayAttrib(pThis, offPrefix3, pAttr); 2251 } 2252 pThis->szPrefix[offPrefix2] = '\0'; 2253 } 2254 2255 if (pSigInfo->UnauthenticatedAttributes.cItems == 0) 2256 RTPrintf("%s Unauthenticated Attributes: none\n", pThis->szPrefix); 2257 else 2258 { 2259 RTPrintf("%s Unauthenticated Attributes: %u item%s\n", pThis->szPrefix, 2260 pSigInfo->UnauthenticatedAttributes.cItems, pSigInfo->UnauthenticatedAttributes.cItems > 1 ? "s" : ""); 2261 for (unsigned j = 0; j < pSigInfo->UnauthenticatedAttributes.cItems; j++) 2262 { 2263 PRTCRPKCS7ATTRIBUTE pAttr = pSigInfo->UnauthenticatedAttributes.papItems[j]; 2264 size_t offPrefix3 = offPrefix2 + RTStrPrintf(&pThis->szPrefix[offPrefix2], sizeof(pThis->szPrefix) - offPrefix2, 2265 " UnauthAttrib[%u]: ", j); 2266 HandleShowExeWorkerPkcs7DisplayAttrib(pThis, offPrefix3, pAttr); 2267 } 2268 pThis->szPrefix[offPrefix2] = '\0'; 2269 } 2270 2271 /** @todo show the encrypted stuff (EncryptedDigest)? */ 2336 int rc2 = HandleShowExeWorkerPkcs7DisplaySignerInfo(pThis, offPrefix2, pSignedData->SignerInfos.papItems[i]); 2337 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 2338 rc = rc2; 2272 2339 } 2273 2340 pThis->szPrefix[offPrefix] = '\0'; 2274 2341 2275 return VINF_SUCCESS;2342 return rc; 2276 2343 } 2277 2344
Note:
See TracChangeset
for help on using the changeset viewer.

