📄 wmdrm_receiver.c
字号:
{ /* * Return the saved Serial Number */ *SerialNumber = HrdSerialNumber; return DRM_SUCCESS;}/*****************************************************************************************************************//*****************************************************************************************************************/ /* * The WmdrmNetGetRegistrationRequestMessage routine gets all of the data needed for the WMDRMNET registration message. * * Parameters: * * Message - Returns the registration message * The returned buffer must be freed using FREE. * * MessageSize - Returns the size (in bytes) of the RegistrationMessage * * Return Value: * DRM_SUCCESS - The operation completed successfully * DRM_E_OUTOFMEMORY - There was not enough memory to perform the operation */DRM_RESULTWmdrmNetGetRegistrationRequestMessage( 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 )); /* * Build a registration message */ dr = WmdrmNetPackRegistrationMessage( &SerialNumber, DeviceCertificate, DeviceCertificateSize, Message, MessageSize ); /* * Cleanup */ErrorExit: if ( DeviceCertificate != NULL ) { FREE( DeviceCertificate ); } return dr;}//DRM_DWORD dwExponent = 65537;const DRM_BYTE dwExponent[128] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01 }; #define cbD 128const DRM_BYTE pbD[128] = { 0x74, 0x1b, 0xb0, 0x89, 0x7b, 0x15, 0x00, 0xcf, 0x34, 0x3e, 0xbc, 0x39, 0x12, 0x46, 0x7e, 0x80, 0xdc, 0x0a, 0x5b, 0x70, 0x55, 0x81, 0x65, 0xac, 0x5c, 0xf2, 0x5d, 0x1f, 0xf1, 0x1a, 0x02, 0xe8, 0xde, 0x82, 0x1a, 0xe5, 0x48, 0xfb, 0x78, 0x21, 0x30, 0x68, 0xc3, 0x02, 0xd2, 0xea, 0xea, 0x73, 0x78, 0xfc, 0x85, 0x20, 0x34, 0x19, 0x87, 0x3e, 0x84, 0x0b, 0x9e, 0x81, 0x38, 0x3e, 0xc3, 0xe6, 0x80, 0x4b, 0xf9, 0xf7, 0x93, 0x3e, 0x22, 0xd2, 0x53, 0x73, 0x9d, 0xdf, 0xae, 0xcc, 0xb8, 0x41, 0xfd, 0x8d, 0x85, 0x60, 0xc8, 0x2c, 0xe6, 0x69, 0xec, 0xbe, 0xc4, 0xd0, 0x4c, 0x40, 0xa2, 0x09, 0xf6, 0x0f, 0x03, 0x95, 0xf7, 0x66, 0x02, 0x9f, 0x51, 0x75, 0xf3, 0xaa, 0x49, 0x72, 0x28, 0xcb, 0x3a, 0x33, 0xe7, 0xb9, 0x4b, 0x54, 0xec, 0x23, 0x9a, 0x48, 0xd2, 0xe2, 0x16, 0x68, 0x80, 0x01 }; #define cbModulus 128const DRM_BYTE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0xa2, 0x0b, 0x9d, 0x17, 0xec, 0x66, 0xf7, 0x79, 0x28, 0xa1, 0x7b, 0x7d, 0xbb, 0x2d, 0xc1 };#define cbQ 64const DRM_BYTE pbQ[64] = { 0xcf, 0x44, 0xd7, 0xda, 0xe7, 0x69, 0x69, 0x8c, 0xda, 0x78, 0x54, 0x91, 0xca, 0x00, 0xbd, 0xdb, 0xf4, 0x1f, 0x93, 0x43, 0x29, 0xa4, 0x43, 0xf3, 0x95, 0xb3, 0xb7, 0x3c, 0xd1, 0xa3, 0xfa, 0x75, 0x5e, 0xbc, 0x46, 0x07, 0x38, 0xe0, 0x37, 0xa3, 0xa7, 0x34, 0x36, 0xc2, 0x0b, 0x12, 0x6b, 0x30, 0xa6, 0xb7, 0x41, 0x9d, 0x27, 0xff, 0xd1, 0xc9, 0xea, 0x39, 0xb0, 0x07, 0x40, 0x20, 0xcf, 0xc1 };/* * The WmdrmNetProcessRegistrationResponseMessage routine processes a received RegistrationResponse message. * * Parameters: * * ProximityContext - Specifies the context of the operation * * RegistrationResponseMessage - Specifies the registration response message * * RegistrationResponseMessageSize - Specifies the size (in bytes) of the registration response message * * Return Value: * DRM_SUCCESS - The operation completed successfully * DRM_E_INVALID_MESSAGE * DRM_E_OUTOFMEMORY */DRM_RESULTWmdrmNetProcessRegistrationResponseMessage( IN DRM_BYTE *RegistrationResponseMessage, IN DRM_DWORD RegistrationResponseMessageSize ){ DRM_RESULT dr; DRM_ID Seed; DRM_ID HrdSerialNumber; DRM_ID MessageSerialNumber; DRM_ID SessionId; DRM_BYTE *Address; DRM_WORD AddressSize; 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 message */ dr = WmdrmNetUnpackRegistrationResponseMessage( pRSAPrivateKey, RegistrationResponseMessage, RegistrationResponseMessageSize, &Seed, &MessageSerialNumber, &SessionId, &Address, &AddressSize ); if ( dr != DRM_SUCCESS) { TRACE(( "Receiver: Cannot unpack RegistrationResponse message %lx\n", dr )); goto ErrorExit; } /* * Ensure the Serial Number matches that of this device */ ChkDR( HrdGetSerialNumber( &HrdSerialNumber )); if ( memcmp( &HrdSerialNumber, &MessageSerialNumber, sizeof(HrdSerialNumber) ) != 0) { dr = DRM_E_INVALID_MESSAGE; TRACE(( "Receiver: RegistrationResponseMessage contains invalid Serial Number\n" )); goto ErrorExit; } /* * Compute the registration content encryption key */ ProximityContext.ProximityContentEncryptionKey = WmdrmNetGetRegistrationKey( &Seed, FALSE ); ChkMem( ProximityContext.ProximityContentEncryptionKey ); /* * Success */ dr = DRM_SUCCESS; /* * Cleanup */ErrorExit: return dr;}#include "osal.h"/******************************************************************************//* Function: *//* *//*! \brief * \param * \return * \remark *//******************************************************************************/DRM_RESULT WmdrmNetGenRandomRightsId(DRM_DWORD *NextSeed){ DRM_AES_KEY *pRandomAesKey = NULL; DRM_UINT64 qwZero = DRM_UI64 ( 0 ); /* Due to Compliance Rule for WMDRM-ND receiver by Microsoft, Random number generation should be Cryptographically Secure Pseudo Random Number generation (CSPRNG). */ /* Generate Random AES key */ *NextSeed = *NextSeed * 1103515245 + 12345; // rand() 0 ~ 31 bits *(NextSeed+1) = *NextSeed * 1103515245 + 12345; // rand() 32 ~ 63 bits *(NextSeed+2) = *(NextSeed+1) * 1103515245 + 12345; // rand() 64 ~ 95 bits *(NextSeed+3) = *(NextSeed+2) * 1103515245 + 12345; // rand() 96 ~ 127 bits /* Cryptographically secure pseudo random number generation by AES CTR mode. */ pRandomAesKey = OEM_DrmAesSetKey( (DRM_BYTE *)NextSeed, DRM_AES_KEYSIZE_128 ); /* Random value is generated by encryption and store into "NextSeed" variable as RightsId. */ DrmAesCtrProcessData( pRandomAesKey, NextSeed, DRM_AES_BLOCKLEN, qwZero, (DRM_WORD)OSAL_time_get()); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -