Metodo IHttpRequest::GetClientCertificate
Recupera il certificato client associato alla richiesta.
Sintassi
HRESULT GetClientCertificate(
OUT HTTP_SSL_CLIENT_CERT_INFO** ppClientCertInfo,
OUT BOOL* pfClientCertNegotiated
);
Parametri
ppClientCertInfo
[OUT] Puntatore a una struttura HTTP_SSL_CLIENT_CERT_INFO .
pfClientCertNegotiated
[OUT] true
se il certificato client è già stato negoziato; in caso contrario, false
. Per altre informazioni, vedere la sezione Osservazioni.
Valore restituito
Oggetto HRESULT
. I valori possibili includono, ma non sono limitati a, quelli indicati nella tabella seguente.
valore | Definizione |
---|---|
S_OK | Indica che non si è verificato alcun errore, ma non garantisce che sia stato trovato un certificato. Per altre informazioni, vedere la sezione Osservazioni. |
HRESULT_FROM_WIN32(ERROR_NOT_FOUND) | Indica che non è stato trovato alcun certificato client. ERROR_NOT_FOUND è definito in Winerror.h. |
ERROR_INVALID_PARAMETER | Indica che il ppClientCertInfo parametro o pfClientCertNegotiated è NULL. |
Commenti
Un valore HRESULT riuscito non garantisce che sia stato trovato un certificato client. Gli sviluppatori devono anche verificare che ppClientCertInfo
non sia NULL.
Un pfClientCertNegotiated
valore di true
non garantisce che l'oggetto ppClientCertInfo
non sia NULL.
Gli sviluppatori possono usare il GetClientCertificate
metodo per recuperare il certificato client associato alla richiesta corrente. Dopo aver chiamato il GetClientCertificate
metodo , il ppClientCertInfo
parametro conterrà un puntatore a una HTTP_SSL_CLIENT_CERT_INFO
struttura, che conterrà il certificato client se disponibile o NULL se non è disponibile alcun certificato.
Per gli URL che non richiedono un certificato client, è possibile chiamare il metodo NegotiateClientCertificate prima di chiamare GetClientCertificate
per tentare un caricamento manuale del certificato client.
Esempio
Nell'esempio seguente viene illustrato come ottenere un puntatore alla struttura HTTP_SSL_CLIENT_CERT_INFO implementando il metodo CHttpModule::OnBeginRequest .
void checkForClientCert(IHttpContext* pHttpContext)
{
static long cnt;
// keep track of how many times we are called
InterlockedIncrement (&cnt);
HRESULT hr = S_OK;
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;
}
HTTP_SSL_CLIENT_CERT_INFO *pClientCertInfo=NULL;
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) ||
pClientCertInfo == NULL ){
TRC_HR_MSG(hr, "Cert not found" );
return;
}
if(FAILED(hr)){
LOG_ERR_HR("GetClientCertificate", hr);
return;
}
// You must verify pClientCertInfo != NULL
if( fccNeg && pClientCertInfo != NULL){
ULONG uSiz = pClientCertInfo->CertEncodedSize;
TRC_MSG( "cert size: " << uSiz \
<< " Previously negotiated " << fccNeg );
// compute the CRC check sum of the certificate
unsigned long certCrc = genCRC(pClientCertInfo->pCertEncoded,
pClientCertInfo->CertEncodedSize);
TRC_MSG( "cert crc: " << certCrc );
}
else
TRC_MSG( "No client certificate. fccNeg = " << fccNeg );
}
REQUEST_NOTIFICATION_STATUS
CMyHttpModule::OnBeginRequest(
IHttpContext* pHttpContext,
IHttpEventProvider* // pProvider
)
{
checkForClientCert(pHttpContext);
return RQ_NOTIFICATION_CONTINUE;
}
Per altre informazioni su come creare e distribuire un modulo DLL nativo, vedere Procedura dettagliata: Creazione di un modulo HTTP Request-Level tramite codice nativo.
Facoltativamente, è possibile compilare il codice usando la __stdcall (/Gz)
convenzione di chiamata anziché dichiarare in modo esplicito la convenzione di chiamata per ogni funzione.
Requisiti
Tipo | Descrizione |
---|---|
Client | - IIS 7.0 in Windows Vista - IIS 7.5 in Windows 7 - IIS 8.0 in Windows 8 - IIS 10.0 in Windows 10 |
Server | - IIS 7.0 in Windows Server 2008 - IIS 7.5 in Windows Server 2008 R2 - IIS 8.0 in Windows Server 2012 - IIS 8.5 in Windows Server 2012 R2 - IIS 10.0 in Windows Server 2016 |
Prodotto | - 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 |
Intestazione | Httpserv.h |
Vedere anche
Interfaccia IHttpRequest
Metodo IHttpRequest::NegotiateClientCertificate