Skip to main content

How to Bind SWFs to a Host?



I'm working on a major Flash project that is going to be the core content of a site.





As most of you well know, almost any site can be entirely copied by copying the cached files and the hierarchy (files and folders structure), and it would run without problems on an Apache server with PHP enabled, if used.





What I would like to know is: How to bind SWF files to run on a specific host?





The SWFs will be encrypted, so outsiders won't have access to the methods used to stop the SWF from running on a different host, question is: what method to use?





I think the solution could be hardcoding the host IP inside the SWF, so if the SWF is looking for 123.123.123.123, only a host with that IP would allow the SWF to run further.





The issue is that AS3 alone can't discover the host IP or could it if it's trying to load a resource file? Anyway, that's why I need your help.





EDIT: Ok, seems someone asked for something similar earlier: Can you secure your swf so it checks if it is running on a recognized environment? I'll try that and see how it works, but the question is still open in case anyone has different suggestions.


Comments

  1. One method you could try is a php script that the swf sends a request to and must receive a correct reply from before it continues to operate. Since people can't get at your server-side php, they can't get the needed code to simulate that reply.

    ReplyDelete
  2. The SWFs will be encrypted, so outsiders won't have access to the methods used to stop the SWF from running on a different host
    Since the file will run on a client computer (and thus they key would have to be stored in an accessible way), this isn't really that much of a protection.


    The best way would probably be to have part of the SWF-logic on the server, and not give access to that part from third party hosts (by using the crossdomain file).

    ReplyDelete
  3. Look into the idea of wrapping main inside a type of preloader, and putting main into a secure dir on the server. I cant remember how this gets around the cache problem, but it had to do with how the wrapper loads main.

    Something like this:

    // preloader.as (embedded in fla)
    var imageLoader:Loader;

    function randomNumber(low:Number=NaN, high:Number=NaN):Number
    {
    var low:Number = low;
    var high:Number = high;

    if(isNaN(low))
    {
    throw new Error("low must be defined");
    }
    if(isNaN(high))
    {
    throw new Error("high must be defined");
    }

    return Math.round(Math.random() * (high - low)) + low;
    }
    function loadImage(url:String):void {
    imageArea.visible=false;
    preloader.visible = true;
    // Set properties on my Loader object
    imageLoader = new Loader();
    imageLoader.load(new URLRequest(url));
    imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
    imageArea.addChild(imageLoader);
    }
    // DOIT!
    loadImage("main.sw?"+randomNumber(1000,10000)); //NOT A TYPO!
    //loadImage("main.swf"+randomNumber(1000,10000);


    function imageLoaded(e:Event):void {
    // Hide Preloader
    preloader.visible = false;
    }

    function imageLoading(e:ProgressEvent):void {
    // Get current download progress
    var loaded:Number = e.bytesLoaded / e.bytesTotal;
    // Send progress info to "preloader" movie clip
    preloader.SetProgress(loaded);
    }

    /// this is main.sw //NOT A TYPO
    <?php
    // Tried this - abandoned
    // session_start();
    //
    // if(isset($_SESSION["flash"])) {
    // $referrer = $_SERVER["HTTP_REFERER"];
    // $referrer = parse_url($referrer);
    // if($referrer["host"] != $_SESSION["flash"]) {
    // echo "Permission denied.";
    // exit();
    // }
    // } else {
    // echo "Permission denied.";
    // exit();
    // }
    //
    // unset($_SESSION["flash"]);

    header("Content-type: application/x-shockwave-flash");
    readfile("/secure/main.swf");
    ?>

    // main.as
    public function onCreationComplete(event:Event):void{
    Security.allowDomain( "*" );
    Security.loadPolicyFile( "crossdomain.xml" );
    }

    // crossdomain.xml
    <?xml version="1.0"?>
    <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
    <allow-access-from domain="*" />
    </cross-domain-policy>


    That should get you started. The idea here was to prevent anyone from getting main on their machine- I am not sure if it worked.

    ReplyDelete
  4. I use this method to determine if I am on dev or production in my config files.

    var lc:LocalConnection = new LocalConnection();
    switch ( lc.domain ){
    case "myDomain.com":
    case "":// local file reference for dev
    case "localhost":// local file reference for dev
    case "dev.mydomain.com":// local file reference for dev
    break;
    default:
    // unknown domain do crash the app here
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.