1// Copyright (c) 2010 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#include "net/socket/ssl_client_socket.h"
6
7namespace net {
8
9SSLClientSocket::SSLClientSocket()
10    : was_npn_negotiated_(false),
11      was_spdy_negotiated_(false) {
12}
13
14SSLClientSocket::NextProto SSLClientSocket::NextProtoFromString(
15    const std::string& proto_string) {
16  if (proto_string == "http1.1" || proto_string == "http/1.1") {
17    return kProtoHTTP11;
18  } else if (proto_string == "spdy/1") {
19    return kProtoSPDY1;
20  } else if (proto_string == "spdy/2") {
21    return kProtoSPDY2;
22  } else {
23    return kProtoUnknown;
24  }
25}
26
27bool SSLClientSocket::IgnoreCertError(int error, int load_flags) {
28  if (error == OK || load_flags & LOAD_IGNORE_ALL_CERT_ERRORS)
29    return true;
30
31  if (error == ERR_CERT_COMMON_NAME_INVALID &&
32      (load_flags & LOAD_IGNORE_CERT_COMMON_NAME_INVALID))
33    return true;
34
35  if (error == ERR_CERT_DATE_INVALID &&
36      (load_flags & LOAD_IGNORE_CERT_DATE_INVALID))
37    return true;
38
39  if (error == ERR_CERT_AUTHORITY_INVALID &&
40      (load_flags & LOAD_IGNORE_CERT_AUTHORITY_INVALID))
41    return true;
42
43  return false;
44}
45
46bool SSLClientSocket::was_npn_negotiated() const {
47  return was_npn_negotiated_;
48}
49
50bool SSLClientSocket::set_was_npn_negotiated(bool negotiated) {
51  return was_npn_negotiated_ = negotiated;
52}
53
54bool SSLClientSocket::was_spdy_negotiated() const {
55  return was_spdy_negotiated_;
56}
57
58bool SSLClientSocket::set_was_spdy_negotiated(bool negotiated) {
59  return was_spdy_negotiated_ = negotiated;
60}
61
62}  // namespace net
63