📄 wmdrm_receiver.c
字号:
/* * The WmdrmNetGetLicenseRequestMessage routine gets all of the data needed for the WMDRMNET License request message. * * Parameters: * * RightsId - Returns the Rights ID for this request * * Message - Returns the License request message * The returned buffer must be freed using FREE. * * MessageSize - Returns the size (in bytes) of the License request message * * Return Value: * DRM_SUCCESS - The operation completed successfully * DRM_E_OUTOFMEMORY - There was not enough memory to perform the operation */DRM_RESULTWmdrmNetGetLicenseRequestMessage( OUT DRM_ID *RightsId, OUT DRM_BYTE **Message, OUT DRM_DWORD *MessageSize ){ DRM_RESULT dr; DRM_BYTE *DeviceCertificate = NULL; DRM_DWORD DeviceCertificateSize; DRM_ID SerialNumber; /* * Get the Device certificate stored in the hardware */ ChkDR( HrdGetCertificate( &DeviceCertificate, &DeviceCertificateSize )); /* * Get the Serial Number stored in the hardware */ ChkDR( HrdGetSerialNumber( &SerialNumber )); /* * Compute a random rights id */ *((uint32 *)RightsId) = OSAL_time_get(); ChkDR( WmdrmNetGenRandomRightsId( (DRM_DWORD *)RightsId )); /* * Build a License request message */ dr = WmdrmNetPackLicenseRequestMessage( RightsId, &SerialNumber, DeviceCertificate, DeviceCertificateSize, (DRM_BYTE *)WMDRMNET_PLAY_ACTION, WMDRMNET_PLAY_ACTION_SIZE, Message, MessageSize ); /* * Cleanup */ErrorExit: if ( DeviceCertificate != NULL ) { FREE( DeviceCertificate ); } return dr;}#define MAX_UNCOMPRESSED_AUDIO_OUTPUT_PROTECTION_LEVEL 300/* * The WmdrmNetProcessLicenseResponseMessage routine processes a received License Response message. * * Parameters: * * ProximityContext - Specifies the context of the operation * * LicenseResponseMessage - Specifies the License response message * * LicenseResponseMessageSize - Specifies the size (in bytes) of the License response message * * Return Value: * DRM_SUCCESS - The operation completed successfully * DRM_E_INVALID_MESSAGE * DRM_E_OUTOFMEMORY */DRM_RESULTWmdrmNetProcessLicenseResponseMessage( IN DRM_ID RightsId, IN DRM_BYTE *LicenseResponseMessage, IN DRM_DWORD LicenseResponseMessageSize, IN DRM_AES_KEY *ContentEncryptionKey ){ DRM_RESULT dr; DRM_ID HrdSerialNumber; DRM_BYTE *pbLicense; DRM_DWORD cbLicense; XMR_LICENSE *pXmrLicense = NULL; crl_rsa_private_key *pRSAPrivateKey = NULL; pRSAPrivateKey = (crl_rsa_private_key *) MALLOC( sizeof(crl_rsa_private_key) ); ChkMem( pRSAPrivateKey ); crl_priv_key_init( (crl_rsa_private_key *)pRSAPrivateKey, (CRL_W8 *)&pbModulus, cbModulus, (CRL_W8 *)&dwExponent, cbModulus, (CRL_W8 *)&pbD, cbD, (CRL_W8 *)&pbP, cbP, (CRL_W8 *)&pbQ, cbQ, NULL, 0, NULL, 0, NULL, 0); /* * Unpack the License response message */ dr = WmdrmNetUnpackLicenseResponseMessage( LicenseResponseMessage, LicenseResponseMessageSize, &pbLicense, &cbLicense ); if ( dr != DRM_SUCCESS ) { TRACE(( "Receiver: Cannot process the License response message. %lx\n", dr )); goto ErrorExit; } /* * Parse the License */ TRACE(( "Receiver: License received: %ld\n", cbLicense )); dr = DrmXmrUnpackLicense( pRSAPrivateKey, pbLicense, cbLicense, &pXmrLicense ); if ( dr != DRM_SUCCESS ) { TRACE(( "Receiver: Cannot unpack XMR License. %lx\n", dr )); goto ErrorExit; } TRACE(( "Receiver: License unpacked\n" )); /* * Verify that the Serial Number matches */ ChkDR( HrdGetSerialNumber( &HrdSerialNumber )); if ( memcmp( &HrdSerialNumber, &(pXmrLicense->gr.SerialNumber), sizeof(HrdSerialNumber) ) != 0) { dr = DRM_E_INVALID_MESSAGE; TRACE(( "Receiver: XMR License contains invalid Serial Number\n" )); goto ErrorExit; } /* * Verify that the Rights ID matches */ if ( memcmp( &RightsId, &(pXmrLicense->RightsId), sizeof(RightsId) ) != 0) { dr = DRM_E_INVALID_MESSAGE; TRACE(( "Receiver: XMR License contains invalid Rights ID\n" )); goto ErrorExit; } /* * Verify that the Output protection object : Minimum Uncompressed Audio Output protection level */ if ( pXmrLicense->mopl.wUncompressedDigitalAudio > MAX_UNCOMPRESSED_AUDIO_OUTPUT_PROTECTION_LEVEL ) { dr = DRM_E_INVALID_MESSAGE; TRACE(( "Receiver: XMR License contains big output protection level \n" )); goto ErrorExit; } /* Unpack Content encryption Key */ dr = DrmXmrGetKeyFromLicense( pRSAPrivateKey, pXmrLicense, TRUE, ContentEncryptionKey ); if ( dr != DRM_SUCCESS ) { TRACE(( "Receiver: Cannot unpack Content Encryption Key. %lx\n", dr )); goto ErrorExit; } TRACE(( "Receiver: Content Encryption Key unpacked\n" )); /* * Success */ dr = DRM_SUCCESS; /* * Cleanup */ErrorExit: if( pXmrLicense != NULL ){ DrmXmrFreeLicense( pXmrLicense ); } return dr;}#define PREPARE_IOREAD_MTP(ev,dev,opCode,opParam,num_param,pbSend,cbSend,pbReceive,cbReceive,resCode) do { \ ev.command = CHILD_CMD_MTP; \ ev.did=dev; \ ev.command_params.mtp_params.mtp_cmdcode=(uint16) opCode; \ ev.command_params.mtp_params.ope_param=(uint32 *) &opParam; \ ev.command_params.mtp_params.param_number=(uint8) num_param; \ ev.command_params.mtp_params.pbMessageToSend=(uint8 *)pbSend; /* send data */ \ ev.command_params.mtp_params.cbMessageToSend=(uint32) cbSend; /* size */ \ ev.command_params.mtp_params.pbMessageReceived=(uint8 **) pbReceive; /* data */ \ ev.command_params.mtp_params.cbMessageReceived=(uint32*) &cbReceive; /* size */ \ ev.command_params.mtp_params.mtp_ResCode=(uint16*) &resCode; /* response code */ } while(0)DRM_RESULTWmdrmNet_TASK_transition( DRM_BYTE handleState ){ DRM_BYTE index; DRM_RESULT dr; DRM_BYTE bMessageType; DRM_WORD OperationCode; DRM_DWORD OperationParameter[5]; DRM_BYTE NumParamater; DRM_WORD ResponseCode = 0; DRM_BYTE *pbMessageToSend = NULL; DRM_DWORD cbMessageToSend = 0; DRM_BYTE **pbMessageReceived = NULL; DRM_DWORD cbMessageReceived; DRM_DWORD RegistrationTransactionID = 0; DRM_ID Challenge; DRM_ID RightsId; DRM_ID EncryptedChallenge; ProximityContext.State = handleState; /* Copy required action to start state. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -