Home | History | Annotate | Download | only in socket
      1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_H_
      6 #define NET_SOCKET_SSL_CLIENT_SOCKET_H_
      7 
      8 #include "net/socket/client_socket.h"
      9 
     10 namespace net {
     11 
     12 class SSLCertRequestInfo;
     13 class SSLInfo;
     14 
     15 // A client socket that uses SSL as the transport layer.
     16 //
     17 // NOTE: The SSL handshake occurs within the Connect method after a TCP
     18 // connection is established.  If a SSL error occurs during the handshake,
     19 // Connect will fail.
     20 //
     21 class SSLClientSocket : public ClientSocket {
     22  public:
     23   // Next Protocol Negotiation (NPN) allows a TLS client and server to come to
     24   // an agreement about the application level protocol to speak over a
     25   // connection.
     26   enum NextProtoStatus {
     27     kNextProtoUnsupported = 0,  // The server doesn't support NPN.
     28     kNextProtoNegotiated = 1,   // We agreed on a protocol.
     29     kNextProtoNoOverlap = 2,    // No protocols in common. We requested
     30                                 // the first protocol in our list.
     31   };
     32 
     33   // Next Protocol Negotiation (NPN), if successful, results in agreement on an
     34   // application-level string that specifies the application level protocol to
     35   // use over the TLS connection. NextProto enumerates the application level
     36   // protocols that we recognise.
     37   enum NextProto {
     38     kProtoUnknown = 0,
     39     kProtoHTTP11 = 1,
     40     kProtoSPDY = 2,
     41   };
     42 
     43   // Gets the SSL connection information of the socket.
     44   virtual void GetSSLInfo(SSLInfo* ssl_info) = 0;
     45 
     46   // Gets the SSL CertificateRequest info of the socket after Connect failed
     47   // with ERR_SSL_CLIENT_AUTH_CERT_NEEDED.
     48   virtual void GetSSLCertRequestInfo(
     49       SSLCertRequestInfo* cert_request_info) = 0;
     50 
     51   // Get the application level protocol that we negotiated with the server.
     52   // *proto is set to the resulting protocol (n.b. that the string may have
     53   // embedded NULs).
     54   //   kNextProtoUnsupported: *proto is cleared.
     55   //   kNextProtoNegotiated:  *proto is set to the negotiated protocol.
     56   //   kNextProtoNoOverlap:   *proto is set to the first protocol in the
     57   //                          supported list.
     58   virtual NextProtoStatus GetNextProto(std::string* proto) = 0;
     59 
     60   static NextProto NextProtoFromString(const std::string& proto_string) {
     61     if (proto_string == "http1.1") {
     62       return kProtoHTTP11;
     63     } else if (proto_string == "spdy") {
     64       return kProtoSPDY;
     65     } else {
     66       return kProtoUnknown;
     67     }
     68   }
     69 };
     70 
     71 }  // namespace net
     72 
     73 #endif  // NET_SOCKET_SSL_CLIENT_SOCKET_H_
     74