| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 GetDefaultCertNickname(), derived from | 5 // This file includes code GetDefaultCertNickname(), derived from |
| 6 // nsNSSCertificate::defaultServerNickName() | 6 // nsNSSCertificate::defaultServerNickName() |
| 7 // in mozilla/security/manager/ssl/src/nsNSSCertificate.cpp | 7 // in mozilla/security/manager/ssl/src/nsNSSCertificate.cpp |
| 8 // and SSLClientSocketNSS::DoVerifyCertComplete() derived from | 8 // and SSLClientSocketNSS::DoVerifyCertComplete() derived from |
| 9 // AuthCertificateCallback() in | 9 // AuthCertificateCallback() in |
| 10 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. | 10 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 143 } |
| 144 PR_FREEIF(name); | 144 PR_FREEIF(name); |
| 145 return nickname; | 145 return nickname; |
| 146 } | 146 } |
| 147 | 147 |
| 148 int NetErrorFromNSPRError(PRErrorCode err) { | 148 int NetErrorFromNSPRError(PRErrorCode err) { |
| 149 // TODO(port): fill this out as we learn what's important | 149 // TODO(port): fill this out as we learn what's important |
| 150 switch (err) { | 150 switch (err) { |
| 151 case PR_WOULD_BLOCK_ERROR: | 151 case PR_WOULD_BLOCK_ERROR: |
| 152 return ERR_IO_PENDING; | 152 return ERR_IO_PENDING; |
| 153 case PR_ADDRESS_NOT_SUPPORTED_ERROR: // For connect. |
| 154 case PR_NO_ACCESS_RIGHTS_ERROR: |
| 155 return ERR_ACCESS_DENIED; |
| 156 case PR_IO_TIMEOUT_ERROR: |
| 157 return ERR_TIMED_OUT; |
| 158 case PR_CONNECT_RESET_ERROR: |
| 159 return ERR_CONNECTION_RESET; |
| 160 case PR_CONNECT_ABORTED_ERROR: |
| 161 return ERR_CONNECTION_ABORTED; |
| 162 case PR_CONNECT_REFUSED_ERROR: |
| 163 return ERR_CONNECTION_REFUSED; |
| 164 case PR_HOST_UNREACHABLE_ERROR: |
| 165 case PR_NETWORK_UNREACHABLE_ERROR: |
| 166 return ERR_ADDRESS_UNREACHABLE; |
| 167 case PR_ADDRESS_NOT_AVAILABLE_ERROR: |
| 168 return ERR_ADDRESS_INVALID; |
| 169 |
| 153 case SSL_ERROR_NO_CYPHER_OVERLAP: | 170 case SSL_ERROR_NO_CYPHER_OVERLAP: |
| 154 return ERR_SSL_VERSION_OR_CIPHER_MISMATCH; | 171 return ERR_SSL_VERSION_OR_CIPHER_MISMATCH; |
| 155 case SSL_ERROR_BAD_CERT_DOMAIN: | 172 case SSL_ERROR_BAD_CERT_DOMAIN: |
| 156 return ERR_CERT_COMMON_NAME_INVALID; | 173 return ERR_CERT_COMMON_NAME_INVALID; |
| 157 case SEC_ERROR_EXPIRED_CERTIFICATE: | 174 case SEC_ERROR_EXPIRED_CERTIFICATE: |
| 158 return ERR_CERT_DATE_INVALID; | 175 return ERR_CERT_DATE_INVALID; |
| 159 case SEC_ERROR_BAD_SIGNATURE: | 176 case SEC_ERROR_BAD_SIGNATURE: |
| 160 return ERR_CERT_INVALID; | 177 return ERR_CERT_INVALID; |
| 161 case SSL_ERROR_REVOKED_CERT_ALERT: | 178 case SSL_ERROR_REVOKED_CERT_ALERT: |
| 162 case SEC_ERROR_REVOKED_CERTIFICATE: | 179 case SEC_ERROR_REVOKED_CERTIFICATE: |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 LeaveFunction(""); | 666 LeaveFunction(""); |
| 650 return; | 667 return; |
| 651 } | 668 } |
| 652 | 669 |
| 653 int rv = DoReadLoop(result); | 670 int rv = DoReadLoop(result); |
| 654 if (rv != ERR_IO_PENDING) | 671 if (rv != ERR_IO_PENDING) |
| 655 DoReadCallback(rv); | 672 DoReadCallback(rv); |
| 656 LeaveFunction(""); | 673 LeaveFunction(""); |
| 657 } | 674 } |
| 658 | 675 |
| 659 // Map a Chromium net error code to an NSS error code | 676 // Map a Chromium net error code to an NSS error code. |
| 660 // See _MD_unix_map_default_error in the NSS source | 677 // See _MD_unix_map_default_error in the NSS source |
| 661 // tree for inspiration. | 678 // tree for inspiration. |
| 662 static PRErrorCode MapErrorToNSS(int result) { | 679 static PRErrorCode MapErrorToNSS(int result) { |
| 663 if (result >=0) | 680 if (result >=0) |
| 664 return result; | 681 return result; |
| 665 // TODO(port): add real table | 682 |
| 666 LOG(ERROR) << "MapErrorToNSS " << result; | 683 switch (result) { |
| 667 return PR_UNKNOWN_ERROR; | 684 case ERR_IO_PENDING: |
| 685 return PR_WOULD_BLOCK_ERROR; |
| 686 case ERR_ACCESS_DENIED: |
| 687 // For connect, this could be mapped to PR_ADDRESS_NOT_SUPPORTED_ERROR. |
| 688 return PR_NO_ACCESS_RIGHTS_ERROR; |
| 689 case ERR_INTERNET_DISCONNECTED: // Equivalent to ENETDOWN. |
| 690 return PR_NETWORK_UNREACHABLE_ERROR; // Best approximation. |
| 691 case ERR_CONNECTION_TIMED_OUT: |
| 692 case ERR_TIMED_OUT: |
| 693 return PR_IO_TIMEOUT_ERROR; |
| 694 case ERR_CONNECTION_RESET: |
| 695 return PR_CONNECT_RESET_ERROR; |
| 696 case ERR_CONNECTION_ABORTED: |
| 697 return PR_CONNECT_ABORTED_ERROR; |
| 698 case ERR_CONNECTION_REFUSED: |
| 699 return PR_CONNECT_REFUSED_ERROR; |
| 700 case ERR_ADDRESS_UNREACHABLE: |
| 701 return PR_HOST_UNREACHABLE_ERROR; // Also PR_NETWORK_UNREACHABLE_ERROR. |
| 702 case ERR_ADDRESS_INVALID: |
| 703 return PR_ADDRESS_NOT_AVAILABLE_ERROR; |
| 704 default: |
| 705 LOG(WARNING) << "MapErrorToNSS " << result |
| 706 << " mapped to PR_UNKNOWN_ERROR"; |
| 707 return PR_UNKNOWN_ERROR; |
| 708 } |
| 668 } | 709 } |
| 669 | 710 |
| 670 // Do network I/O between the given buffer and the given socket. | 711 // Do network I/O between the given buffer and the given socket. |
| 671 // Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING) | 712 // Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING) |
| 672 bool SSLClientSocketNSS::DoTransportIO() { | 713 bool SSLClientSocketNSS::DoTransportIO() { |
| 673 EnterFunction(""); | 714 EnterFunction(""); |
| 674 bool network_moved = false; | 715 bool network_moved = false; |
| 675 if (nss_bufs_ != NULL) { | 716 if (nss_bufs_ != NULL) { |
| 676 int nsent = BufferSend(); | 717 int nsent = BufferSend(); |
| 677 int nreceived = BufferRecv(); | 718 int nreceived = BufferRecv(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 703 else | 744 else |
| 704 memio_PutWriteResult(nss_bufs_, MapErrorToNSS(rv)); | 745 memio_PutWriteResult(nss_bufs_, MapErrorToNSS(rv)); |
| 705 } | 746 } |
| 706 | 747 |
| 707 LeaveFunction(rv); | 748 LeaveFunction(rv); |
| 708 return rv; | 749 return rv; |
| 709 } | 750 } |
| 710 | 751 |
| 711 void SSLClientSocketNSS::BufferSendComplete(int result) { | 752 void SSLClientSocketNSS::BufferSendComplete(int result) { |
| 712 EnterFunction(result); | 753 EnterFunction(result); |
| 713 memio_PutWriteResult(nss_bufs_, result); | 754 memio_PutWriteResult(nss_bufs_, MapErrorToNSS(result)); |
| 714 transport_send_busy_ = false; | 755 transport_send_busy_ = false; |
| 715 OnSendComplete(result); | 756 OnSendComplete(result); |
| 716 LeaveFunction(""); | 757 LeaveFunction(""); |
| 717 } | 758 } |
| 718 | 759 |
| 719 | 760 |
| 720 int SSLClientSocketNSS::BufferRecv(void) { | 761 int SSLClientSocketNSS::BufferRecv(void) { |
| 721 if (transport_recv_busy_) return ERR_IO_PENDING; | 762 if (transport_recv_busy_) return ERR_IO_PENDING; |
| 722 | 763 |
| 723 char *buf; | 764 char *buf; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 744 } | 785 } |
| 745 | 786 |
| 746 void SSLClientSocketNSS::BufferRecvComplete(int result) { | 787 void SSLClientSocketNSS::BufferRecvComplete(int result) { |
| 747 EnterFunction(result); | 788 EnterFunction(result); |
| 748 if (result > 0) { | 789 if (result > 0) { |
| 749 char *buf; | 790 char *buf; |
| 750 memio_GetReadParams(nss_bufs_, &buf); | 791 memio_GetReadParams(nss_bufs_, &buf); |
| 751 memcpy(buf, recv_buffer_->data(), result); | 792 memcpy(buf, recv_buffer_->data(), result); |
| 752 } | 793 } |
| 753 recv_buffer_ = NULL; | 794 recv_buffer_ = NULL; |
| 754 memio_PutReadResult(nss_bufs_, result); | 795 memio_PutReadResult(nss_bufs_, MapErrorToNSS(result)); |
| 755 transport_recv_busy_ = false; | 796 transport_recv_busy_ = false; |
| 756 OnRecvComplete(result); | 797 OnRecvComplete(result); |
| 757 LeaveFunction(""); | 798 LeaveFunction(""); |
| 758 } | 799 } |
| 759 | 800 |
| 760 int SSLClientSocketNSS::DoHandshakeLoop(int last_io_result) { | 801 int SSLClientSocketNSS::DoHandshakeLoop(int last_io_result) { |
| 761 EnterFunction(last_io_result); | 802 EnterFunction(last_io_result); |
| 762 bool network_moved; | 803 bool network_moved; |
| 763 int rv = last_io_result; | 804 int rv = last_io_result; |
| 764 do { | 805 do { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 } | 1130 } |
| 1090 PRErrorCode prerr = PR_GetError(); | 1131 PRErrorCode prerr = PR_GetError(); |
| 1091 if (prerr == PR_WOULD_BLOCK_ERROR) { | 1132 if (prerr == PR_WOULD_BLOCK_ERROR) { |
| 1092 return ERR_IO_PENDING; | 1133 return ERR_IO_PENDING; |
| 1093 } | 1134 } |
| 1094 LeaveFunction(""); | 1135 LeaveFunction(""); |
| 1095 return NetErrorFromNSPRError(prerr); | 1136 return NetErrorFromNSPRError(prerr); |
| 1096 } | 1137 } |
| 1097 | 1138 |
| 1098 } // namespace net | 1139 } // namespace net |
| OLD | NEW |