验证微软和微软提供给第三方的数字签名
验证微软和微软提供给第三方的签名 ,看MSDN内容好多啊!不过下面的程序对已签名的文件验证是没有问题的。
// WinTrustSignature.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
// GetFileSignature.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
/*
* An example of file signature verification using WinTrust API
* Derived from the sample vertrust.cpp in the Platform SDK
*
* Copyright (c) 2009 Mounir IDRASSI <mounir.idrassi@idrix.fr>. All rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include <windows.h>
#include <Softpub.h>
#include <Wincrypt.h>
#include <tchar.h>
#include <stdlib.h>
#pragma comment(lib, "Crypt32.lib")
#pragma comment(lib, "Wintrust.lib")
LPTSTR GetCertificateDescription(PCCERT_CONTEXT pCertCtx)
{
DWORD dwStrType;
DWORD dwCount;
LPTSTR szSubjectRDN = NULL;
dwStrType = CERT_X500_NAME_STR;
dwCount = CertGetNameString(pCertCtx,
CERT_NAME_RDN_TYPE,
0,
&dwStrType,
NULL,
0);
if (dwCount)
{
szSubjectRDN = (LPTSTR) LocalAlloc(0, dwCount * sizeof(TCHAR));
CertGetNameString(pCertCtx,
CERT_NAME_RDN_TYPE,
0,
&dwStrType,
szSubjectRDN,
dwCount);
}
return szSubjectRDN;
}
int _tmain(int argc, _TCHAR* argv[])
{
GUID guidAction = WINTRUST_ACTION_GENERIC_VERIFY_V2;
WINTRUST_FILE_INFO sWintrustFileInfo;
WINTRUST_DATA sWintrustData;
HRESULT hr;
if (argc != 2)
{
_tprintf(_T("Usage: VerifyExeSignature file_name\n"));
return -1;
}
memset((void*)&sWintrustFileInfo, 0x00, sizeof(WINTRUST_FILE_INFO));
memset((void*)&sWintrustData, 0x00, sizeof(WINTRUST_DATA));
sWintrustFileInfo.cbStruct = sizeof(WINTRUST_FILE_INFO);
sWintrustFileInfo.pcwszFilePath = argv[1];
sWintrustFileInfo.hFile = NULL;
sWintrustData.cbStruct = sizeof(WINTRUST_DATA);
sWintrustData.dwUIChoice = WTD_UI_NONE;
sWintrustData.fdwRevocationChecks = WTD_REVOKE_NONE;
sWintrustData.dwUnionChoice = WTD_CHOICE_FILE;
sWintrustData.pFile = &sWintrustFileInfo;
sWintrustData.dwStateAction = WTD_STATEACTION_VERIFY;
hr = WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &guidAction, &sWintrustData);
if (TRUST_E_NOSIGNATURE == hr)
{
_tprintf(_T("No signature found on the file.\n"));
}
else if (TRUST_E_BAD_DIGEST == hr)
{
_tprintf(_T("The signature of the file is invalid\n"));
}
else if (TRUST_E_PROVIDER_UNKNOWN == hr)
{
_tprintf(_T("No trust provider on this machine can verify this type of files.\n"));
}
else if (S_OK != hr)
{
_tprintf(_T("WinVerifyTrust failed with error 0x%.8X\n"), hr);
}
else
{
_tprintf(_T("File signature is OK.\n"));
// retreive the signer certificate and display its information
CRYPT_PROVIDER_DATA const *psProvData = NULL;
CRYPT_PROVIDER_SGNR *psProvSigner = NULL;
CRYPT_PROVIDER_CERT *psProvCert = NULL;
FILETIME localFt;
SYSTEMTIME sysTime;
psProvData = WTHelperProvDataFromStateData(sWintrustData.hWVTStateData);
if (psProvData)
{
psProvSigner = WTHelperGetProvSignerFromChain((PCRYPT_PROVIDER_DATA)psProvData, 0 , FALSE, 0);
if (psProvSigner)
{
FileTimeToLocalFileTime(&psProvSigner->sftVerifyAsOf, &localFt);
FileTimeToSystemTime(&localFt, &sysTime);
_tprintf(_T("Signature Date = %.2d/%.2d/%.4d at %.2d:%2.d:%.2d\n"), sysTime.wDay, sysTime.wMonth,sysTime.wYear, sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
psProvCert = WTHelperGetProvCertFromChain(psProvSigner, 0);
if (psProvCert)
{
LPTSTR szCertDesc = GetCertificateDescription(psProvCert->pCert);
if (szCertDesc)
{
_tprintf(_T("File Signer = %s\n"), szCertDesc);
LocalFree(szCertDesc);
}
}
if (psProvSigner->csCounterSigners)
{
_tprintf(_T("\n"));
// Timestamp information
FileTimeToLocalFileTime(&psProvSigner->pasCounterSigners[0].sftVerifyAsOf, &localFt);
FileTimeToSystemTime(&localFt, &sysTime);
_tprintf(_T("Timestamp Date = %.2d/%.2d/%.4d at %.2d:%2.d:%.2d\n"), sysTime.wDay, sysTime.wMonth,sysTime.wYear, sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
psProvCert = WTHelperGetProvCertFromChain(&psProvSigner->pasCounterSigners[0], 0);
if (psProvCert)
{
LPTSTR szCertDesc = GetCertificateDescription(psProvCert->pCert);
if (szCertDesc)
{
_tprintf(_T("Timestamp Signer = %s\n"), szCertDesc);
LocalFree(szCertDesc);
}
}
}
}
}
}
sWintrustData.dwUIChoice = WTD_UI_NONE;
sWintrustData.dwStateAction = WTD_STATEACTION_CLOSE;
WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &guidAction, &sWintrustData);
return 0;
}
验证微软和微软提供给第三方的数字签名相关推荐
- 微软为NBA提供云计算服务、Google公布Fuchsia OS细节、Zoom用户可选择数据库等|Decode the Week...
Decode the Week≠音视频技术周刊 01 苹果正在研发可替换零部件的入耳式无线耳机 并发布了Apple Music Web版 彭博社消息,苹果试图通过高端音频产品扩大AirPods业务, ...
- Java 提供给第三方使用接口方法
Java提供接口给第三方使用,校验保证接口的安全性 前言 接口Controller 接口幂等性校验 实现类ServiceImpl 第三方调用接口Api实现类 生成签名工具类 HttpCilent工具类 ...
- cdn.bootcss.com网站提供的第三方jQuery库遭到篡改
若出现访问后某个模块引用的js文件,这个js文件是判断当前环境然后跳转到博彩网站或色情网站引流的的,可以考虑以下情况: cdn.bootcss.com网站提供的第三方jQuery库遭到篡改,使用该站点 ...
- Windows 无法验证此设备所需的驱动程序的数字签名
前几天不知何故,自己的小米6手机无法使用usb连接电脑了. 主要是插上之后没有反应,打开设备管理器找到便携设备显示黄色感叹号(如下图,MTP USB设备前手机图示右下角处有黄色感叹号). 右键设备,选 ...
- 无法加载操作系统,因为无法验证文件或其某个00项的数字签名
无法加载操作系统,因为无法验证文件或其某个00项的数字签名 你的电脑/设备需要修复 无法加载操作系统,因为无法验证文件或其某个00项的数字签名. 文件\Windows\System32\drivers ...
- VB编程宣告终结,微软:不再提供新功能
容易上手.可以直接编写图形界面,过去很多人接触计算机编程的第一种语言是微软推出的 Visual Basic.但这一语言即将停止更新了. 本周三,微软.NET 团队在一份开发者博客中表示,微软将在.NE ...
- 划入 .NET 6版本目标,微软鼓励开发人员信任第三方库
喜欢就关注我们吧! 鉴于许多 .NET 社区的开发人员都不愿意使用非微软官方打造的库,近日,微软 .NET Framework 团队的项目经理 Immo Landwerth 发布了一个名为" ...
- 使用教育网邮箱学生验证Microsoft Imagine 微软开发者 获取window server 2016正版密钥教程
Microsoft Imagine介绍 微软免费软件项目DreamSpark 2016年9月正式更名为Microsoft Imagine,将与一年一度的微软"创新杯(Imagine Cup) ...
- windows远程桌面连接时,显示发生身份验证错误,给函数提供的身份无效
初次看到这个错误的时候懵了.访问给的地址一看,发现大概意思是不安全了,微软要更新一下 凭据安全支持提供程序协议 (CredSSP) 是处理其他应用程序的身份验证请求的身份验证提供程序. CredSSP ...
最新文章
- 用Windows Live Writer在51CTO写博客(2018年2月24日更新)
- UVA - 1252 Twenty Questions (状压dp+vis数组加速)
- oracle面临的挑战,Oracle SUN,严峻的挑战(一)
- 【阿佳说】打造抖音个人IP实现利润翻倍
- Prim算法和Kruskal算法
- 如何让“GMV下降”实现自动化分析?
- java+多线程菜鸟_java多线程
- 数据库快照,自定义函数与计算列
- 封装instanceof
- Oracle shared_pool_reserved_size参数设置说明
- C#遍历DataSet中数据的几种方法总结
- 使用开源软件 Mantis 实施缺陷跟踪的成功实践
- 点击选中框 批量删除
- 今日不谈股市, 谈谈财政部副部长廖晓军不降个税问题
- OCCT教程二:在visual studio上创建一个occt工程
- SLURM Array Job
- Tekton实战案例--S2I
- make sure you have the 32 bits oracle client installed
- Tableau图表 • 排序图(凹凸图)
- mysql配置 cloudreve_Cloudreve网盘系统安装笔记