title: Set Punjab as a BOSH XMPP Proxy for Facebook Chat
body: <p>I want to use Punjab as an xmpp proxy for Facebook Chat</p>
  
  <p>Punjab is running well but when i ask chat.facebook.com it won't work</p>
  
  <pre><code>SENT: &lt;body rid='313820892' xmlns='http://jabber.org/protocol/httpbind' to='chat.facebook.com' xml:lang='en' wait='300' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:xmpp='urn:xmpp:xbosh'/&gt;
  RECV: &lt;body xmlns='http://jabber.org/protocol/httpbind' type='terminate' condition='remote-connection-failed'/&gt;
  </code></pre>
  
  <p>When we look at the punjab log we wan see that punjab connect to chat.facebook.com but don't have any answer</p>
  
  <pre><code>2012/03/09 10:42 +0200 [-] Log opened.
  2012/03/09 10:42 +0200 [-] twistd 2.5.0 (/usr/bin/python 2.5.0) starting up
  2012/03/09 10:42 +0200 [-] reactor class: &lt;class 'twisted.internet.selectreactor.SelectReactor'&gt;
  2012/03/09 10:42 +0200 [-] Loading punjab.tac...
  2012/03/09 10:42 +0200 [-] twisted.web.server.Site starting on 5281
  2012/03/09 10:42 +0200 [-] Starting factory &lt;twisted.web.server.Site instance at 0xb785c58c&gt;
  2012/03/09 10:42 +0200 [-] Loaded.
  2012/03/09 10:42 +0200 [-] twisted.web.server.Site starting on 5280
  2012/03/09 10:42 +0200 [HTTPChannel,0,127.0.0.1] HEADERS 1331282556.16:
  2012/03/09 10:42 +0200 [HTTPChannel,0,127.0.0.1] {'origin': 'http://mydomain.tld', 'content-length': '264', 'via': '1.1 mydomain.tld', 'accept-language': 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4', 'accept-encoding': 'gzip,deflate,sdch', 'x-forwarded-host': 'mydomain.tld', 'x-forwarded-for': 'XXX.XXX.XXX.XXX', 'connection': 'Keep-Alive', 'accept': '*/*', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Ubuntu/11.10 Chromium/17.0.963.65 Chrome/17.0.963.65 Safari/535.11', 'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'host': 'localhost:5280', 'referer': 'http://mydomain.tld/facebook/', 'max-forwards': '10', 'cookie': '_jsuid=2679835210; fbm_XXXXXXXXX=base_domain=.mydomain.tld; fbsr_XXXXXXXXX=XXXXXXXXX', 'x-forwarded-server': 'mydomain.tld', 'content-type': 'application/xml'}
  2012/03/09 10:42 +0200 [HTTPChannel,0,127.0.0.1] HTTPB POST : 
  2012/03/09 10:42 +0200 [HTTPChannel,0,127.0.0.1] &lt;body rid='XXXXXXXXX' xmlns='http://jabber.org/protocol/httpbind' to='chat.facebook.com' xml:lang='en' wait='300' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xml='http://www.w3.org/XML/1998/namespace' xmlns:xmpp='urn:xmpp:xbosh'/&gt;
  2012/03/09 10:42 +0200 [HTTPChannel,0,127.0.0.1] Session Created : afeb0b2bf66d6ca8b5f5fee83ebbb449b64f4c65 1331282556.16
  2012/03/09 10:42 +0200 [HTTPChannel,0,127.0.0.1] ================================== 1331282556.17 connect to chat.facebook.com:5222 ==================================
  2012/03/09 10:42 +0200 [HTTPChannel,0,127.0.0.1] Starting factory &lt;punjab.session.Session instance at 0xb77e4eac&gt;
  2012/03/09 10:42 +0200 [HTTPChannel,0,127.0.0.1] twisted.names.dns.DNSDatagramProtocol starting on 55647
  2012/03/09 10:42 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] &lt;punjab.session.XMPPClientConnector instance at 0xb77e4f6c&gt; will retry in 3 seconds
  2012/03/09 10:42 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory &lt;punjab.session.Session instance at 0xb77e4eac&gt;
  2012/03/09 10:42 +0200 [-] Starting factory &lt;punjab.session.Session instance at 0xb77e4eac&gt;
  2012/03/09 10:42 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] &lt;punjab.session.XMPPClientConnector instance at 0xb77e4f6c&gt; will retry in 10 seconds
  2012/03/09 10:42 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory &lt;punjab.session.Session instance at 0xb77e4eac&gt;
  2012/03/09 10:42 +0200 [-] Starting factory &lt;punjab.session.Session instance at 0xb77e4eac&gt;
  2012/03/09 10:42 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Abandoning &lt;punjab.session.XMPPClientConnector instance at 0xb77e4f6c&gt; after 3 retries.
  2012/03/09 10:42 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory &lt;punjab.session.Session instance at 0xb77e4eac&gt;
  2012/03/09 10:43 +0200 [-] ================================== afeb0b2bf66d6ca8b5f5fee83ebbb449b64f4c65 1331282584.43 startup timeout ==================================
  2012/03/09 10:43 +0200 [-] HTTPB Error 200
  2012/03/09 10:43 +0200 [-] HTTPB Return Error: 200 -&gt; &lt;body xmlns='http://jabber.org/protocol/httpbind' type='terminate' condition='remote-connection-failed'/&gt;
  </code></pre>
  
  <p>My punjab tac file with the ssl configuration for facebook :</p>
  
  <pre><code># punjab tac file
  from twisted.web import server, resource, static
  from twisted.application import service, internet
  from twisted.internet import reactor, ssl
  
  from punjab.httpb  import Httpb, HttpbService
  
  root = static.File("./html")
  
  bosh = HttpbService(1)
  
  root.putChild('http-bind', resource.IResource(bosh))
  
  site  = server.Site(root)
  
  application = service.Application("punjab")
  internet.TCPServer(5280, site).setServiceParent(application)
  
  #
  # RMW adding TLS support for Facebook chat/xmpp support
  #
  sslContext = ssl.DefaultOpenSSLContextFactory(
          '/root/punjab_privkey.pem',
          '/root/punjab_cacert.pem',
  )
  reactor.listenSSL(
          5281,
          site,
          contextFactory=sslContext,
  )
  </code></pre>
  
  <p>Do you know why i don't have any answer from chat.facebook.com ?</p>
  
  <p>Thank you</p>