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

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

Issue 2694903006: Restore SSL_SESSION/X509Certificate X509* sharing (Closed)
Patch Set: . Created 3 years, 10 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
« net/cert/x509_util_openssl.cc ('K') | « net/cert/x509_util_openssl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ssl_client_socket_impl.h" 5 #include "net/socket/ssl_client_socket_impl.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 openssl_chain_.reset(X509_chain_up_ref(other.openssl_chain_.get())); 470 openssl_chain_.reset(X509_chain_up_ref(other.openssl_chain_.get()));
471 return *this; 471 return *this;
472 } 472 }
473 473
474 void SSLClientSocketImpl::PeerCertificateChain::Reset(STACK_OF(X509) * chain) { 474 void SSLClientSocketImpl::PeerCertificateChain::Reset(STACK_OF(X509) * chain) {
475 openssl_chain_.reset(chain ? X509_chain_up_ref(chain) : NULL); 475 openssl_chain_.reset(chain ? X509_chain_up_ref(chain) : NULL);
476 } 476 }
477 477
478 scoped_refptr<X509Certificate> 478 scoped_refptr<X509Certificate>
479 SSLClientSocketImpl::PeerCertificateChain::AsOSChain() const { 479 SSLClientSocketImpl::PeerCertificateChain::AsOSChain() const {
480 // DER-encode the chain and convert to a platform certificate handle. 480 #if defined(USE_OPENSSL_CERTS)
481 std::vector<std::string> chain; 481 // When OSCertHandle is typedef'ed to X509, this implementation does a short
482 chain.reserve(sk_X509_num(openssl_chain_.get())); 482 // cut to avoid converting back and forth between DER and the X509 struct.
483 X509Certificate::OSCertHandles intermediates;
484 for (size_t i = 1; i < sk_X509_num(openssl_chain_.get()); ++i) {
485 X509* cert = sk_X509_value(openssl_chain_.get(), i);
486 DCHECK(cert->buf);
487 intermediates.push_back(cert);
488 }
489
490 X509* leaf = sk_X509_value(openssl_chain_.get(), 0);
491 DCHECK(leaf->buf);
492 return X509Certificate::CreateFromHandle(leaf, intermediates);
493 #else
494 // Convert the certificate chains to a platform certificate handle.
495 std::vector<base::StringPiece> der_chain;
496 der_chain.reserve(sk_X509_num(openssl_chain_.get()));
483 for (size_t i = 0; i < sk_X509_num(openssl_chain_.get()); ++i) { 497 for (size_t i = 0; i < sk_X509_num(openssl_chain_.get()); ++i) {
484 X509* x = sk_X509_value(openssl_chain_.get(), i); 498 X509* cert = sk_X509_value(openssl_chain_.get(), i);
485 // Note: This intentionally avoids using x509_util::GetDER(), which may 499 DCHECK(cert->buf);
486 // cache the encoded DER on |x|, as |x| is shared with the underlying 500 base::StringPiece der;
487 // socket (SSL*) this chain belongs to. As the DER will only be used 501 if (!x509_util::GetDER(cert, &der))
488 // once in //net, within this code, this avoids needlessly caching
489 // additional data. See https://crbug.com/642082
490 int len = i2d_X509(x, nullptr);
491 if (len < 0)
492 return nullptr; 502 return nullptr;
493 std::string cert; 503 der_chain.push_back(der);
494 uint8_t* ptr = reinterpret_cast<uint8_t*>(base::WriteInto(&cert, len + 1));
495 len = i2d_X509(x, &ptr);
496 if (len < 0) {
497 NOTREACHED();
498 return nullptr;
499 }
500 chain.push_back(std::move(cert));
501 } 504 }
502 std::vector<base::StringPiece> stringpiece_chain; 505 return X509Certificate::CreateFromDERCertChain(der_chain);
503 for (const auto& cert : chain) 506 #endif
504 stringpiece_chain.push_back(cert);
505
506 return X509Certificate::CreateFromDERCertChain(stringpiece_chain);
507 } 507 }
508 508
509 // static 509 // static
510 void SSLClientSocket::ClearSessionCache() { 510 void SSLClientSocket::ClearSessionCache() {
511 SSLClientSocketImpl::SSLContext* context = 511 SSLClientSocketImpl::SSLContext* context =
512 SSLClientSocketImpl::SSLContext::GetInstance(); 512 SSLClientSocketImpl::SSLContext::GetInstance();
513 context->session_cache()->Flush(); 513 context->session_cache()->Flush();
514 } 514 }
515 515
516 SSLClientSocketImpl::SSLClientSocketImpl( 516 SSLClientSocketImpl::SSLClientSocketImpl(
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && 2040 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED &&
2041 !certificate_requested_) { 2041 !certificate_requested_) {
2042 net_error = ERR_SSL_PROTOCOL_ERROR; 2042 net_error = ERR_SSL_PROTOCOL_ERROR;
2043 } 2043 }
2044 } 2044 }
2045 2045
2046 return net_error; 2046 return net_error;
2047 } 2047 }
2048 2048
2049 } // namespace net 2049 } // namespace net
OLDNEW
« net/cert/x509_util_openssl.cc ('K') | « net/cert/x509_util_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698