对应用程序进行身份验证

应用程序必须执行的第一步是身份验证。 身份验证向 Windows Media 设备管理器验证应用程序的标识。 对应用程序进行身份验证后,可以调用 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 设备管理器 应用程序