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

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

Issue 274783002: Implement SSL server socket over OpenSSL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary comment. Created 6 years, 7 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 #include "net/socket/ssl_server_socket_nss.h" 5 #include "net/socket/ssl_server_socket_nss.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <winsock2.h> 8 #include <winsock2.h>
9 #endif 9 #endif
10 10
(...skipping 11 matching lines...) Expand all
22 #include <nss.h> 22 #include <nss.h>
23 #include <pk11pub.h> 23 #include <pk11pub.h>
24 #include <secerr.h> 24 #include <secerr.h>
25 #include <sechash.h> 25 #include <sechash.h>
26 #include <ssl.h> 26 #include <ssl.h>
27 #include <sslerr.h> 27 #include <sslerr.h>
28 #include <sslproto.h> 28 #include <sslproto.h>
29 29
30 #include <limits> 30 #include <limits>
31 31
32 #include "base/callback_helpers.h"
32 #include "base/lazy_instance.h" 33 #include "base/lazy_instance.h"
33 #include "base/memory/ref_counted.h" 34 #include "base/memory/ref_counted.h"
34 #include "crypto/rsa_private_key.h" 35 #include "crypto/rsa_private_key.h"
35 #include "crypto/nss_util_internal.h" 36 #include "crypto/nss_util_internal.h"
36 #include "net/base/io_buffer.h" 37 #include "net/base/io_buffer.h"
37 #include "net/base/net_errors.h" 38 #include "net/base/net_errors.h"
38 #include "net/base/net_log.h" 39 #include "net/base/net_log.h"
39 #include "net/socket/nss_ssl_util.h" 40 #include "net/socket/nss_ssl_util.h"
40 #include "net/socket/ssl_error_params.h" 41 #include "net/socket/ssl_error_params.h"
41 42
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 241
241 int SSLServerSocketNSS::SetReceiveBufferSize(int32 size) { 242 int SSLServerSocketNSS::SetReceiveBufferSize(int32 size) {
242 return transport_socket_->SetReceiveBufferSize(size); 243 return transport_socket_->SetReceiveBufferSize(size);
243 } 244 }
244 245
245 int SSLServerSocketNSS::SetSendBufferSize(int32 size) { 246 int SSLServerSocketNSS::SetSendBufferSize(int32 size) {
246 return transport_socket_->SetSendBufferSize(size); 247 return transport_socket_->SetSendBufferSize(size);
247 } 248 }
248 249
249 bool SSLServerSocketNSS::IsConnected() const { 250 bool SSLServerSocketNSS::IsConnected() const {
251 // TODO(wtc): Check transport_socket_->IsConnected() as well.
wtc 2014/05/16 19:36:14 This comment should say: find out if we should che
byungchul 2014/05/16 19:50:32 Done.
250 return completed_handshake_; 252 return completed_handshake_;
251 } 253 }
252 254
253 void SSLServerSocketNSS::Disconnect() { 255 void SSLServerSocketNSS::Disconnect() {
254 transport_socket_->Disconnect(); 256 transport_socket_->Disconnect();
255 } 257 }
256 258
257 bool SSLServerSocketNSS::IsConnectedAndIdle() const { 259 bool SSLServerSocketNSS::IsConnectedAndIdle() const {
258 return completed_handshake_ && transport_socket_->IsConnectedAndIdle(); 260 return completed_handshake_ && transport_socket_->IsConnectedAndIdle();
259 } 261 }
(...skipping 24 matching lines...) Expand all
284 286
285 bool SSLServerSocketNSS::WasEverUsed() const { 287 bool SSLServerSocketNSS::WasEverUsed() const {
286 return transport_socket_->WasEverUsed(); 288 return transport_socket_->WasEverUsed();
287 } 289 }
288 290
289 bool SSLServerSocketNSS::UsingTCPFastOpen() const { 291 bool SSLServerSocketNSS::UsingTCPFastOpen() const {
290 return transport_socket_->UsingTCPFastOpen(); 292 return transport_socket_->UsingTCPFastOpen();
291 } 293 }
292 294
293 bool SSLServerSocketNSS::WasNpnNegotiated() const { 295 bool SSLServerSocketNSS::WasNpnNegotiated() const {
296 NOTIMPLEMENTED();
294 return false; 297 return false;
295 } 298 }
296 299
297 NextProto SSLServerSocketNSS::GetNegotiatedProtocol() const { 300 NextProto SSLServerSocketNSS::GetNegotiatedProtocol() const {
298 // NPN is not supported by this class. 301 // NPN is not supported by this class.
299 return kProtoUnknown; 302 return kProtoUnknown;
300 } 303 }
301 304
302 bool SSLServerSocketNSS::GetSSLInfo(SSLInfo* ssl_info) { 305 bool SSLServerSocketNSS::GetSSLInfo(SSLInfo* ssl_info) {
303 NOTIMPLEMENTED(); 306 NOTIMPLEMENTED();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return OK; 493 return OK;
491 } 494 }
492 495
493 void SSLServerSocketNSS::OnSendComplete(int result) { 496 void SSLServerSocketNSS::OnSendComplete(int result) {
494 if (next_handshake_state_ == STATE_HANDSHAKE) { 497 if (next_handshake_state_ == STATE_HANDSHAKE) {
495 // In handshake phase. 498 // In handshake phase.
496 OnHandshakeIOComplete(result); 499 OnHandshakeIOComplete(result);
497 return; 500 return;
498 } 501 }
499 502
503 // TODO(byungchul): This state machine is not correct. Copy the state machine
504 // of SSLClientSocketNSS::OnSendComplete() which handles it better.
500 if (!completed_handshake_) 505 if (!completed_handshake_)
501 return; 506 return;
502 507
503 if (user_write_buf_.get()) { 508 if (user_write_buf_.get()) {
504 int rv = DoWriteLoop(result); 509 int rv = DoWriteLoop(result);
505 if (rv != ERR_IO_PENDING) 510 if (rv != ERR_IO_PENDING)
506 DoWriteCallback(rv); 511 DoWriteCallback(rv);
507 } else { 512 } else {
508 // Ensure that any queued ciphertext is flushed. 513 // Ensure that any queued ciphertext is flushed.
509 DoTransportIO(); 514 DoTransportIO();
(...skipping 12 matching lines...) Expand all
522 if (!user_read_buf_.get() || !completed_handshake_) 527 if (!user_read_buf_.get() || !completed_handshake_)
523 return; 528 return;
524 529
525 int rv = DoReadLoop(result); 530 int rv = DoReadLoop(result);
526 if (rv != ERR_IO_PENDING) 531 if (rv != ERR_IO_PENDING)
527 DoReadCallback(rv); 532 DoReadCallback(rv);
528 } 533 }
529 534
530 void SSLServerSocketNSS::OnHandshakeIOComplete(int result) { 535 void SSLServerSocketNSS::OnHandshakeIOComplete(int result) {
531 int rv = DoHandshakeLoop(result); 536 int rv = DoHandshakeLoop(result);
532 if (rv != ERR_IO_PENDING) { 537 if (rv == ERR_IO_PENDING)
533 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_SERVER_HANDSHAKE, rv); 538 return;
534 if (!user_handshake_callback_.is_null()) 539
535 DoHandshakeCallback(rv); 540 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_SERVER_HANDSHAKE, rv);
536 } 541 if (!user_handshake_callback_.is_null())
542 DoHandshakeCallback(rv);
537 } 543 }
538 544
539 // Return 0 for EOF, 545 // Return 0 for EOF,
540 // > 0 for bytes transferred immediately, 546 // > 0 for bytes transferred immediately,
541 // < 0 for error (or the non-error ERR_IO_PENDING). 547 // < 0 for error (or the non-error ERR_IO_PENDING).
542 int SSLServerSocketNSS::BufferSend(void) { 548 int SSLServerSocketNSS::BufferSend(void) {
543 if (transport_send_busy_) 549 if (transport_send_busy_)
544 return ERR_IO_PENDING; 550 return ERR_IO_PENDING;
545 551
546 const char* buf1; 552 const char* buf1;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 int rv; 724 int rv;
719 do { 725 do {
720 rv = DoPayloadRead(); 726 rv = DoPayloadRead();
721 network_moved = DoTransportIO(); 727 network_moved = DoTransportIO();
722 } while (rv == ERR_IO_PENDING && network_moved); 728 } while (rv == ERR_IO_PENDING && network_moved);
723 return rv; 729 return rv;
724 } 730 }
725 731
726 int SSLServerSocketNSS::DoWriteLoop(int result) { 732 int SSLServerSocketNSS::DoWriteLoop(int result) {
727 DCHECK(completed_handshake_); 733 DCHECK(completed_handshake_);
728 DCHECK(next_handshake_state_ == STATE_NONE); 734 DCHECK_EQ(next_handshake_state_, STATE_NONE);
729 735
730 if (result < 0) 736 if (result < 0)
731 return result; 737 return result;
732 738
733 if (!nss_bufs_) { 739 if (!nss_bufs_) {
734 LOG(DFATAL) << "!nss_bufs_"; 740 LOG(DFATAL) << "!nss_bufs_";
735 int rv = ERR_UNEXPECTED; 741 int rv = ERR_UNEXPECTED;
736 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR, 742 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR,
737 CreateNetLogSSLErrorCallback(rv, 0)); 743 CreateNetLogSSLErrorCallback(rv, 0));
738 return rv; 744 return rv;
(...skipping 26 matching lines...) Expand all
765 << ", net_error " << net_error; 771 << ", net_error " << net_error;
766 net_log_.AddEvent(NetLog::TYPE_SSL_HANDSHAKE_ERROR, 772 net_log_.AddEvent(NetLog::TYPE_SSL_HANDSHAKE_ERROR,
767 CreateNetLogSSLErrorCallback(net_error, prerr)); 773 CreateNetLogSSLErrorCallback(net_error, prerr));
768 } 774 }
769 } 775 }
770 return net_error; 776 return net_error;
771 } 777 }
772 778
773 void SSLServerSocketNSS::DoHandshakeCallback(int rv) { 779 void SSLServerSocketNSS::DoHandshakeCallback(int rv) {
774 DCHECK_NE(rv, ERR_IO_PENDING); 780 DCHECK_NE(rv, ERR_IO_PENDING);
775 781 ResetAndReturn(&user_handshake_callback_).Run(rv > OK ? OK : rv);
776 CompletionCallback c = user_handshake_callback_;
777 user_handshake_callback_.Reset();
778 c.Run(rv > OK ? OK : rv);
779 } 782 }
780 783
781 void SSLServerSocketNSS::DoReadCallback(int rv) { 784 void SSLServerSocketNSS::DoReadCallback(int rv) {
782 DCHECK(rv != ERR_IO_PENDING); 785 DCHECK(rv != ERR_IO_PENDING);
783 DCHECK(!user_read_callback_.is_null()); 786 DCHECK(!user_read_callback_.is_null());
784 787
785 // Since Run may result in Read being called, clear |user_read_callback_|
786 // up front.
787 CompletionCallback c = user_read_callback_;
788 user_read_callback_.Reset();
789 user_read_buf_ = NULL; 788 user_read_buf_ = NULL;
790 user_read_buf_len_ = 0; 789 user_read_buf_len_ = 0;
791 c.Run(rv); 790 ResetAndReturn(&user_read_callback_).Run(rv);
792 } 791 }
793 792
794 void SSLServerSocketNSS::DoWriteCallback(int rv) { 793 void SSLServerSocketNSS::DoWriteCallback(int rv) {
795 DCHECK(rv != ERR_IO_PENDING); 794 DCHECK(rv != ERR_IO_PENDING);
796 DCHECK(!user_write_callback_.is_null()); 795 DCHECK(!user_write_callback_.is_null());
797 796
798 // Since Run may result in Write being called, clear |user_write_callback_|
799 // up front.
800 CompletionCallback c = user_write_callback_;
801 user_write_callback_.Reset();
802 user_write_buf_ = NULL; 797 user_write_buf_ = NULL;
803 user_write_buf_len_ = 0; 798 user_write_buf_len_ = 0;
804 c.Run(rv); 799 ResetAndReturn(&user_write_callback_).Run(rv);
805 } 800 }
806 801
807 // static 802 // static
808 // NSS calls this if an incoming certificate needs to be verified. 803 // NSS calls this if an incoming certificate needs to be verified.
809 // Do nothing but return SECSuccess. 804 // Do nothing but return SECSuccess.
810 // This is called only in full handshake mode. 805 // This is called only in full handshake mode.
811 // Peer certificate is retrieved in HandshakeCallback() later, which is called 806 // Peer certificate is retrieved in HandshakeCallback() later, which is called
812 // in full handshake mode or in resumption handshake mode. 807 // in full handshake mode or in resumption handshake mode.
813 SECStatus SSLServerSocketNSS::OwnAuthCertHandler(void* arg, 808 SECStatus SSLServerSocketNSS::OwnAuthCertHandler(void* arg,
814 PRFileDesc* socket, 809 PRFileDesc* socket,
(...skipping 17 matching lines...) Expand all
832 // initializes the NSS base library. 827 // initializes the NSS base library.
833 EnsureNSSSSLInit(); 828 EnsureNSSSSLInit();
834 if (!NSS_IsInitialized()) 829 if (!NSS_IsInitialized())
835 return ERR_UNEXPECTED; 830 return ERR_UNEXPECTED;
836 831
837 EnableSSLServerSockets(); 832 EnableSSLServerSockets();
838 return OK; 833 return OK;
839 } 834 }
840 835
841 } // namespace net 836 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698