Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: net/socket/openssl_ssl_util.cc

Issue 401153002: Switch to BoringSSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase across DEPS change Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/aead_base_encrypter_openssl.cc ('k') | net/socket/ssl_client_socket_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "net/socket/openssl_ssl_util.h" 5 #include "net/socket/openssl_ssl_util.h"
6 6
7 #include <errno.h>
8
7 #include <openssl/err.h> 9 #include <openssl/err.h>
8 #include <openssl/ssl.h> 10 #include <openssl/ssl.h>
9 11
10 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
11 #include "base/location.h" 13 #include "base/location.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
13 #include "crypto/openssl_util.h" 15 #include "crypto/openssl_util.h"
14 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
15 17
16 namespace net { 18 namespace net {
(...skipping 15 matching lines...) Expand all
32 public: 34 public:
33 OpenSSLNetErrorLibSingleton() { 35 OpenSSLNetErrorLibSingleton() {
34 crypto::EnsureOpenSSLInit(); 36 crypto::EnsureOpenSSLInit();
35 37
36 // Allocate a new error library value for inserting net errors into 38 // Allocate a new error library value for inserting net errors into
37 // OpenSSL. This does not register any ERR_STRING_DATA for the errors, so 39 // OpenSSL. This does not register any ERR_STRING_DATA for the errors, so
38 // stringifying error codes through OpenSSL will return NULL. 40 // stringifying error codes through OpenSSL will return NULL.
39 net_error_lib_ = ERR_get_next_error_library(); 41 net_error_lib_ = ERR_get_next_error_library();
40 } 42 }
41 43
42 int net_error_lib() const { return net_error_lib_; } 44 unsigned net_error_lib() const { return net_error_lib_; }
43 45
44 private: 46 private:
45 int net_error_lib_; 47 unsigned net_error_lib_;
46 }; 48 };
47 49
48 base::LazyInstance<OpenSSLNetErrorLibSingleton>::Leaky g_openssl_net_error_lib = 50 base::LazyInstance<OpenSSLNetErrorLibSingleton>::Leaky g_openssl_net_error_lib =
49 LAZY_INSTANCE_INITIALIZER; 51 LAZY_INSTANCE_INITIALIZER;
50 52
51 int OpenSSLNetErrorLib() { 53 unsigned OpenSSLNetErrorLib() {
52 return g_openssl_net_error_lib.Get().net_error_lib(); 54 return g_openssl_net_error_lib.Get().net_error_lib();
53 } 55 }
54 56
55 int MapOpenSSLErrorSSL(unsigned long error_code) { 57 int MapOpenSSLErrorSSL(unsigned long error_code) {
56 DCHECK_EQ(ERR_LIB_SSL, ERR_GET_LIB(error_code)); 58 DCHECK_EQ(ERR_LIB_SSL, ERR_GET_LIB(error_code));
57 59
58 DVLOG(1) << "OpenSSL SSL error, reason: " << ERR_GET_REASON(error_code) 60 DVLOG(1) << "OpenSSL SSL error, reason: " << ERR_GET_REASON(error_code)
59 << ", name: " << ERR_error_string(error_code, NULL); 61 << ", name: " << ERR_error_string(error_code, NULL);
60 switch (ERR_GET_REASON(error_code)) { 62 switch (ERR_GET_REASON(error_code)) {
61 case SSL_R_READ_TIMEOUT_EXPIRED: 63 case SSL_R_READ_TIMEOUT_EXPIRED:
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } // namespace 157 } // namespace
156 158
157 void OpenSSLPutNetError(const tracked_objects::Location& location, int err) { 159 void OpenSSLPutNetError(const tracked_objects::Location& location, int err) {
158 // Net error codes are negative. Encode them as positive numbers. 160 // Net error codes are negative. Encode them as positive numbers.
159 err = -err; 161 err = -err;
160 if (err < 0 || err > 0xfff) { 162 if (err < 0 || err > 0xfff) {
161 // OpenSSL reserves 12 bits for the reason code. 163 // OpenSSL reserves 12 bits for the reason code.
162 NOTREACHED(); 164 NOTREACHED();
163 err = ERR_INVALID_ARGUMENT; 165 err = ERR_INVALID_ARGUMENT;
164 } 166 }
165 ERR_PUT_error(OpenSSLNetErrorLib(), 0, err, 167 ERR_put_error(OpenSSLNetErrorLib(), 0, err,
166 location.file_name(), location.line_number()); 168 location.file_name(), location.line_number());
167 } 169 }
168 170
169 int MapOpenSSLError(int err, const crypto::OpenSSLErrStackTracer& tracer) { 171 int MapOpenSSLError(int err, const crypto::OpenSSLErrStackTracer& tracer) {
170 switch (err) { 172 switch (err) {
171 case SSL_ERROR_WANT_READ: 173 case SSL_ERROR_WANT_READ:
172 case SSL_ERROR_WANT_WRITE: 174 case SSL_ERROR_WANT_WRITE:
173 return ERR_IO_PENDING; 175 return ERR_IO_PENDING;
174 case SSL_ERROR_SYSCALL: 176 case SSL_ERROR_SYSCALL:
175 LOG(ERROR) << "OpenSSL SYSCALL error, earliest error code in " 177 LOG(ERROR) << "OpenSSL SYSCALL error, earliest error code in "
(...skipping 15 matching lines...) Expand all
191 } while (error_code != 0); 193 } while (error_code != 0);
192 return ERR_SSL_PROTOCOL_ERROR; 194 return ERR_SSL_PROTOCOL_ERROR;
193 default: 195 default:
194 // TODO(joth): Implement full mapping. 196 // TODO(joth): Implement full mapping.
195 LOG(WARNING) << "Unknown OpenSSL error " << err; 197 LOG(WARNING) << "Unknown OpenSSL error " << err;
196 return ERR_SSL_PROTOCOL_ERROR; 198 return ERR_SSL_PROTOCOL_ERROR;
197 } 199 }
198 } 200 }
199 201
200 } // namespace net 202 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/aead_base_encrypter_openssl.cc ('k') | net/socket/ssl_client_socket_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698