Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Utilizzare il metodo ICertServerPolicy::SetCertificateProperty per impostare le proprietà dell'oggetto di un certificato. Le proprietà del soggetto sono proprietà correlate al proprietario del certificato o alla persona che ha richiesto il certificato. Per un elenco delle proprietà dell'oggetto, vedere Proprietà dei nomi.
È anche possibile utilizzare il metodo SetCertificateProperty per impostare le proprietà del certificato NotBefore e NotAfter. Per una descrizione delle proprietà del certificato NotBefore e NotAfter, vedere Proprietà del certificato.
Utilizzare il metodo ICertServerPolicy::SetCertificateExtension per aggiungere un numero qualsiasi di estensioni al certificato. È possibile usare le estensioni per aggiungere informazioni supplementari sull'oggetto o sull'utilizzo al certificato. Per altre informazioni, vedere Gestori di estensione.
Nell'esempio seguente viene impostata una proprietà e un'estensione del certificato in un certificato. Chiamare i metodi SetCertificateProperty e SetCertificateExtension nell'implementazione ICertPolicy2::VerifyRequest . L'esempio non è un'implementazione VerifyRequest completa; l'esempio non mostra la logica di verifica.
#include <windows.h>
#include <stdio.h>
STDMETHODIMP CCertPolicy::VerifyRequest(
BSTR const strConfig,
LONG Context,
LONG bNewRequest,
LONG Flags,
LONG __RPC_FAR *pDisposition)
{
HRESULT hr = S_OK;
ICertServerPolicy *pServer = NULL;
BSTR bstrPropName = NULL;
VARIANT vPropValue;
BSTR bstrExtName = NULL;
VARIANT vExtValue;
// Retrieve an ICertServerPolicy interface pointer.
hr = CoCreateInstance( CLSID_CCertServerPolicy,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICertServerPolicy,
(void **) &pServer );
if (FAILED( hr ))
{
printf("Failed CoCreateInstance for ICertServerPolicy "
"- %x\n", hr );
return hr;
}
// Set the context to which this request refers.
hr = pServer->SetContext(Context);
if (FAILED( hr ))
{
printf("Failed SetContext(%u) - %x\n", Context, hr );
pServer->Release();
return hr;
}
// Specify the subject property to set on the certificate.
bstrPropName = SysAllocString(L"Subject.EMail");
if ( NULL == bstrPropName )
{
hr = E_OUTOFMEMORY;
printf("Failed SysAllocString for bstrPropName "
"(no memory)\n" );
pServer->Release();
return hr;
}
VariantInit( &vPropValue );
vPropValue.VT_BSTR;
vPropValue.bstrVal = SysAllocString(L"someone@example.com");
if ( NULL == vPropValue.bstrVal )
{
hr = E_OUTOFMEMORY;
printf("Failed SysAllocString for vPropValue "
"(no memory)\n" );
SysFreeString(bstrPropName);
pServer->Release();
return hr;
}
// Set the subject property on the certificate.
hr = pServer->SetCertificateProperty( bstrPropName,
PROPTYPE_STRING,
&vPropValue );
SysFreeString(bstrPropName);
VariantClear(&vPropValue);
if (FAILED(hr))
{
printf("Failed SetCertificateProperty - %x\n", hr);
pServer->Release();
return hr;
}
// Specify the extension property to set on the certificate.
bstrExtName = SysAllocString(L"2.29.38.4");
if ( NULL == bstrExtName )
{
hr = E_OUTOFMEMORY;
printf("Failed SysAllocString for bstrExtName "
"(no memory)\n" );
pServer->Release();
return hr;
}
VariantInit( &vExtValue );
vExtValue.VT_BSTR;
vExtValue.bstrVal = SysAllocString
(L"https://example.microsoft.com");
if ( NULL == vExtValue.bstrVal )
{
hr = E_OUTOFMEMORY;
printf("Failed SysAllocString for vExtValue (no memory)\n" );
SysFreeString(bstrExtName);
pServer->Release();
return hr;
}
// Set the extension property on the certificate.
hr = pServer->SetCertificateExtension( bstrExtName,
PROPTYPE_STRING,
EXTENSION_CRITICAL_FLAG,
&vExtValue );
SysFreeString(bstrExtName);
VariantClear(&vExtValue);
if (FAILED(hr))
{
printf("Failed SetCertificateExtension - %x\n", hr);
pServer->Release();
return hr;
}
pServer->Release();
return(hr);
}