IHttpRequest::NegotiateClientCertificate-Methode
Initiiert die Clientzertifikataushandlung mit einem Webclient.
Syntax
HRESULT NegotiateClientCertificate(
IN BOOL fAsync,
OUT BOOL* pfCompletionPending = NULL
)
Parameter
fAsync
[IN] true
, um anzugeben, dass die Aushandlung asynchron erfolgen soll; false
andernfalls .
pfCompletionPending
[OUT] true
, um anzugeben, dass eine asynchrone Vervollständigung aussteht; false
andernfalls .
Rückgabewert
HRESULT
. Mögliches Werte (aber nicht die Einzigen) sind die in der folgenden Tabelle.
Wert | Definition |
---|---|
S_OK | Gibt an, dass der Vorgang erfolgreich war. |
E_FAIL | Gibt an, dass der Vorgang fehlgeschlagen ist. |
Bemerkungen
Entwickler können die NegotiateClientCertificate
-Methode verwenden, um die Clientzertifikataushandlung mit einem Webclient manuell zu initiieren, auch wenn IIS so konfiguriert ist, dass Clientzertifikate akzeptiert oder ignoriert werden. NegotiateClientCertificate
unterstützt sowohl synchrone als auch asynchrone Vorgänge, indem die entsprechende Einstellung im fAsync
Parameter angegeben wird. Wenn Ihr Modul asynchron aufruft NegotiateClientCertificate
, muss das Modul die Verarbeitung unmittelbar nach dem Aufruf der -Methode an die integrierte Anforderungsverarbeitungspipeline zurückgeben, wenn der pfCompletionPending
Wert angibt, dass ein asynchroner Abschluss aussteht.
Beispiel
Im folgenden Beispiel wird veranschaulicht, wie die -Methode aufgerufen wird 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;
}
Weitere Informationen zum Erstellen und Bereitstellen eines nativen DLL-Moduls finden Sie unter Exemplarische Vorgehensweise: Erstellen eines Request-Level HTTP-Moduls mithilfe von nativem Code.
Sie können den Code optional kompilieren, indem Sie die __stdcall (/Gz)
Aufrufkonvention verwenden, anstatt die Aufrufkonvention für jede Funktion explizit zu deklarieren.
Anforderungen
type | BESCHREIBUNG |
---|---|
Client | – IIS 7.0 unter Windows Vista – IIS 7.5 unter Windows 7 – IIS 8.0 unter Windows 8 – IIS 10.0 unter Windows 10 |
Server | – IIS 7.0 unter Windows Server 2008 – IIS 7.5 unter Windows Server 2008 R2 – IIS 8.0 unter Windows Server 2012 – IIS 8.5 unter Windows Server 2012 R2 – IIS 10.0 unter Windows Server 2016 |
Produkt | – 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 |
Weitere Informationen
IHttpRequest-Schnittstelle
IHttpRequest::GetClientCertificate-Methode