123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- /*
- * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- #include "ReplayProtectedDRM.h"
- #include "TimeBasedDRM.h"
- #include <iostream>
- using namespace std;
- #include <string.h>
- #include <unistd.h>
- #define memcpy_s(dst,dst_size,src,max_count) memcpy(dst,src,max_count)
- #define Sleep(n) usleep((n)*1000)
- uint32_t test_replay_protected_drm_operation()
- {
- cout<<endl<<"\tReplay Protected DRM operation:"<<endl;
- uint32_t result = 0;
- ReplayProtectedDRM DRM;
- result = DRM.init();
- if(result)
- {
- cerr<<"Initialization the DRM failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully initialized the DRM."<<endl;
- do{
- result = DRM.perform_function();
- if(result)
- {
- cerr<<"Performing the DRM functions failed."<<endl;
- break;
- }
- else
- cout<<"Successfully performed the DRM functions."<<endl;
- result = DRM.update_secret();
- if(result)
- {
- cerr<<"Updating the DRM secret failed."<<endl;
- break;
- }
- else
- cout<<"Successfully updated the DRM secret."<<endl;
- result = DRM.perform_function();
- if(result)
- {
- cerr<<"Performing the DRM functions failed."<<endl;
- break;
- }
- else
- cout<<"Successfully performed the DRM functions."<<endl;
- }while(0);
- if(DRM.delete_secret())
- {
- cerr<<"Deleting the DRM secret failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully deleted the DRM secret."<<endl;
- return result;
- }
- uint32_t test_replay_protected_drm_update_limitation()
- {
- cout<<endl<<"\tReplay Protected DRM update limitation:"<<endl;
- uint32_t result = 0;
- ReplayProtectedDRM DRM;
- result = DRM.init();
- if(result)
- {
- cerr<<"Initialization the DRM failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully initialized the DRM."<<endl;
- do{
- result = DRM.perform_function();
- if(result)
- {
- cerr<<"Performing the DRM functions fail."<<endl;
- break;
- }
- else
- cout<<"Successfully performed the DRM functions."<<endl;
- for (int i = 0; i <= REPLAY_PROTECTED_PAY_LOAD_MAX_RELEASE_VERSION; i++)
- {
- result = DRM.update_secret();
- if(result == MAX_RELEASE_REACHED &&
- i>=REPLAY_PROTECTED_PAY_LOAD_MAX_RELEASE_VERSION)
- {
- cout<<"\tExpected failure."<<endl
- <<"\tThe DRM secret update limitation reached."<<endl;
- result = 0;
- return result;
- }
- else if(result)
- {
- cerr<<"Updating the DRM secret failed."<<endl;
- break;
- }
- else
- cout<<"Successfully updated the DRM secret."<<endl;
- result = DRM.perform_function();
- if(result)
- {
- cerr<<"Performing the DRM functions failed."<<endl;
- break;
- }
- else
- cout<<"Successfully performed the DRM functions."<<endl;
- }
- if(!result)
- {
- result = 1;
- cerr<<"\tUnexpected success."<<endl
- <<"\tFailed to catch update limitation."<<endl;
- }
- }while(0);
- if(DRM.delete_secret())
- {
- cerr<<"Deleting the DRM secret failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully deleted the DRM secret."<<endl;
- return result;
- }
- uint32_t test_replay_protected_drm_replay_attack_protection()
- {
- cout<<endl<<"\tReplay Protected DRM replay attack protection:"<<endl;
- uint32_t result = 0;
- uint8_t sealed_log[ReplayProtectedDRM::sealed_activity_log_length];
- ReplayProtectedDRM DRM;
- result = DRM.init(sealed_log);
- if(result)
- {
- cerr<<"Initialization the DRM failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully initialized the DRM."<<endl;
- /* store a valid log for replay attack */
- uint8_t replay_log[ReplayProtectedDRM::sealed_activity_log_length];
- memcpy_s(replay_log,ReplayProtectedDRM::sealed_activity_log_length,
- sealed_log,ReplayProtectedDRM::sealed_activity_log_length);
- do{
- result = DRM.update_secret(sealed_log);
- if(result)
- {
- cerr<<"Updating the DRM secret functions failed."<<endl;
- break;
- }
- else
- cout<<"Successfully updated the DRM functions."<<endl;
- result = DRM.perform_function(replay_log);
- if(result == REPLAY_DETECTED)
- cout<<"\tExpected failure."<<endl
- <<"\tReplay attack to DRM functions is caught."<<endl;
- else
- {
- cerr<<"\tUnexpected success."<<endl
- <<"\tReplay attack to DRM functions is NOT caught."<<endl;
- result = 1;
- break;
- }
- result = DRM.perform_function(sealed_log);
- if(result)
- {
- cerr<<"Performing the DRM functions failed."<<endl;
- break;
- }
- else
- cout<<"Successfully performed the DRM functions ."<<endl;
- }while(0);
- if(DRM.delete_secret(sealed_log))
- {
- cerr<<"Deleting the DRM secret failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully deleted the DRM secret."<<endl;
- return result;
- }
- uint32_t test_time_based_policy_operation()
- {
- cout<<endl<<"\tTime based policy operation:"<<endl;
- TimeBasedDRM DRM;
- uint32_t result = 0;
- result = DRM.init();
- if(result)
- {
- cerr<<"Initialization the time based policy failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully initialized the time based policy."<<endl;
- result = DRM.perform_function();
- if(result)
- {
- cerr<<"Performing the time based policy functions failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully performed the time based policy functions."<<endl;
- return 0;
- }
- uint32_t test_time_based_policy_expiration()
- {
- cout<<endl<<"\tTime based policy expiration:"<<endl;
- TimeBasedDRM DRM;
- uint32_t result = 0;
- result = DRM.init();
- if(result)
- {
- cerr<<"Initialization the time based policy failed."<<endl;
- return result;
- }
- else
- cout<<"Successfully initialized the time based policy."<<endl;
- /* wait for time based DRM expiring */
- Sleep((TIME_BASED_LEASE_DURATION_SECOND+1)*1000);
- result = DRM.perform_function();
- if(result== LEASE_EXPIRED)
- {
- cout<<"\tExpected failure."<<endl
- <<"\tTime based policy has expired."<<endl;
- return 0;
- }
- else
- {
- cerr<<"\tUnexpected success."<<endl
- <<"\tTime based policy failed to catch expiration."<<endl;
- return 1;
- }
- }
- #define _T(x) x
- int main(int argc, char* argv[])
- {
- argc; /* unused parameter */
- argv; /* unused parameter */
- uint32_t result;
- /* normal operation */
- result = test_replay_protected_drm_operation();
- /* trigger update limitation */
- result = test_replay_protected_drm_update_limitation();
- /* replay attack */
- result = test_replay_protected_drm_replay_attack_protection();
- /* normal operation */
- result = test_time_based_policy_operation();
- /* trigger expiration */
- result = test_time_based_policy_expiration();
-
- printf("Enter a character before exit ...\n");
- getchar();
- return 0;
- }
|