Bug 1056934 - Part 5: Open TLS sockets when communicating with a TLS endpoint. r=drno
authorByron Campen [:bwc] <docfaraday@gmail.com>
Tue, 03 Jan 2017 12:32:54 -0600
changeset 357705 c100d0ad4d4a8d6e5d5c1d35d09b853a733784c9
parent 357704 8689021c7d766f55654fec638a4793e13ed9659e
child 357706 a78433dca4bbdba58b232cea94251381b79a7549
push id10621
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 16:02:43 +0000
treeherdermozilla-aurora@dca7b42e6c67 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno
bugs1056934
milestone53.0a1
Bug 1056934 - Part 5: Open TLS sockets when communicating with a TLS endpoint. r=drno MozReview-Commit-ID: 1V7bzPLPBYi
media/mtransport/nr_socket_prsock.cpp
media/mtransport/nr_socket_prsock.h
--- a/media/mtransport/nr_socket_prsock.cpp
+++ b/media/mtransport/nr_socket_prsock.cpp
@@ -868,16 +868,20 @@ void NrSocket::close() {
 
 
 int NrSocket::connect(nr_transport_addr *addr) {
   ASSERT_ON_THREAD(ststhread_);
   int r,_status;
   PRNetAddr naddr;
   int32_t connect_status, getsockname_status;
 
+  // TODO: Add TLS layer with nsISocketProviderService?
+  if (addr->tls_host[0] != '\0')
+    ABORT(R_INTERNAL);
+
   if ((r=nr_transport_addr_to_praddr(addr, &naddr)))
     ABORT(r);
 
   if(!fd_)
     ABORT(R_EOD);
 
   // Note: this just means we tried to connect, not that we
   // are actually live.
@@ -1850,40 +1854,43 @@ void NrTcpSocketIpc::close() {
                 NS_DISPATCH_NORMAL);
 
   //remove all enqueued messages
   std::queue<RefPtr<nr_tcp_message>> empty;
   std::swap(msg_queue_, empty);
 }
 
 int NrTcpSocketIpc::connect(nr_transport_addr *addr) {
-  nsCString remote_addr, local_addr;
+  nsCString remote_addr, local_addr, tls_host;
   int32_t remote_port, local_port;
   int r, _status;
   if ((r=nr_transport_addr_get_addrstring_and_port(addr,
                                                    &remote_addr,
                                                    &remote_port))) {
     ABORT(r);
   }
 
   if ((r=nr_transport_addr_get_addrstring_and_port(&my_addr_,
                                                    &local_addr,
                                                    &local_port))) {
     MOZ_ASSERT(false); // shouldn't fail as it was sanity-checked in ::create()
     ABORT(r);
   }
 
+  tls_host = addr->tls_host;
+
   state_ = mirror_state_ = NR_CONNECTING;
   RUN_ON_THREAD(io_thread_,
                 mozilla::WrapRunnable(RefPtr<NrTcpSocketIpc>(this),
                              &NrTcpSocketIpc::connect_i,
                              remote_addr,
                              static_cast<uint16_t>(remote_port),
                              local_addr,
-                             static_cast<uint16_t>(local_port)),
+                             static_cast<uint16_t>(local_port),
+                             tls_host),
                 NS_DISPATCH_NORMAL);
 
   // Make caller wait for ready to write.
   _status = R_WOULDBLOCK;
  abort:
   return _status;
 }
 
@@ -1949,31 +1956,41 @@ int NrTcpSocketIpc::listen(int backlog) 
 
 int NrTcpSocketIpc::accept(nr_transport_addr *addrp, nr_socket **sockp) {
   return R_INTERNAL;
 }
 
 void NrTcpSocketIpc::connect_i(const nsACString &remote_addr,
                                uint16_t remote_port,
                                const nsACString &local_addr,
-                               uint16_t local_port) {
+                               uint16_t local_port,
+                               const nsACString &tls_host) {
   ASSERT_ON_THREAD(io_thread_);
   mirror_state_ = NR_CONNECTING;
 
   dom::TCPSocketChild* child = new dom::TCPSocketChild(NS_ConvertUTF8toUTF16(remote_addr), remote_port);
   socket_child_ = child;
 
   // Bug 1285330: put filtering back in here
 
-  // XXX remove remote!
-  socket_child_->SendWindowlessOpenBind(this,
-                                        remote_addr, remote_port,
-                                        local_addr, local_port,
-                                        /* use ssl */ false,
-                                        /* reuse addr port */ true);
+  if (tls_host.IsEmpty()) {
+    // XXX remove remote!
+    socket_child_->SendWindowlessOpenBind(this,
+                                          remote_addr, remote_port,
+                                          local_addr, local_port,
+                                          /* use ssl */ false,
+                                          /* reuse addr port */ true);
+  } else {
+    // XXX remove remote!
+    socket_child_->SendWindowlessOpenBind(this,
+                                          tls_host, remote_port,
+                                          local_addr, local_port,
+                                          /* use ssl */ true,
+                                          /* reuse addr port */ true);
+  }
 }
 
 void NrTcpSocketIpc::write_i(nsAutoPtr<InfallibleTArray<uint8_t>> arr,
                              uint32_t tracking_number) {
   ASSERT_ON_THREAD(io_thread_);
   if (!socket_child_) {
     return;
   }
--- a/media/mtransport/nr_socket_prsock.h
+++ b/media/mtransport/nr_socket_prsock.h
@@ -365,17 +365,18 @@ private:
   class TcpSocketReadyRunner;
   DISALLOW_COPY_ASSIGN(NrTcpSocketIpc);
   virtual ~NrTcpSocketIpc();
 
   // Main thread executors of the NrSocketBase APIs
   void connect_i(const nsACString &remote_addr,
                  uint16_t remote_port,
                  const nsACString &local_addr,
-                 uint16_t local_port);
+                 uint16_t local_port,
+                 const nsACString &tls_host);
   void write_i(nsAutoPtr<InfallibleTArray<uint8_t>> buf,
                uint32_t tracking_number);
   void close_i();
 
   static void release_child_i(dom::TCPSocketChild* aChild, nsCOMPtr<nsIEventTarget> ststhread);
 
   // STS thread executor
   void message_sent_s(uint32_t bufferedAmount, uint32_t tracking_number);