This Question is Answered

2 "helpful" answers available (5 pts)
16 Replies Last post: Jun 5, 2008 9:04 PM by Daniel  
BenV Bronze 65 posts since
Jan 25, 2007
Currently Being Moderated

May 7, 2008 12:19 PM

[PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

So, the latest versions of Flash 9.0.115.0 and 9.0.124.0 are much more strict about which sockets you are allowed to connect to. Openfire is configured to serve a policy file on a separate port (5229) than the client port (5222). This works fine, except for some of our users behind strict firewalls do not have port 5229 open, as it is not very common.

 

 

This patch allows openfire to recognize a cross-domain policy request in the form of a "policy-file-request" and automatically serve up a cross-domain policy which allows flash to connect to the client port. After the policy is sent, the connection is closed.

 

 

 

 

I hope this can be accepted into trunk, as it really is a pain to require our users to open two ports in their firewall just to be able to connect. The simple change is inside StanzaHandler.java, at the top of the process function:

 

 

 

 

 

 


 
public void process(String stanza, XMPPPacketReader reader) throws Exception {
        boolean initialStream = stanza.startsWith("<stream:stream") || stanza.startsWith("></stream:stream>" ) ){
             & nbsp;      String crossDomainText = FlashCrossDomainHandler.CROSS_DOMAIN_TEXT +
             & nbsp;          XMPPServer.getInstance().getConnectionManager().getClientListenerPort() +
             & nbsp;          FlashCrossDomainHandler.CROSS_DOMAIN_END_TEXT + '\0';
             & nbsp;      connection.deliverRawText( crossDomainText );
             & nbsp;      return;
             & nbsp;  } else {
             & nbsp;      // Ignore <?xml version="1.0"?>
             & nbsp;      return;
             & nbsp;  }
            }

 

With this code in place, I can remove the call to System.security.loadPolicyFile("xmlsocket://" + address + ":5229" ) which is currently required.

 

 

 

 

 

Here is the output from the flash debugger, which shows that the strict policy rules are being followed properly:

 

 

 

OK: Policy file accepted: xmlsocket://localhost:5222

OK: Request for resource at xmlsocket://localhost:5222 by requestor from http://localhost:3000/flash/chat.swf

 

 

 

 

 

 

 

 

 

 

I hope this is helpful to others, it is really a lifesaver for us.

 

Message was edited by: BenV

Attachments:
Gaston Dombiak Jiver 3,751 posts since
Sep 26, 2001
Currently Being Moderated
May 5, 2008 10:44 PM in response to: BenV
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

Hey Ben,

 

Excellent improvement. I will see to include it for Openfire 3.5.2 and trunk (3.6.0).

 

Thanks,

 

  -- Gato

Gaston Dombiak Jiver 3,751 posts since
Sep 26, 2001
Currently Being Moderated
May 6, 2008 6:45 PM in response to: BenV
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

Hey Ben,

 

Do you want me to delete the connection.close() that was included in your added code?

 

Thanks,

 

  -- Gato

Gaston Dombiak Jiver 3,751 posts since
Sep 26, 2001
Currently Being Moderated
May 13, 2008 7:12 PM in response to: BenV
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

Hey Ben,

 

Thanks for contributing this enhancement. I filed it as JM-1361 and checked it in for Openfire 3.6.0.

 

Regards,

 

  -- Gato

ikester Bronze 16 posts since
Jun 23, 2006
Currently Being Moderated
May 9, 2008 6:14 PM in response to: BenV
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

This should also help with another problem we're seeing which appears to be a timing issue related to the implementation in FlashCrossDomainHandler. As it's coded, the Handler DOES NOT WAIT for the <policy-file-request> string to come in and just sends the policy stream back as soon as the socket is connected. Under unpredictable circumstances we see the Flash player opening the socket and getting the policy file back from the server BEFORE it requests it. When this happens the System.security.loadPolicyFile() call fails, presumably because it needs to get it AFTER the request is made.

 

I'm also assuming that Ben's patch benefits from NIO since it's inside the regular stanza handler (is that the case?). The FlashCrossDomainHandler was a single threaded socket listener suffering from scalability issues. Of course they weren't apparent until recently when the new, stricter Flash Players became available.

 

Thanks for this patch Ben!

 

Ike

Joacim Breiler Bronze 1 posts since
Mar 10, 2008
Currently Being Moderated
May 10, 2008 10:00 AM in response to: BenV
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

 

Great work!

 

 

I just would like to confirm your suggested update.

 

 

Some of our users have had problems with our implementation of a group chat client.

We've been using the 5229 for serving the policy file, and even though some of our users are

not using firewalls, they were not able to connect...

 

 

After applying your patch and removing the 'loadPolicyFile', our users are able to connect.

 

 

Thanks!

 

 

 

 

 

 

Prasanta Saha Bronze 1 posts since
May 25, 2008
Currently Being Moderated
May 25, 2008 2:30 AM in response to: Joacim Breiler
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

I think this patch has been implemented with the 3.6.0 Alpha version. I have downloaded and installed the same and is working absolutely fine. I am very thankful to all of you in openfire team.

 

 

 

 

Now it never fails to connect because of crossdomain.xml. I dont need to load policy file from 5229 port.

 

 

 

 

 

 

Thanks and regard,

 

 

 

 

 

 

Prasanta Saha

 

 

 

http://www.labymaze.co.in

Daniel Bronze 58 posts since
Jun 22, 2006
Currently Being Moderated
May 11, 2008 8:34 PM in response to: BenV
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

 

I just installed this patch and it solved a heap of issues we are having.

 

 

I look forward to this being in the next release of Openfire!

 

 

Thanks

 

 

Daniel

 

 

Noam Bronze 4 posts since
Apr 17, 2008
Currently Being Moderated
May 25, 2008 4:51 AM in response to: BenV
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

 

Hey Ben,

 

Excellent improvement.

 

 

I hope to see it in next Openfire versions (3.5.2 and 3.6.0).

 

Thanks!!!

 

 

Andrew Van Hoesen Bronze 12 posts since
Oct 23, 2007
Currently Being Moderated
Jun 5, 2008 1:20 PM in response to: Noam
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

 

I was able to run this in the 6/5/2008 nightly build successfully.  Is there any prespective date this functionality this will be released.  I noticed this particular nightly build was 3.6.0 Alpha.  Is Jive going to release a 3.5.2 version with this particular piece or no 3.5.2 version at all?

 

 

Gaston Dombiak Jiver 3,751 posts since
Sep 26, 2001
Currently Being Moderated
Jun 5, 2008 1:46 PM in response to: Andrew Van Hoesen
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

Hey Andrew,

 

Being a new feature we initially decided to leave it for Openfire 3.6.0. However, I think that there is no risk in moving it to Openfire 3.5.2 that will be released next week. If you want us to move it just let us know.

 

Thanks,

 

  -- Gato

Gaston Dombiak Jiver 3,751 posts since
Sep 26, 2001
Currently Being Moderated
Jun 5, 2008 1:50 PM in response to: Gaston Dombiak
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

Hey Andrew,

 

Done. The patch was moved to 3.5.2 so it will be available next week.

 

Regards,

 

  -- Gato

Andrew Van Hoesen Bronze 12 posts since
Oct 23, 2007
Currently Being Moderated
Jun 5, 2008 2:16 PM in response to: Gaston Dombiak
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

 

Wow, you're fast!  Before I could reply you already had the fix in place.  I look forward to the release next week.

 

 

Daniel Bronze 58 posts since
Jun 22, 2006
Currently Being Moderated
Jun 5, 2008 9:04 PM in response to: Gaston Dombiak
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

 

We have been using the latest builds in the live environment just because of this patch as it solves a bunch of firewall issues.

 

 

Since we have recently upgraded to use the XIFF flash libraries rather than the old third party jabberflash javascript libraries it has meant that we could BIND direct from a client to the Openfire server on port 80! (whereas before we had to use ISAPI rewrite as you couldn't bind to a different domain using JavaScript - due to security but it works in Flash).

 

 

We have Openfire setup to listen on port 80 for BOSH connections - and do not run any other web servers on that computer.

 

 

This is heaps better for scalability / reliability etc and the firewalls don't block port 80. And no need to proxy the bind requests through the web servers.

 

 

Now the question is - do you think you should also add the binding port to the recent patch that serves the crossdomain.xml file as it is only allowing the port for socket connections currently?

 

 

&lt;?xml version="1.0" ?&gt;   &lt;!DOCTYPE cross-domain-policy (View Source for full doctype...)&gt; - &lt;cross-domain-policy&gt;   &lt;allow-access-from domain="**" to-ports="5222" secure="true*" /&gt;   &lt;/cross-domain-policy&gt;

 

 

So the ports= both the socket and binding ports as set in openfire.

 

 

Please let me know if this makes sense or maybe I am confusing how Flash security works - they couldn't make it more complicated if they tried!

 

 

Thanks

 

 

Daniel

 

 

 

 

 

 

 

 

 

 

Andrew Van Hoesen Bronze 12 posts since
Oct 23, 2007
Currently Being Moderated
Jun 5, 2008 1:57 PM in response to: Gaston Dombiak
Re: [PATCH] Allow Openfire to serve cross-domain policy on client port for Flash

 

I would be most appreciative if this functionality could be incorporated into the 3.5.2 version for next week's release.  Is there any official channel or person I need to get in contact with to make this happen?

 

 

 

 

-Andy

 

 

More Like This

  • Retrieving data ...