Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/secure_socket.h" | 5 #include "bin/secure_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 PK11_SetPasswordFunc(PasswordCallback); | 578 PK11_SetPasswordFunc(PasswordCallback); |
| 579 } | 579 } |
| 580 library_initialized_ = true; | 580 library_initialized_ = true; |
| 581 | 581 |
| 582 status = NSS_SetDomesticPolicy(); | 582 status = NSS_SetDomesticPolicy(); |
| 583 if (status != SECSuccess) { | 583 if (status != SECSuccess) { |
| 584 mutex_->Unlock(); // MutexLocker destructor not called when throwing. | 584 mutex_->Unlock(); // MutexLocker destructor not called when throwing. |
| 585 ThrowPRException("TlsException", | 585 ThrowPRException("TlsException", |
| 586 "Failed NSS_SetDomesticPolicy call."); | 586 "Failed NSS_SetDomesticPolicy call."); |
| 587 } | 587 } |
| 588 // Enable TLS, as well as SSL3 and SSL2. | 588 |
| 589 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); | 589 // Enable the same additional ciphers that Chromium does. |
| 590 if (status != SECSuccess) { | 590 // See NSSSSLInitSingleton() in Chromium's net/socket/nss_ssl_util.cc. |
| 591 mutex_->Unlock(); // MutexLocker destructor not called when throwing. | 591 // Explicitly enable exactly those ciphers with keys of at least 80 bits. |
| 592 ThrowPRException("TlsException", | 592 const PRUint16* const ssl_ciphers = SSL_GetImplementedCiphers(); |
|
Anders Johnsen
2013/12/04 10:08:57
Do we need to release this buffer somehow?
wtc
2013/12/04 14:35:16
No. SSL_GetImplementedCiphers() returns a pointer
| |
| 593 "Failed SSL_OptionSetDefault enable TLS call."); | 593 const PRUint16 num_ciphers = SSL_GetNumImplementedCiphers(); |
| 594 for (int i = 0; i < num_ciphers; i++) { | |
| 595 SSLCipherSuiteInfo info; | |
| 596 if (SSL_GetCipherSuiteInfo(ssl_ciphers[i], &info, sizeof(info)) == | |
| 597 SECSuccess) { | |
| 598 bool enabled = (info.effectiveKeyBits >= 80); | |
| 599 // Trim the list of cipher suites in order to keep the size of the | |
| 600 // ClientHello down. DSS, ECDH, CAMELLIA, SEED, ECC+3DES, and | |
| 601 // HMAC-SHA256 cipher suites are disabled. | |
| 602 if (info.symCipher == ssl_calg_camellia || | |
| 603 info.symCipher == ssl_calg_seed || | |
| 604 (info.symCipher == ssl_calg_3des && info.keaType != ssl_kea_rsa) || | |
| 605 info.authAlgorithm == ssl_auth_dsa || | |
| 606 info.macAlgorithm == ssl_hmac_sha256 || | |
| 607 info.nonStandard || | |
| 608 strcmp(info.keaTypeName, "ECDH") == 0) { | |
| 609 enabled = false; | |
| 610 } | |
| 611 | |
| 612 if (ssl_ciphers[i] == TLS_DHE_DSS_WITH_AES_128_CBC_SHA) { | |
| 613 // Enabled to allow servers with only a DSA certificate to function. | |
| 614 enabled = true; | |
| 615 } | |
| 616 SSL_CipherPrefSetDefault(ssl_ciphers[i], enabled); | |
| 617 } | |
| 594 } | 618 } |
| 619 | |
| 595 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL); | 620 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL); |
| 596 if (status != SECSuccess) { | 621 if (status != SECSuccess) { |
| 597 mutex_->Unlock(); // MutexLocker destructor not called when throwing. | 622 mutex_->Unlock(); // MutexLocker destructor not called when throwing. |
| 598 ThrowPRException("TlsException", | 623 ThrowPRException("TlsException", |
| 599 "Failed SSL_ConfigServerSessionIDCache call."); | 624 "Failed SSL_ConfigServerSessionIDCache call."); |
| 600 } | 625 } |
| 601 | 626 |
| 602 } else if (report_duplicate_initialization) { | 627 } else if (report_duplicate_initialization) { |
| 603 mutex_->Unlock(); // MutexLocker destructor not called when throwing. | 628 mutex_->Unlock(); // MutexLocker destructor not called when throwing. |
| 604 // Like ThrowPRException, without adding an OSError. | 629 // Like ThrowPRException, without adding an OSError. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 client_certificate_name_ = strdup(certificate_name); | 676 client_certificate_name_ = strdup(certificate_name); |
| 652 } | 677 } |
| 653 | 678 |
| 654 filter_ = SSL_ImportFD(NULL, filter_); | 679 filter_ = SSL_ImportFD(NULL, filter_); |
| 655 if (filter_ == NULL) { | 680 if (filter_ == NULL) { |
| 656 ThrowPRException("TlsException", "Failed SSL_ImportFD call"); | 681 ThrowPRException("TlsException", "Failed SSL_ImportFD call"); |
| 657 } | 682 } |
| 658 | 683 |
| 659 SSLVersionRange vrange; | 684 SSLVersionRange vrange; |
| 660 vrange.min = SSL_LIBRARY_VERSION_3_0; | 685 vrange.min = SSL_LIBRARY_VERSION_3_0; |
| 661 vrange.max = SSL_LIBRARY_VERSION_TLS_1_1; | 686 vrange.max = SSL_LIBRARY_VERSION_TLS_1_2; |
| 662 SSL_VersionRangeSet(filter_, &vrange); | 687 SSL_VersionRangeSet(filter_, &vrange); |
| 663 | 688 |
| 664 SECStatus status; | 689 SECStatus status; |
| 665 if (is_server) { | 690 if (is_server) { |
| 666 CERTCertificate* certificate = NULL; | 691 CERTCertificate* certificate = NULL; |
| 667 if (strstr(certificate_name, "CN=") != NULL) { | 692 if (strstr(certificate_name, "CN=") != NULL) { |
| 668 // Look up certificate using the distinguished name (DN) certificate_name. | 693 // Look up certificate using the distinguished name (DN) certificate_name. |
| 669 CERTCertDBHandle* certificate_database = CERT_GetDefaultCertDB(); | 694 CERTCertDBHandle* certificate_database = CERT_GetDefaultCertDB(); |
| 670 if (certificate_database == NULL) { | 695 if (certificate_database == NULL) { |
| 671 ThrowPRException("CertificateException", | 696 ThrowPRException("CertificateException", |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 } | 965 } |
| 941 if (bytes_processed > 0) { | 966 if (bytes_processed > 0) { |
| 942 memio_PutWriteResult(secret, bytes_processed); | 967 memio_PutWriteResult(secret, bytes_processed); |
| 943 } | 968 } |
| 944 } | 969 } |
| 945 return bytes_processed; | 970 return bytes_processed; |
| 946 } | 971 } |
| 947 | 972 |
| 948 } // namespace bin | 973 } // namespace bin |
| 949 } // namespace dart | 974 } // namespace dart |
| OLD | NEW |