启动与 Web 客户端的客户端证书协商。
语法
HRESULT NegotiateClientCertificate(
IN BOOL fAsync,
OUT BOOL* pfCompletionPending = NULL
)
parameters
fAsync
[IN] true
指定应异步进行协商;否则为 false
。
pfCompletionPending
[OUT] true
指定异步完成挂起;否则为 false
。
返回值
HRESULT
。 可能的值包括(但并不限于)下表中的项。
值 | 定义 |
---|---|
S_OK | 指示操作成功。 |
E_FAIL | 指示操作失败。 |
备注
即使 IIS 配置为接受或忽略客户端证书,开发人员也可以使用 NegotiateClientCertificate
方法手动启动与 Web 客户端的客户端证书协商。 NegotiateClientCertificate
通过在 参数中 fAsync
指定适当的设置,支持同步和异步操作。 当模块以异步方式调用 NegotiateClientCertificate
时,如果 pfCompletionPending
值指示异步完成挂起,则模块必须在调用 方法后立即将处理返回到集成请求处理管道。
示例
以下示例演示如何调用 NegotiateClientCertificate
方法。
REQUEST_NOTIFICATION_STATUS
CMyHttpModule::OnBeginRequest(
IHttpContext* pHttpContext,
IHttpEventProvider* // pProvider
)
{
static long cnt;
InterlockedIncrement (&cnt); // keep track of how many times we are called
HRESULT hr = E_FAIL;
IHttpRequest *pIHTTPR = pHttpContext->GetRequest();
HTTP_REQUEST * pRawRequest = pIHTTPR->GetRawHttpRequest();
HTTP_COOKED_URL hcu = pRawRequest->CookedUrl;
// Send URL and count to the trace window
TRC_MSGW_FULL( L"cnt = " << cnt << " URI: " << hcu.pFullUrl );
// return immediately if not a HTTPS request
if ( pRawRequest->pSslInfo == NULL ){
TRC_MSG( "connection is not using SSL");
return RQ_NOTIFICATION_CONTINUE;
}
// change the bForce flag to test behavior of forcing load of client cert
bool bForce=true;
if(bForce){
TRC_MSG("forcing load of client cert");
hr = pIHTTPR->NegotiateClientCertificate(FALSE);
if(FAILED(hr)){
LOG_ERR_HR(hr, "NegotiateClientCertificate : HR = ");
return RQ_NOTIFICATION_CONTINUE;
}
}
else
TRC_MSG("Not forcing load of client cert");
HTTP_SSL_CLIENT_CERT_INFO *pClientCertInfo;
BOOL fccNeg;
hr = pIHTTPR->GetClientCertificate(&pClientCertInfo,&fccNeg);
// If you have not selected "Require Client Certificates" or called
// NegotiateClientCertificate(), you may get ERROR_NOT_FOUND
if( hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)){
TRC_MSG( "Cert not found" );
return RQ_NOTIFICATION_CONTINUE;
}
if(FAILED(hr)){
LOG_ERR_HR("GetClientCertificate", hr);
return RQ_NOTIFICATION_CONTINUE;
}
if( fccNeg && pClientCertInfo != NULL){
ULONG uSiz = pClientCertInfo->CertEncodedSize;
TRC_MSG( "cert size: " << uSiz \
<< " Previously negotiated " << fccNeg );
unsigned long certCrc = genCRC(pClientCertInfo->pCertEncoded,
pClientCertInfo->CertEncodedSize);
TRC_MSG( "cert crc: " << certCrc );
}
else
TRC_MSG( "No client certificate.");
return RQ_NOTIFICATION_CONTINUE;
}
有关如何创建和部署本机 DLL 模块的详细信息,请参阅 演练:使用本机代码创建 Request-Level HTTP 模块。
可以选择使用调用约定编译代码, __stdcall (/Gz)
而不是为每个函数显式声明调用约定。
要求
类型 | 说明 |
---|---|
客户端 | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10 上的 IIS 10.0 |
服务器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016 上的 IIS 10.0 |
产品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 - IIS Express 7.5、IIS Express 8.0、IIS Express 10.0 |
Header | Httpserv.h |