- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们使用 WinInet 和 Delphi 通过 HTTPS 进行通信。WinInet 中是否有一个函数可以返回 session 中协商的协议(protocol),即 TLS1.1、TLS 1.2 等。
最佳答案
不幸的是,显然不是(在 Windows 7 上使用 Internet Explorer 11 进行测试)。
使用 InternetQueryOption
与 INTERNET_OPTION_SECURITY_CERTIFICATE
或INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
是我在 WinInet 文档中可以找到的最接近的(请参阅 lpszProtocolName
中的 INTERNET_CERTIFICATE_INFO
),但它们返回空字符串(请参阅下面的输出)。
lpszProtocolName
Pointer to a buffer that contains the name of the protocol used to provide the
secure connection. The application must call LocalFree to release the resources
allocated for this parameter.
我找不到任何其他内容表明 Wininet 公开了底层 SChannel 连接属性。
program test_wininet;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Winapi.Windows,
Winapi.Wininet;
type
// fixed declaration
PInternetCertificateInfo = ^TInternetCertificateInfo;
TInternetCertificateInfo = record
ftExpiry: TFileTime;
ftStart: TFileTime;
lpszSubjectInfo: PAnsiChar;
lpszIssuerInfo: PAnsiChar;
lpszProtocolName: PAnsiChar;
lpszSignatureAlgName: PAnsiChar;
lpszEncryptionAlgName: PAnsiChar;
dwKeySize: DWORD;
end;
procedure FreeCertificateInfo(var Info: TInternetCertificateInfo);
begin
if Assigned(Info.lpszSubjectInfo) then
LocalFree(NativeUInt(Info.lpszSubjectInfo));
if Assigned(Info.lpszIssuerInfo) then
LocalFree(NativeUInt(Info.lpszIssuerInfo));
if Assigned(Info.lpszProtocolName) then
LocalFree(NativeUInt(Info.lpszProtocolName));
if Assigned(Info.lpszSignatureAlgName) then
LocalFree(NativeUInt(Info.lpszSignatureAlgName));
if Assigned(Info.lpszEncryptionAlgName) then
LocalFree(NativeUInt(Info.lpszEncryptionAlgName));
end;
function GetCertificateInfo(H: HINTERNET): TInternetCertificateInfo;
var
Size: Cardinal;
begin
Size := SizeOf(Result);
FillChar(Result, Size, 0);
Win32Check(InternetQueryOption(H, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, @Result, Size));
end;
function GetCertificateInfoStr(H: HINTERNET): AnsiString;
var
Buffer: array[0..1024] of AnsiChar;
BufferSize: Cardinal;
L: Integer;
begin
Result := '';
BufferSize := SizeOf(Buffer);
FillChar(Buffer, BufferSize, 0);
Win32Check(InternetQueryOption(H, INTERNET_OPTION_SECURITY_CERTIFICATE, @Buffer[0], BufferSize));
L := StrLen(PAnsiChar(@Buffer[0]));
if L > 0 then
SetString(Result, Buffer, L);
end;
procedure Main;
var
H, H2: HINTERNET;
Info: TInternetCertificateInfo;
SysTime: TSystemTime;
begin
H := InternetOpen('test', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
H2 := InternetOpenUrl(H, 'https://www.microsoft.com', nil, 0, INTERNET_FLAG_NO_UI or INTERNET_FLAG_SECURE, 0);
try
Writeln('InternetQueryOption with INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT: ');
Info := GetCertificateInfo(H2);
try
Writeln('Subject:');
Writeln(Info.lpszSubjectInfo);
Writeln('Issuer:');
Writeln(Info.lpszIssuerInfo);
Writeln(Format('Security Protocol: %s', [Info.lpszProtocolName]));
Writeln(Format('Signature Type: %s', [Info.lpszSignatureAlgName]));
Writeln(Format('Encryption Type: %s', [Info.lpszEncryptionAlgName]));
FileTimeToSystemTime(Info.ftStart, SysTime);
Writeln(Format('Effective Date: %s', [FormatDateTime('dd/mmm/yy hh:nn:ss', SystemTimeToDateTime(SysTime))]));
FileTimeToSystemTime(Info.ftExpiry, SysTime);
Writeln(Format('Expiration Date: %s', [FormatDateTime('dd/mmm/yy hh:nn:ss', SystemTimeToDateTime(SysTime))]));
Writeln(Format('Key size: %d', [Info.dwKeySize]));
Writeln;
finally
FreeCertificateInfo(Info);
end;
Writeln('InternetQueryOption with INTERNET_OPTION_SECURITY_CERTIFICATE:');
Writeln(GetCertificateInfoStr(H2));
Writeln;
finally
InternetCloseHandle(H2);
end;
finally
InternetCloseHandle(H);
end;
end;
begin
try
Main;
Readln;
except
on E: Exception do
begin
ExitCode := 1;
Writeln(Format('[%s] %s', [E.ClassName, E.Message]));
end;
end;
end.
上面的代码产生以下输出:
InternetQueryOption with INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
Subject:
US
Washington
Private Organization
600413485
US
98052
Washington
Redmond
1 Microsoft Way
Microsoft Corporation
www.microsoft.com
Issuer:
US
Symantec Corporation
Symantec Trust Network
Symantec Class 3 EV SSL CA - G3
Security Protocol:
Signature Type:
Encryption Type:
Effective Date: 24-Mar-16 00:00:00
Expiration Date: 25-Mar-18 23:59:59
Key size: 256
InternetQueryOption with INTERNET_OPTION_SECURITY_CERTIFICATE:
Subject:
US
Washington
Private Organization
600413485
US
98052
Washington
Redmond
1 Microsoft Way
Microsoft Corporation
www.microsoft.com
Issuer:
US
Symantec Corporation
Symantec Trust Network
Symantec Class 3 EV SSL CA - G3
Effective Date: 24-Mar-16 00:00:00
Expiration Date: 25-Mar-18 23:59:59
Security Protocol: (null)
Signature Type: (null)
Encryption Type: (null)
Privacy Strength: High (256 bits)
关于delphi - WinInet 能否返回正在使用的 TLS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37275395/
我正在寻找一个简单的函数,它能够将来自 Internet 的文本或二进制文件读入 string 多变的。 令人难以置信的是,我在网络上找不到任何内容,只有所有 WinInet 的低级描述。在 MQL
我有以下代码: #include #include #include #include #include using namespace std; int main(int argc, ch
我正在使用 wininet 连接到服务器。一切正常,上传,下载,列出命令等......因此,我有一个小错误,我不知道它来自哪里。错误是某些包含超过 100 个文件(例如图像)的服务器文件夹没有全部列出
我正在使用 WinInet 和 InternetOpenUrl 下载一个文件...正在运行。但我想监控进度,所以我尝试添加一个回调函数,但由于某种原因它从未被调用过...... 代码: void CA
我对 C++ 编程还很陌生,所以请多多包涵。我正在尝试创建一个用于教育目的的 ftp 客户端,做了一些研究并决定尝试一下 Wininet,并发现了一些在线教程: 以此为例: #include #in
我有一个将网页下载到文本文件的功能 #include #include #include #include #include #pragma comment(lib, "WinINet.li
我很好奇为什么我在使用此功能时遇到问题。我正在将网络上的 PNG 文件下载到目标路径。例如下载谷歌图片到C:盘: netDownloadData("http://www.google.com/intl
我已经为 Internet Explorer 编写了一个 BHO,它 Hook WinInet 以修改来自 IE 的一些 HTTP 请求,方法是将它们重定向到内部服务器。 当我在 IE 中打开前 3
我正在试验我的 .NET 客户端和服务器之间的缓存。在 WinInet 决定缓存结果之前,我看到一个看似随机的端点命中数。 .NET 客户端使用 HttpWebRequest 发出请求: HttpWe
我发现 WinHTTP 不可重入(1、2)。 WinINET 是可重入的吗? 我们有一个与 WinINET 同步 HTTP 的 ActiveX 控件。如果浏览器(在 javascript 中)触发一个
相关 How to send a HTTP POST Request in Delphi using WinInet api : 我如何提出发布请求并跟踪进度? 这不起作用(检查评论): proced
iam 使用 wininet 下载图像并将其保存到内存流这是我的程序 procedure DownloadToStream(const Url: string; ms: TMemoryStream);
我们使用 WinInet 和 Delphi 通过 HTTPS 进行通信。WinInet 中是否有一个函数可以返回 session 中协商的协议(protocol),即 TLS1.1、TLS 1.2 等
我有一个应用程序,它大量使用 Wininet 函数从互联网获取一些数据。有时我会收到非常奇怪的与句柄相关的错误消息: Internal error in ConnectToHost when tryi
我从第三方网站获得了以下源代码,解释了如何使用 WinInet 从互联网下载文件。我对 API 不太熟悉,我查看了 WinInet 单元,但没有看到任何我需要的 API 调用。 我正在做的是添加报告文
我在 wininet.dll 深处遇到崩溃。尝试读取 HTTP_REQUEST_HANDLE_OBJECT::ReleaseConnection 中的零内存位置时崩溃了 这是实际 DLL 中的错误,而
我正在尝试检测 ftp 服务器何时关闭我在应用程序中打开的连接。我正在使用 WinInet 功能。 我发现了一些使用 InternetSetStatusCallback 函数的示例。我实现了一个回调函
我编写了一个使用 WinInet 库的程序。该程序每天运行约 8-12 小时。首先它连接到互联网,然后它使用 FTP 下载/上传文件。之后它开始一个循环,在不同的时间间隔启动最多两个线程。两个线程都在
我正在尝试连接并确保我们设计的仪器提供的网络服务器上存在各种页面。我正在尝试使用 WinInet 命令通过 C++ Win32 执行此操作。 我很高兴我已经通过 HTTP 正确连接到网络服务器: hI
我正在尝试使用 C++ 中的 WinHTTP 获取文件的内容。该文件是一个 XML 文件,由服务器上的可执行文件生成。 用于初始化、连接甚至读取指定服务器地址上的文件的代码正在运行。 // Conne
我是一名优秀的程序员,十分优秀!