| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 SSLClientSocketNSS::DoVerifyCertComplete() derived | 5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived |
| 6 // from AuthCertificateCallback() in | 6 // from AuthCertificateCallback() in |
| 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. | 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. |
| 8 | 8 |
| 9 /* ***** BEGIN LICENSE BLOCK ***** | 9 /* ***** BEGIN LICENSE BLOCK ***** |
| 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } | 649 } |
| 650 | 650 |
| 651 bool SSLClientSocketNSS::SetReceiveBufferSize(int32 size) { | 651 bool SSLClientSocketNSS::SetReceiveBufferSize(int32 size) { |
| 652 return transport_->SetReceiveBufferSize(size); | 652 return transport_->SetReceiveBufferSize(size); |
| 653 } | 653 } |
| 654 | 654 |
| 655 bool SSLClientSocketNSS::SetSendBufferSize(int32 size) { | 655 bool SSLClientSocketNSS::SetSendBufferSize(int32 size) { |
| 656 return transport_->SetSendBufferSize(size); | 656 return transport_->SetSendBufferSize(size); |
| 657 } | 657 } |
| 658 | 658 |
| 659 #if defined(OS_WIN) |
| 660 // static |
| 661 X509Certificate::OSCertHandle SSLClientSocketNSS::CreateOSCert( |
| 662 const SECItem& der_cert) { |
| 663 // TODO(wtc): close cert_store_ at shutdown. |
| 664 if (!cert_store_) |
| 665 cert_store_ = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, 0, NULL); |
| 666 |
| 667 X509Certificate::OSCertHandle cert_handle = NULL; |
| 668 BOOL ok = CertAddEncodedCertificateToStore( |
| 669 cert_store_, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, |
| 670 der_cert.data, der_cert.len, CERT_STORE_ADD_USE_EXISTING, &cert_handle); |
| 671 return ok ? cert_handle : NULL; |
| 672 } |
| 673 #elif defined(OS_MACOSX) |
| 674 // static |
| 675 X509Certificate::OSCertHandle SSLClientSocketNSS::CreateOSCert( |
| 676 const SECItem& der_cert) { |
| 677 return X509Certificate::CreateOSCertHandleFromBytes( |
| 678 reinterpret_cast<char*>(der_cert.data), der_cert.len); |
| 679 } |
| 680 #endif |
| 681 |
| 659 X509Certificate *SSLClientSocketNSS::UpdateServerCert() { | 682 X509Certificate *SSLClientSocketNSS::UpdateServerCert() { |
| 660 // We set the server_cert_ from OwnAuthCertHandler(), but this handler | 683 // We set the server_cert_ from OwnAuthCertHandler(), but this handler |
| 661 // does not necessarily get called if we are continuing a cached SSL | 684 // does not necessarily get called if we are continuing a cached SSL |
| 662 // session. | 685 // session. |
| 663 if (server_cert_ == NULL) { | 686 if (server_cert_ == NULL) { |
| 664 server_cert_nss_ = SSL_PeerCertificate(nss_fd_); | 687 server_cert_nss_ = SSL_PeerCertificate(nss_fd_); |
| 665 if (server_cert_nss_) { | 688 if (server_cert_nss_) { |
| 666 #if defined(OS_MACOSX) || defined(OS_WIN) | 689 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 667 // Get each of the intermediate certificates in the server's chain. | 690 // Get each of the intermediate certificates in the server's chain. |
| 668 // These will be added to the server's X509Certificate object, making | 691 // These will be added to the server's X509Certificate object, making |
| (...skipping 10 matching lines...) Expand all Loading... |
| 679 continue; | 702 continue; |
| 680 #if defined(OS_WIN) | 703 #if defined(OS_WIN) |
| 681 // Work around http://crbug.com/43538 by not importing the | 704 // Work around http://crbug.com/43538 by not importing the |
| 682 // problematic COMODO EV SGC CA certificate. CryptoAPI will | 705 // problematic COMODO EV SGC CA certificate. CryptoAPI will |
| 683 // download a good certificate for that CA, issued by COMODO | 706 // download a good certificate for that CA, issued by COMODO |
| 684 // Certification Authority, using the AIA extension in the server | 707 // Certification Authority, using the AIA extension in the server |
| 685 // certificate. | 708 // certificate. |
| 686 if (IsProblematicComodoEVCACert(*node->cert)) | 709 if (IsProblematicComodoEVCACert(*node->cert)) |
| 687 continue; | 710 continue; |
| 688 #endif | 711 #endif |
| 689 cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 712 cert_handle = CreateOSCert(node->cert->derCert); |
| 690 reinterpret_cast<char*>(node->cert->derCert.data), | |
| 691 node->cert->derCert.len); | |
| 692 DCHECK(cert_handle); | 713 DCHECK(cert_handle); |
| 693 intermediate_ca_certs.push_back(cert_handle); | 714 intermediate_ca_certs.push_back(cert_handle); |
| 694 } | 715 } |
| 695 CERT_DestroyCertList(cert_list); | 716 CERT_DestroyCertList(cert_list); |
| 696 } | 717 } |
| 697 | 718 |
| 698 // Finally create the X509Certificate object. | 719 // Finally create the X509Certificate object. |
| 699 cert_handle = X509Certificate::CreateOSCertHandleFromBytes( | 720 cert_handle = CreateOSCert(server_cert_nss_->derCert); |
| 700 reinterpret_cast<char*>(server_cert_nss_->derCert.data), | |
| 701 server_cert_nss_->derCert.len); | |
| 702 DCHECK(cert_handle); | 721 DCHECK(cert_handle); |
| 703 server_cert_ = X509Certificate::CreateFromHandle( | 722 server_cert_ = X509Certificate::CreateFromHandle( |
| 704 cert_handle, | 723 cert_handle, |
| 705 X509Certificate::SOURCE_FROM_NETWORK, | 724 X509Certificate::SOURCE_FROM_NETWORK, |
| 706 intermediate_ca_certs); | 725 intermediate_ca_certs); |
| 707 for (size_t i = 0; i < intermediate_ca_certs.size(); ++i) | 726 for (size_t i = 0; i < intermediate_ca_certs.size(); ++i) |
| 708 X509Certificate::FreeOSCertHandle(intermediate_ca_certs[i]); | 727 X509Certificate::FreeOSCertHandle(intermediate_ca_certs[i]); |
| 709 #else | 728 #else |
| 710 server_cert_ = X509Certificate::CreateFromHandle( | 729 server_cert_ = X509Certificate::CreateFromHandle( |
| 711 CERT_DupCertificate(server_cert_nss_), | 730 CERT_DupCertificate(server_cert_nss_), |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1497 PRErrorCode prerr = PR_GetError(); | 1516 PRErrorCode prerr = PR_GetError(); |
| 1498 if (prerr == PR_WOULD_BLOCK_ERROR) { | 1517 if (prerr == PR_WOULD_BLOCK_ERROR) { |
| 1499 LeaveFunction(""); | 1518 LeaveFunction(""); |
| 1500 return ERR_IO_PENDING; | 1519 return ERR_IO_PENDING; |
| 1501 } | 1520 } |
| 1502 LeaveFunction(""); | 1521 LeaveFunction(""); |
| 1503 return MapNSPRError(prerr); | 1522 return MapNSPRError(prerr); |
| 1504 } | 1523 } |
| 1505 | 1524 |
| 1506 } // namespace net | 1525 } // namespace net |
| OLD | NEW |