애플리케이션 인증
애플리케이션이 수행해야 하는 첫 번째 단계는 인증입니다. 인증은 Windows Media Device Manager에 대한 애플리케이션의 ID를 확인합니다. 애플리케이션을 인증하면, QueryInterface을 호출하여 루트 IWMDeviceManager 인터페이스를 얻을 수 있습니다. 이는 다른 필요한 인터페이스를 쿼리할 수 있고, 각 인터페이스는 또 다른 모든 인터페이스에 대해 쿼리할 수 있습니다. 인증은 시작할 때 한 번만 수행하면 됩니다.
애플리케이션을 인증하려면 다음 단계를 수행합니다.
- MediaDevMgr 개체(ID MediaDevMgr 클래스)를 공동 생성하고 IComponentAuthenticate 인터페이스를 요청합니다.
- 인증을 처리할 CSecureChannelClient 개체를 만듭니다.
- 애플리케이션 키를 전달하고 인증서를 보안 채널 개체로 전송합니다. 다음 예제 코드에 표시된 더미 키/인증서를 사용하여 SDK 함수에서 기본 기능을 가져올 수 있습니다. 그러나 전체 기능(디바이스에서 파일을 전달하는 데 중요)을 얻으려면 Tools for Development설명한 대로 Microsoft에서 키와 인증서를 요청해야 합니다.
- 1단계에서 만든 IComponentAuthenticate 인터페이스를 보안 채널 개체에 전달합니다.
- CSecureChannelClient::Authenticate 호출하여 애플리케이션을 인증합니다.
- IComponentAuthenticate를 IWMDeviceManager 인터페이스에 대해 쿼리합니다.
이러한 단계는 다음 C++ 코드에 나와 있습니다.
HRESULT CWMDMController::Authenticate()
{
// Use a dummy key/certificate pair to allow basic functionality.
// An authentic keypair is required for full SDK functionality.
BYTE abPVK[] = {0x00};
BYTE abCert[] = {0x00};
HRESULT hr;
CComPtr<IComponentAuthenticate> pAuth;
// Create the WMDM object and acquire
// its authentication interface.
hr = CoCreateInstance(
__uuidof(MediaDevMgr),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IComponentAuthenticate),
(void**)&pAuth);
if (FAILED(hr)) return hr;
// Create the secure channel client class needed to authenticate the application.
// We'll use a global member variable to hold the secure channel client
// in case we need to handle encryption, decryption, or MAC verification
// during this session.
m_pSAC = new CSecureChannelClient;
if (m_pSAC == NULL) return E_FAIL;
// Send the application's transfer certificate and the associated
// private key to the secure channel client.
hr = m_pSAC->SetCertificate(
SAC_CERT_V1,
(BYTE *)abCert, sizeof(abCert),
(BYTE *)abPVK, sizeof(abPVK));
if (FAILED(hr)) return hr;
// Send the authentication interface we created to the secure channel
// client and authenticate the application with the V1 protocol.
// (This is the only protocol currently supported.)
m_pSAC->SetInterface(pAuth);
hr = m_pSAC->Authenticate(SAC_PROTOCOL_V1);
if (FAILED(hr)) return hr;
// Authentication succeeded, so we can use WMDM.
// Query for the root WMDM interface.
hr = pAuth->QueryInterface( __uuidof(IWMDeviceManager), (void**)&m_IWMDMDeviceMgr);
return hr;
}
관련 항목