Share via


To Implement IComponentAuthenticate in a Service Provider

banner art
  1. Include Sac.h and Scserver.h.

  2. Link to Mssachlp.lib.

  3. Add the Keys.c file that you received when you signed the license agreement for your project.

  4. Declare a CSecureChannelServer object. This object must be available to all other objects implemented in your component.

  5. Implement IComponentAuthenticate on the main object of your component. For a service provider, this is the object that implements IMDServiceProvider. Use code similar to the following example in the constructor for your main object:

    CMediaDevMgr::CmediaDevMgr()
    {
    g_pAppSCServer = new CSecureChannelServer();
    if (g_pAppSCServer)
    {
           g_pAppSCServer->SetCertificate(SAC_CERT_V1,
                                          (BYTE*)abCert,
                                          sizeof(abCert),
                                          (BYTE*)abPVK, 
                                          sizeof(abPVK) );
    }
    
    }
    
  6. Delegate the methods of IComponentAuthenticate to the global CSecureChannelServer object. Use code such as:

    // Example to implement SACAuth.
    HRESULT CMediaDevMgr::SACAuth(DWORD dwProtocolID,
                                  DWORD dwPass,
                                  BYTE *pbDataIn,
                                  DWORD dwDataInLen,
                                  BYTE **ppbDataOut,
                                  DWORD *pdwDataOutLen)
    {
        HRESULT hr;
        if (g_pAppSCServer)
        {
            hr = g_pAppSCServer->SACAuth(dwProtocolID, 
                                         dwPass, 
                                         pbDataIn, 
                                         dwDataInLen, 
                                         ppbDataOut, 
                                         pdwDataOutLen);
        }
        else
        {
            hr = E_FAIL;
        }
        return hr;
    
    // Example of how to implement SACGetProtocols.
    HRESULT CMediaDevMgr::SACGetProtocols(DWORD **ppdwProtocols,
                                          DWORD *pdwProtocolCount)
    {
        HRESULT hr;
        if (g_pAppSCServer)
        {
            hr = g_pAppSCServer->SACGetProtocols(ppdwProtocols,
                                                 pdwProtocolCount);
        }
        else
        {
            hr = E_FAIL;
        }
        return hr;
    }
    
  7. When the caller has not been authenticated, return WMDM_E_NOT_CERTIFIED from all of your methods.

See Also