애플리케이션 인증

애플리케이션이 수행해야 하는 첫 번째 단계는 인증입니다. 인증은 Windows Media 장치 관리자 애플리케이션의 ID를 확인합니다. 애플리케이션을 인증한 후 QueryInterface 를 호출하여 다른 모든 인터페이스에 대해 쿼리할 수 있는 다른 필수 인터페이스에 대해 쿼리할 수 있는 루트 IWMDeviceManager 인터페이스를 가져올 수 있습니다. 인증은 시작할 때 한 번만 수행됩니다.

애플리케이션을 인증하려면 다음 단계를 수행합니다.

  1. MediaDevMgr 개체(클래스 ID MediaDevMgr)를 공동으로 만들고 IComponentAuthenticate 인터페이스를 요청합니다.
  2. 인증을 처리할 CSecureChannelClient 개체를 만듭니다.
  3. 애플리케이션 키를 전달하고 인증서를 보안 채널 개체로 전송합니다. 다음 예제 코드에 표시된 더미 키/인증서를 사용하여 SDK 함수에서 기본 기능을 가져올 수 있습니다. 그러나 전체 기능(디바이스에서 파일을 전달하는 데 중요)을 얻으려면 개발 도구에 설명된 대로 Microsoft에서 키와 인증서를 요청해야 합니다.
  4. 1단계에서 만든 IComponentAuthenticate 인터페이스를 보안 채널 개체에 전달합니다.
  5. CSecureChannelClient::Authenticate를 호출하여 애플리케이션을 인증합니다.
  6. IWMDeviceManager 인터페이스에 대한 IComponentAuthenticate를 쿼리합니다.

이러한 단계는 다음 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;
}

Windows Media 장치 관리자 애플리케이션 만들기