Branch: Tag:

2014-08-08

2014-08-08 12:26:57 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Protocols: Added StartTLSProtocol.

This is a protocol that starts out in clear text, but supports
the option of switching to SSL/TLS later.

2284:   }      #if constant(SSL.sslfile) - class SSLProtocol - //! Base protocol for SSL ports. Exactly like Port, but uses SSL. + //! Base protocol for protocols that support upgrading to TLS. + //! + //! Exactly like Port, but contains settings for TLS. + class StartTLSProtocol   {    inherit Protocol;   
2542:    }    }    -  SSL.sslfile accept() -  { -  Stdio.File q = ::accept(); -  if (q) -  return SSL.sslfile (q, ctx); -  return 0; -  } -  -  protected void bind (void|int ignore_eaddrinuse) -  { -  // Don't bind if we don't have correct certs. -  if (!ctx->certificates) return; -  ::bind (ignore_eaddrinuse); -  } -  +     void create(int pn, string i, void|int ignore_eaddrinuse)    {    ctx->random = Crypto.Random.random_string;
2581:       string _sprintf( )    { +  return "StartTLSProtocol(" + get_url() + ")"; +  } + } +  + class SSLProtocol + //! Base protocol for SSL ports. + //! + //! Exactly like Port, but uses SSL. + { +  inherit StartTLSProtocol; +  +  SSL.sslfile accept() +  { +  Stdio.File q = ::accept(); +  if (q) +  return SSL.sslfile (q, ctx); +  return 0; +  } +  +  protected void bind (void|int ignore_eaddrinuse) +  { +  // Don't bind if we don't have correct certs. +  if (!ctx->certificates) return; +  ::bind (ignore_eaddrinuse); +  } +  +  string _sprintf( ) +  {    return "SSLProtocol(" + get_url() + ")";    }   }
5914:   #endif      #if constant(SSL.sslfile) +  add_constant( "StartTLSProtocol", StartTLSProtocol );    add_constant( "SSLProtocol", SSLProtocol );   #endif