OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived | 5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived |
6 // from AuthCertificateCallback() in | 6 // from AuthCertificateCallback() in |
7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. | 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. |
8 | 8 |
9 /* ***** BEGIN LICENSE BLOCK ***** | 9 /* ***** BEGIN LICENSE BLOCK ***** |
10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 * | 45 * |
46 * ***** END LICENSE BLOCK ***** */ | 46 * ***** END LICENSE BLOCK ***** */ |
47 | 47 |
48 #include "net/socket/ssl_client_socket_nss.h" | 48 #include "net/socket/ssl_client_socket_nss.h" |
49 | 49 |
50 #include <certdb.h> | 50 #include <certdb.h> |
51 #include <hasht.h> | 51 #include <hasht.h> |
52 #include <keyhi.h> | 52 #include <keyhi.h> |
53 #include <nspr.h> | 53 #include <nspr.h> |
54 #include <nss.h> | 54 #include <nss.h> |
55 #include <ocsp.h> | |
55 #include <pk11pub.h> | 56 #include <pk11pub.h> |
56 #include <secerr.h> | 57 #include <secerr.h> |
57 #include <sechash.h> | 58 #include <sechash.h> |
58 #include <ssl.h> | 59 #include <ssl.h> |
59 #include <sslerr.h> | 60 #include <sslerr.h> |
60 #include <sslproto.h> | 61 #include <sslproto.h> |
61 | 62 |
62 #include <limits> | 63 #include <limits> |
63 | 64 |
64 #include "base/compiler_specific.h" | 65 #include "base/compiler_specific.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 #endif | 105 #endif |
105 | 106 |
106 static const int kRecvBufferSize = 4096; | 107 static const int kRecvBufferSize = 4096; |
107 | 108 |
108 // kCorkTimeoutMs is the number of milliseconds for which we'll wait for a | 109 // kCorkTimeoutMs is the number of milliseconds for which we'll wait for a |
109 // Write to an SSL socket which we're False Starting. Since corking stops the | 110 // Write to an SSL socket which we're False Starting. Since corking stops the |
110 // Finished message from being sent, the server sees an incomplete handshake | 111 // Finished message from being sent, the server sees an incomplete handshake |
111 // and some will time out such sockets quite aggressively. | 112 // and some will time out such sockets quite aggressively. |
112 static const int kCorkTimeoutMs = 200; | 113 static const int kCorkTimeoutMs = 200; |
113 | 114 |
115 #if defined(OS_LINUX) | |
wtc
2010/11/23 00:44:45
We should ideally test USE_NSS instead of OS_LINUX
agl
2010/11/30 15:59:46
I think this is specifically a Linux (and maybe Fr
| |
116 // On Linux, we dynamically link against the system version of libnss3.so. In | |
117 // order to continue working on systems without up-to-date versions of NSS we | |
118 // declare CERT_CacheOCSPResponseFromSideChannel to be a weak symbol. If, at | |
119 // run time, we find that the symbol didn't resolve then we can avoid calling | |
120 // the function. | |
121 extern SECStatus | |
122 CERT_CacheOCSPResponseFromSideChannel( | |
123 CERTCertDBHandle *handle, CERTCertificate *cert, PRTime time, | |
124 SECItem *encodedResponse, void *pwArg) __attribute__((weak)); | |
wtc
2010/11/23 00:44:45
Does "weak" need to be double-parenthesized?
agl
2010/11/30 15:59:46
It's the GCC syntax.
| |
125 | |
126 static bool HaveCacheOCSPResponseFromSideChannelFunction() { | |
127 return CERT_CacheOCSPResponseFromSideChannel != NULL; | |
128 } | |
129 #else | |
130 // On other platforms we ship this function ourselves so we know that we have | |
wtc
2010/11/23 00:44:45
This comment is misleading because on other platfo
agl
2010/11/30 15:59:46
Have changed the comment to include that point, ha
| |
131 // it. | |
132 static bool HaveCacheOCSPResponseFromSideChannelFunction() { | |
133 return true; | |
134 } | |
135 #endif | |
136 | |
114 namespace net { | 137 namespace net { |
115 | 138 |
116 // State machines are easier to debug if you log state transitions. | 139 // State machines are easier to debug if you log state transitions. |
117 // Enable these if you want to see what's going on. | 140 // Enable these if you want to see what's going on. |
118 #if 1 | 141 #if 1 |
119 #define EnterFunction(x) | 142 #define EnterFunction(x) |
120 #define LeaveFunction(x) | 143 #define LeaveFunction(x) |
121 #define GotoState(s) next_handshake_state_ = s | 144 #define GotoState(s) next_handshake_state_ = s |
122 #define LogData(s, len) | 145 #define LogData(s, len) |
123 #else | 146 #else |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 if (!ssl_config_.next_protos.empty()) { | 817 if (!ssl_config_.next_protos.empty()) { |
795 rv = SSL_SetNextProtoNego( | 818 rv = SSL_SetNextProtoNego( |
796 nss_fd_, | 819 nss_fd_, |
797 reinterpret_cast<const unsigned char *>(ssl_config_.next_protos.data()), | 820 reinterpret_cast<const unsigned char *>(ssl_config_.next_protos.data()), |
798 ssl_config_.next_protos.size()); | 821 ssl_config_.next_protos.size()); |
799 if (rv != SECSuccess) | 822 if (rv != SECSuccess) |
800 LogFailedNSSFunction(net_log_, "SSL_SetNextProtoNego", ""); | 823 LogFailedNSSFunction(net_log_, "SSL_SetNextProtoNego", ""); |
801 } | 824 } |
802 #endif | 825 #endif |
803 | 826 |
827 #ifdef SSL_ENABLE_OCSP_STAPLING | |
828 if (!ssl_config_.snap_start_enabled) { | |
829 rv = SSL_OptionSet(nss_fd_, SSL_ENABLE_OCSP_STAPLING, PR_TRUE); | |
830 if (rv != SECSuccess) | |
831 LogFailedNSSFunction(net_log_, "SSL_OptionSet (OCSP stapling)", ""); | |
832 } | |
833 #endif | |
834 | |
804 rv = SSL_OptionSet(nss_fd_, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); | 835 rv = SSL_OptionSet(nss_fd_, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); |
805 if (rv != SECSuccess) { | 836 if (rv != SECSuccess) { |
806 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_HANDSHAKE_AS_CLIENT"); | 837 LogFailedNSSFunction(net_log_, "SSL_OptionSet", "SSL_HANDSHAKE_AS_CLIENT"); |
807 return ERR_UNEXPECTED; | 838 return ERR_UNEXPECTED; |
808 } | 839 } |
809 | 840 |
810 rv = SSL_AuthCertificateHook(nss_fd_, OwnAuthCertHandler, this); | 841 rv = SSL_AuthCertificateHook(nss_fd_, OwnAuthCertHandler, this); |
811 if (rv != SECSuccess) { | 842 if (rv != SECSuccess) { |
812 LogFailedNSSFunction(net_log_, "SSL_AuthCertificateHook", ""); | 843 LogFailedNSSFunction(net_log_, "SSL_AuthCertificateHook", ""); |
813 return ERR_UNEXPECTED; | 844 return ERR_UNEXPECTED; |
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2150 if (certs[i]->derCert.len != state.certs[i].size() || | 2181 if (certs[i]->derCert.len != state.certs[i].size() || |
2151 memcmp(certs[i]->derCert.data, state.certs[i].data(), | 2182 memcmp(certs[i]->derCert.data, state.certs[i].data(), |
2152 certs[i]->derCert.len) != 0) { | 2183 certs[i]->derCert.len) != 0) { |
2153 predicted_cert_chain_correct_ = false; | 2184 predicted_cert_chain_correct_ = false; |
2154 break; | 2185 break; |
2155 } | 2186 } |
2156 } | 2187 } |
2157 } | 2188 } |
2158 } | 2189 } |
2159 | 2190 |
2191 #if defined(SSL_ENABLE_OCSP_STAPLING) | |
2192 if (!predicted_cert_chain_correct_ && | |
2193 HaveCacheOCSPResponseFromSideChannelFunction()) { | |
wtc
2010/11/23 00:44:45
Could you add a TODO comment to note that we need
agl
2010/11/30 15:59:46
Done.
| |
2194 unsigned int len = 0; | |
2195 SSL_GetOCSPStapledData(nss_fd_, NULL, &len); | |
2196 if (len) { | |
2197 const unsigned int orig_len = len; | |
2198 scoped_array<uint8> ocsp_response(new uint8[orig_len]); | |
2199 SSL_GetOCSPStapledData(nss_fd_, ocsp_response.get(), &len); | |
2200 DCHECK_EQ(orig_len, len); | |
2201 | |
2202 SECItem ocsp_response_item; | |
2203 memset(&ocsp_response_item, 0, sizeof(ocsp_response_item)); | |
wtc
2010/11/23 00:44:45
Nit: you can replace this memset call with
ocs
agl
2010/11/30 15:59:46
Done.
| |
2204 ocsp_response_item.data = ocsp_response.get(); | |
2205 ocsp_response_item.len = len; | |
2206 | |
2207 CERT_CacheOCSPResponseFromSideChannel( | |
2208 CERT_GetDefaultCertDB(), server_cert_nss_, PR_Now(), | |
2209 &ocsp_response_item, NULL); | |
2210 } | |
2211 } | |
2212 #endif | |
2213 | |
2160 SaveSnapStartInfo(); | 2214 SaveSnapStartInfo(); |
2161 // SSL handshake is completed. It's possible that we mispredicted the | 2215 // SSL handshake is completed. It's possible that we mispredicted the |
2162 // NPN agreed protocol. In this case, we've just sent a request in the | 2216 // NPN agreed protocol. In this case, we've just sent a request in the |
2163 // wrong protocol! The higher levels of this network stack aren't | 2217 // wrong protocol! The higher levels of this network stack aren't |
2164 // prepared for switching the protocol like that so we make up an error | 2218 // prepared for switching the protocol like that so we make up an error |
2165 // and rely on the fact that the request will be retried. | 2219 // and rely on the fact that the request will be retried. |
2166 if (IsNPNProtocolMispredicted()) { | 2220 if (IsNPNProtocolMispredicted()) { |
2167 LOG(WARNING) << "Mispredicted NPN protocol for " | 2221 LOG(WARNING) << "Mispredicted NPN protocol for " |
2168 << host_and_port_.ToString(); | 2222 << host_and_port_.ToString(); |
2169 net_error = ERR_SSL_SNAP_START_NPN_MISPREDICTION; | 2223 net_error = ERR_SSL_SNAP_START_NPN_MISPREDICTION; |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2605 case SSL_CONNECTION_VERSION_TLS1_1: | 2659 case SSL_CONNECTION_VERSION_TLS1_1: |
2606 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1); | 2660 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_1); |
2607 break; | 2661 break; |
2608 case SSL_CONNECTION_VERSION_TLS1_2: | 2662 case SSL_CONNECTION_VERSION_TLS1_2: |
2609 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2); | 2663 UpdateConnectionTypeHistograms(CONNECTION_SSL_TLS1_2); |
2610 break; | 2664 break; |
2611 }; | 2665 }; |
2612 } | 2666 } |
2613 | 2667 |
2614 } // namespace net | 2668 } // namespace net |
OLD | NEW |