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

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

Issue 173853014: Make OpenSSL UpdateServerCert() OS independent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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 // OpenSSL binding for SSLClientSocket. The class layout and general principle 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle
6 // of operation is derived from SSLClientSocketNSS. 6 // of operation is derived from SSLClientSocketNSS.
7 7
8 #include "net/socket/ssl_client_socket_openssl.h" 8 #include "net/socket/ssl_client_socket_openssl.h"
9 9
10 #include <openssl/err.h> 10 #include <openssl/err.h>
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 void SSLClientSocketOpenSSL::DoConnectCallback(int rv) { 911 void SSLClientSocketOpenSSL::DoConnectCallback(int rv) {
912 if (!user_connect_callback_.is_null()) { 912 if (!user_connect_callback_.is_null()) {
913 CompletionCallback c = user_connect_callback_; 913 CompletionCallback c = user_connect_callback_;
914 user_connect_callback_.Reset(); 914 user_connect_callback_.Reset();
915 c.Run(rv > OK ? OK : rv); 915 c.Run(rv > OK ? OK : rv);
916 } 916 }
917 } 917 }
918 918
919 X509Certificate* SSLClientSocketOpenSSL::UpdateServerCert() { 919 X509Certificate* SSLClientSocketOpenSSL::UpdateServerCert() {
920 if (server_cert_.get()) 920 if (server_cert_.get())
921 return server_cert_.get(); 921 return server_cert_.get();
Ryan Sleevi 2014/02/21 22:34:38 So, this is wrong :) Compare with the NSS impleme
haavardm 2014/02/24 18:54:31 Ah, ok. I tried to do this fix without changing th
Ryan Sleevi 2014/02/24 19:02:47 Yeah, but we can fix this while we're having to (s
922 922
923 crypto::ScopedOpenSSL<X509, X509_free> cert(SSL_get_peer_certificate(ssl_)); 923 crypto::ScopedOpenSSL<X509, X509_free> cert(SSL_get_peer_certificate(ssl_));
haavardm 2014/02/25 16:13:01 Is this needed? I suddenly realized that cert.get(
924 if (!cert.get()) { 924 if (!cert.get()) {
925 LOG(WARNING) << "SSL_get_peer_certificate returned NULL"; 925 LOG(WARNING) << "SSL_get_peer_certificate returned NULL";
926 return NULL; 926 return NULL;
927 } 927 }
928 928
929 #if defined(USE_OPENSSL)
929 // Unlike SSL_get_peer_certificate, SSL_get_peer_cert_chain does not 930 // Unlike SSL_get_peer_certificate, SSL_get_peer_cert_chain does not
930 // increment the reference so sk_X509_free does not need to be called. 931 // increment the reference so sk_X509_free does not need to be called.
931 STACK_OF(X509)* chain = SSL_get_peer_cert_chain(ssl_); 932 STACK_OF(X509)* chain = SSL_get_peer_cert_chain(ssl_);
932 X509Certificate::OSCertHandles intermediates; 933 X509Certificate::OSCertHandles intermediates;
933 if (chain) { 934 if (chain) {
934 for (int i = 0; i < sk_X509_num(chain); ++i) 935 for (int i = 0; i < sk_X509_num(chain); ++i)
935 intermediates.push_back(sk_X509_value(chain, i)); 936 intermediates.push_back(sk_X509_value(chain, i));
936 } 937 }
937 server_cert_ = X509Certificate::CreateFromHandle(cert.get(), intermediates); 938 server_cert_ = X509Certificate::CreateFromHandle(cert.get(), intermediates);
939 #else
940 unsigned char* cert_data = NULL;
941 int cert_data_length = i2d_X509(cert.get(), &cert_data);
942 if (cert_data_length <= 0 || !cert_data) {
943 return NULL;
944 }
Ryan Sleevi 2014/02/21 22:34:38 net/ style: Don't include braces on single-line co
haavardm 2014/03/11 18:43:20 Done.
945 std::vector<std::string> cert_chain;
946 cert_chain.push_back(
947 std::string(reinterpret_cast<char*>(cert_data), cert_data_length));
948 OPENSSL_free(cert_data);
Ryan Sleevi 2014/02/21 22:34:38 Rather than copying all of these to strings, then
haavardm 2014/02/24 18:54:31 Right. Just to clear up one detail: I assume you m
Ryan Sleevi 2014/02/24 19:02:47 I'm not sure I grokked your clarification. What I
haavardm 2014/02/24 20:47:00 That's how I understood it yes.
haavardm 2014/03/11 18:43:20 Done.
949
950 STACK_OF(X509)* chain = SSL_get_peer_cert_chain(ssl_);
951 if (chain) {
952 for (int i = 0; i < sk_X509_num(chain); ++i) {
953 cert_data = NULL;
954 cert_data_length = i2d_X509(sk_X509_value(chain, i), &cert_data);
955 if (cert_data_length <= 0 || !cert_data) {
956 return NULL;
957 }
958 cert_chain.push_back(
959 std::string(reinterpret_cast<char*>(cert_data), cert_data_length));
wtc 2014/02/25 01:13:09 If you directly push a base::StringPiece to chain_
haavardm 2014/02/25 16:13:01 For that to work one must actually using C-type ca
haavardm 2014/03/11 18:43:20 Done.
960 OPENSSL_free(cert_data);
961 }
962 }
963
964 std::vector<base::StringPiece> chain_ref;
965 for (size_t i = 0; i < cert_chain.size();i++) {
966 chain_ref.push_back(base::StringPiece(cert_chain[0]));
haavardm 2014/02/24 18:54:31 Ouch, bad typo right there (cert_chain[0]). Will f
Ryan Sleevi 2014/02/24 19:02:47 No. There's no test that covers this. The CertVeri
haavardm 2014/03/11 18:43:20 Done.
967 }
968 server_cert_ = X509Certificate::CreateFromDERCertChain(chain_ref);
969 #endif // USE_OPENSSL
970
938 DCHECK(server_cert_.get()); 971 DCHECK(server_cert_.get());
Ryan Sleevi 2014/02/21 22:34:38 This DCHECK is going to have to go when adding !Op
haavardm 2014/02/24 18:54:31 Ok. I'll move it into the USE_OPENSSL code.
Ryan Sleevi 2014/02/24 19:02:47 I was saying to remove it entirely.
haavardm 2014/03/11 18:43:20 Done.
939
940 return server_cert_.get(); 972 return server_cert_.get();
941 } 973 }
942 974
943 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { 975 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) {
944 int rv = DoHandshakeLoop(result); 976 int rv = DoHandshakeLoop(result);
945 if (rv != ERR_IO_PENDING) { 977 if (rv != ERR_IO_PENDING) {
946 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); 978 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv);
947 DoConnectCallback(rv); 979 DoConnectCallback(rv);
948 } 980 }
949 } 981 }
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 } 1450 }
1419 1451
1420 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen); 1452 npn_proto_.assign(reinterpret_cast<const char*>(*out), *outlen);
1421 server_protos_.assign(reinterpret_cast<const char*>(in), inlen); 1453 server_protos_.assign(reinterpret_cast<const char*>(in), inlen);
1422 DVLOG(2) << "next protocol: '" << npn_proto_ << "' status: " << npn_status_; 1454 DVLOG(2) << "next protocol: '" << npn_proto_ << "' status: " << npn_status_;
1423 #endif 1455 #endif
1424 return SSL_TLSEXT_ERR_OK; 1456 return SSL_TLSEXT_ERR_OK;
1425 } 1457 }
1426 1458
1427 } // namespace net 1459 } // namespace net
OLDNEW
« net/cert/x509_certificate_mac.cc ('K') | « net/cert/x509_certificate_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698