dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Policy file server for flash as2/as3 clients

  1. #1
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    954

    Policy file server for flash as2/as3 clients

    Going to leave this here to fix security issue error #2048 in as2/as3 because everyones hosting it in a non actionscript language.

    This is an adobe air as3 script that I wrote to host on port 843 to respond to <policy-file-request/> requests you have to forward port 843 on your router for your machine as well.

    PHP Code:
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.events.ServerSocketConnectEvent;
    import flash.net.ServerSocket;
    import flash.net.Socket;
    import flash.utils.ByteArray;
    import flash.net.FileReference;
    import flash.filesystem.File;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;

    var 
    socket:XMLSocket;
    var 
    clientObject = {};
    var 
    pid:Number=0;
    var 
    policy='<cross-domain-policy><allow-access-from domain="*" to-ports="*" /><allow-access-from domain="127.0.0.1" to-ports="*" /></cross-domain-policy>'
    var nullByte;
    var 
    serverSocket:ServerSocket = new ServerSocket();
    var 
    clientSocket:Socket;
    serverSocket.bind(843);
    serverSocket.addEventListener(ServerSocketConnectEvent.CONNECTonConnection);
    serverSocket.listen();

    socket = new XMLSocket();
    socket.connect("127.0.0.1",843);        
    socket.send(policy);
    var 
    msg_num=0
    var parsedString
    var completeString
    function onClientSocketData(e:ProgressEvent){
    e.currentTarget.writeUTFBytes(policy)
    e.currentTarget.flush();
    e.currentTarget.close();
    }
    function 
    onConnection(e:ServerSocketConnectEvent){
    clientSocket e.socket;
    clientSocket.addEventListener(ProgressEvent.SOCKET_DATAonClientSocketData);

    Last edited by Alloy Bacon; 12-03-2018 at 03:42 AM.

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,774
    Nice. I wish that there was an option for dcp as well. tcp only limited the potential a lot.
    .

  3. #3
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    954
    Yeah but tcp fixes lost packets, maybe there is for udp havent needed udp yet but im surprised the policy didn't need a nullbyte, it was getting rejected with a nullbyte. I left some old unused variables in there too hmm.
    Last edited by Alloy Bacon; 12-04-2018 at 06:04 PM.

  4. #4
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    954
    new update to remove running event listeners when the client disconnects and gets its data:

    PHP Code:
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.events.ServerSocketConnectEvent;
    import flash.net.ServerSocket;
    import flash.net.Socket;
    import flash.utils.ByteArray;
    import flash.net.FileReference;
    import flash.filesystem.File;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;

    var 
    socket:XMLSocket;
    var 
    clientObject = {};
    var 
    pid:Number=0;
    var 
    policy='<cross-domain-policy><allow-access-from domain="*" to-ports="45055" /><allow-access-from domain="127.0.0.1" to-ports="*" /></cross-domain-policy>'
    var nullByte;
    var 
    serverSocket:ServerSocket = new ServerSocket();
    var 
    clientSocket:Socket;
    serverSocket.bind(843);
    serverSocket.addEventListener(ServerSocketConnectEvent.CONNECTonConnection);
    serverSocket.listen();

    socket = new XMLSocket();
    socket.connect("127.0.0.1",843);        
    socket.send(policy);
    var 
    msg_num=0
    var parsedString
    var completeString
    function onClientSocketData(e:ProgressEvent){
    clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.removeEventListener(ProgressEvent.SOCKET_DATAonClientSocketData);
    clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.removeEventListener(Event.CLOSE,closed);
    clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.removeEventListener(IOErrorEvent.IO_ERROR,closed);delete clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()]
    delete clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()]
    e.currentTarget.writeUTFBytes(policy)
    e.currentTarget.flush();
    e.currentTarget.close();
    }
    var 
    cnt=0
    function closed(e:*){
    clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.removeEventListener(ProgressEvent.SOCKET_DATAonClientSocketData);
    clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.removeEventListener(Event.CLOSE,closed);
    clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.removeEventListener(IOErrorEvent.IO_ERROR,closed);
    delete clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()]
    }
    function 
    onConnection(e:ServerSocketConnectEvent){
    clientSocket e.socket;
    clientSocket.addEventListener(ProgressEvent.SOCKET_DATAonClientSocketData);
    clientSocket.addEventListener(Event.CLOSEclosed);
    clientSocket.addEventListener(IOErrorEvent.IO_ERRORclosed);
    clientObject[(clientSocket.remoteAddress).toString()+":"+(clientSocket.remotePort).toString()] = {call_name:(clientSocket.remoteAddress).toString()+":"+(clientSocket.remotePort).toString(), connection:e.socket};

    Last edited by Alloy Bacon; 12-04-2018 at 06:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center