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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 | 43 |
| 44 // Forward declaration. | 44 // Forward declaration. |
| 45 static void ProcessFilter(Dart_Port dest_port_id, | 45 static void ProcessFilter(Dart_Port dest_port_id, |
| 46 Dart_Port reply_port_id, | 46 Dart_Port reply_port_id, |
| 47 Dart_CObject* message); | 47 Dart_CObject* message); |
| 48 | 48 |
| 49 NativeService SSLFilter::filter_service_("FilterService", ProcessFilter, 16); | 49 NativeService SSLFilter::filter_service_("FilterService", ProcessFilter, 16); |
| 50 | 50 |
| 51 static const int kSSLFilterNativeFieldIndex = 0; | 51 static const int kSSLFilterNativeFieldIndex = 0; |
| 52 | 52 |
| 53 | |
| 54 /* Handle an error reported from the NSS library. */ | |
| 55 static void ThrowPRException(const char* exception_type, const char* message) { | |
| 56 PRErrorCode error_code = PR_GetError(); | |
| 57 const char* error_message = PR_ErrorToString(error_code, PR_LANGUAGE_EN); | |
| 58 OSError os_error_struct(error_code, error_message, OSError::kNSS); | |
| 59 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct); | |
| 60 Dart_Handle exception = | |
| 61 DartUtils::NewDartIOException(exception_type, message, os_error); | |
| 62 Dart_ThrowException(exception); | |
| 63 } | |
| 64 | |
| 65 | |
| 53 static SSLFilter* GetFilter(Dart_NativeArguments args) { | 66 static SSLFilter* GetFilter(Dart_NativeArguments args) { |
| 54 SSLFilter* filter; | 67 SSLFilter* filter; |
| 55 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); | 68 Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0)); |
| 56 ASSERT(Dart_IsInstance(dart_this)); | 69 ASSERT(Dart_IsInstance(dart_this)); |
| 57 ThrowIfError(Dart_GetNativeInstanceField( | 70 ThrowIfError(Dart_GetNativeInstanceField( |
| 58 dart_this, | 71 dart_this, |
| 59 kSSLFilterNativeFieldIndex, | 72 kSSLFilterNativeFieldIndex, |
| 60 reinterpret_cast<intptr_t*>(&filter))); | 73 reinterpret_cast<intptr_t*>(&filter))); |
| 61 return filter; | 74 return filter; |
| 62 } | 75 } |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 375 } |
| 363 } | 376 } |
| 364 | 377 |
| 365 | 378 |
| 366 static Dart_Handle X509FromCertificate(CERTCertificate* certificate) { | 379 static Dart_Handle X509FromCertificate(CERTCertificate* certificate) { |
| 367 PRTime start_validity; | 380 PRTime start_validity; |
| 368 PRTime end_validity; | 381 PRTime end_validity; |
| 369 SECStatus status = | 382 SECStatus status = |
| 370 CERT_GetCertTimes(certificate, &start_validity, &end_validity); | 383 CERT_GetCertTimes(certificate, &start_validity, &end_validity); |
| 371 if (status != SECSuccess) { | 384 if (status != SECSuccess) { |
| 372 ThrowPRException("Cannot get validity times from certificate"); | 385 ThrowPRException("CertificateException", |
| 386 "Cannot get validity times from certificate"); | |
| 373 } | 387 } |
| 374 int64_t start_epoch_ms = start_validity / PR_USEC_PER_MSEC; | 388 int64_t start_epoch_ms = start_validity / PR_USEC_PER_MSEC; |
| 375 int64_t end_epoch_ms = end_validity / PR_USEC_PER_MSEC; | 389 int64_t end_epoch_ms = end_validity / PR_USEC_PER_MSEC; |
| 376 Dart_Handle subject_name_object = | 390 Dart_Handle subject_name_object = |
| 377 DartUtils::NewString(certificate->subjectName); | 391 DartUtils::NewString(certificate->subjectName); |
| 378 Dart_Handle issuer_name_object = | 392 Dart_Handle issuer_name_object = |
| 379 DartUtils::NewString(certificate->issuerName); | 393 DartUtils::NewString(certificate->issuerName); |
| 380 Dart_Handle start_epoch_ms_int = Dart_NewInteger(start_epoch_ms); | 394 Dart_Handle start_epoch_ms_int = Dart_NewInteger(start_epoch_ms); |
| 381 Dart_Handle end_epoch_ms_int = Dart_NewInteger(end_epoch_ms); | 395 Dart_Handle end_epoch_ms_int = Dart_NewInteger(end_epoch_ms); |
| 382 | 396 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 Dart_Handle secure_filter_impl_type = | 440 Dart_Handle secure_filter_impl_type = |
| 427 Dart_InstanceGetType(dart_this); | 441 Dart_InstanceGetType(dart_this); |
| 428 Dart_Handle dart_buffer_size = ThrowIfError( | 442 Dart_Handle dart_buffer_size = ThrowIfError( |
| 429 Dart_GetField(secure_filter_impl_type, DartUtils::NewString("SIZE"))); | 443 Dart_GetField(secure_filter_impl_type, DartUtils::NewString("SIZE"))); |
| 430 int64_t buffer_size = DartUtils::GetIntegerValue(dart_buffer_size); | 444 int64_t buffer_size = DartUtils::GetIntegerValue(dart_buffer_size); |
| 431 Dart_Handle dart_encrypted_buffer_size = ThrowIfError( | 445 Dart_Handle dart_encrypted_buffer_size = ThrowIfError( |
| 432 Dart_GetField(secure_filter_impl_type, | 446 Dart_GetField(secure_filter_impl_type, |
| 433 DartUtils::NewString("ENCRYPTED_SIZE"))); | 447 DartUtils::NewString("ENCRYPTED_SIZE"))); |
| 434 int64_t encrypted_buffer_size = | 448 int64_t encrypted_buffer_size = |
| 435 DartUtils::GetIntegerValue(dart_encrypted_buffer_size); | 449 DartUtils::GetIntegerValue(dart_encrypted_buffer_size); |
| 436 if (buffer_size <= 0 || buffer_size > 1024 * 1024) { | 450 if (buffer_size <= 0 || buffer_size > 1024 * 1024) { |
|
Anders Johnsen
2013/06/25 05:55:03
I think these numbers deserve a constant.
Bill Hesse
2013/06/25 12:41:14
The upper one is just a sanity check - there is no
| |
| 437 Dart_ThrowException( | 451 FATAL("Invalid buffer size in _ExternalBuffer"); |
| 438 DartUtils::NewString("Invalid buffer size in _ExternalBuffer")); | |
| 439 } | 452 } |
| 440 if (encrypted_buffer_size <= 0 || encrypted_buffer_size > 1024 * 1024) { | 453 if (encrypted_buffer_size <= 0 || encrypted_buffer_size > 1024 * 1024) { |
| 441 Dart_ThrowException(DartUtils::NewString( | 454 FATAL("Invalid encrypted buffer size in _ExternalBuffer"); |
| 442 "Invalid encrypted buffer size in _ExternalBuffer")); | |
| 443 } | 455 } |
| 444 buffer_size_ = static_cast<int>(buffer_size); | 456 buffer_size_ = static_cast<int>(buffer_size); |
| 445 encrypted_buffer_size_ = static_cast<int>(encrypted_buffer_size); | 457 encrypted_buffer_size_ = static_cast<int>(encrypted_buffer_size); |
| 446 | 458 |
| 447 | 459 |
| 448 Dart_Handle data_identifier = DartUtils::NewString("data"); | 460 Dart_Handle data_identifier = DartUtils::NewString("data"); |
| 449 for (int i = 0; i < kNumBuffers; ++i) { | 461 for (int i = 0; i < kNumBuffers; ++i) { |
| 450 int size = isBufferEncrypted(i) ? encrypted_buffer_size_ : buffer_size_; | 462 int size = isBufferEncrypted(i) ? encrypted_buffer_size_ : buffer_size_; |
| 451 dart_buffer_objects_[i] = | 463 dart_buffer_objects_[i] = |
| 452 Dart_NewPersistentHandle(Dart_ListGetAt(dart_buffers_object, i)); | 464 Dart_NewPersistentHandle(Dart_ListGetAt(dart_buffers_object, i)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 MutexLocker locker(&mutex_); | 508 MutexLocker locker(&mutex_); |
| 497 SECStatus status; | 509 SECStatus status; |
| 498 if (!library_initialized_) { | 510 if (!library_initialized_) { |
| 499 password_ = strdup(password); // This one copy persists until Dart exits. | 511 password_ = strdup(password); // This one copy persists until Dart exits. |
| 500 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); | 512 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); |
| 501 // TODO(whesse): Verify there are no UTF-8 issues here. | 513 // TODO(whesse): Verify there are no UTF-8 issues here. |
| 502 if (certificate_database == NULL || certificate_database[0] == '\0') { | 514 if (certificate_database == NULL || certificate_database[0] == '\0') { |
| 503 status = NSS_NoDB_Init(NULL); | 515 status = NSS_NoDB_Init(NULL); |
| 504 if (status != SECSuccess) { | 516 if (status != SECSuccess) { |
| 505 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 517 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 506 ThrowPRException("Failed NSS_NoDB_Init call."); | 518 ThrowPRException("TlsException", |
| 519 "Failed NSS_NoDB_Init call."); | |
| 507 } | 520 } |
| 508 if (use_builtin_root_certificates) { | 521 if (use_builtin_root_certificates) { |
| 509 SECMODModule* module = SECMOD_LoadUserModule( | 522 SECMODModule* module = SECMOD_LoadUserModule( |
| 510 const_cast<char*>(builtin_roots_module), NULL, PR_FALSE); | 523 const_cast<char*>(builtin_roots_module), NULL, PR_FALSE); |
| 511 if (!module) { | 524 if (!module) { |
| 512 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 525 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 513 ThrowPRException("Failed to load builtin root certificates."); | 526 ThrowPRException("TlsException", |
| 527 "Failed to load builtin root certificates."); | |
| 514 } | 528 } |
| 515 } | 529 } |
| 516 } else { | 530 } else { |
| 517 PRUint32 init_flags = NSS_INIT_READONLY; | 531 PRUint32 init_flags = NSS_INIT_READONLY; |
| 518 if (!use_builtin_root_certificates) { | 532 if (!use_builtin_root_certificates) { |
| 519 init_flags |= NSS_INIT_NOMODDB; | 533 init_flags |= NSS_INIT_NOMODDB; |
| 520 } | 534 } |
| 521 status = NSS_Initialize(certificate_database, | 535 status = NSS_Initialize(certificate_database, |
| 522 "", | 536 "", |
| 523 "", | 537 "", |
| 524 SECMOD_DB, | 538 SECMOD_DB, |
| 525 init_flags); | 539 init_flags); |
| 526 if (status != SECSuccess) { | 540 if (status != SECSuccess) { |
| 527 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 541 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 528 ThrowPRException("Failed NSS_Init call."); | 542 ThrowPRException("TlsException", |
| 543 "Failed NSS_Init call."); | |
| 529 } | 544 } |
| 530 } | 545 } |
| 531 library_initialized_ = true; | 546 library_initialized_ = true; |
| 532 | 547 |
| 533 status = NSS_SetDomesticPolicy(); | 548 status = NSS_SetDomesticPolicy(); |
| 534 if (status != SECSuccess) { | 549 if (status != SECSuccess) { |
| 535 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 550 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 536 ThrowPRException("Failed NSS_SetDomesticPolicy call."); | 551 ThrowPRException("TlsException", |
| 552 "Failed NSS_SetDomesticPolicy call."); | |
| 537 } | 553 } |
| 538 // Enable TLS, as well as SSL3 and SSL2. | 554 // Enable TLS, as well as SSL3 and SSL2. |
| 539 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); | 555 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); |
| 540 if (status != SECSuccess) { | 556 if (status != SECSuccess) { |
| 541 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 557 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 542 ThrowPRException("Failed SSL_OptionSetDefault enable TLS call."); | 558 ThrowPRException("TlsException", |
| 559 "Failed SSL_OptionSetDefault enable TLS call."); | |
| 543 } | 560 } |
| 544 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL); | 561 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL); |
| 545 if (status != SECSuccess) { | 562 if (status != SECSuccess) { |
| 546 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 563 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 547 ThrowPRException("Failed SSL_ConfigServerSessionIDCache call."); | 564 ThrowPRException("TlsException", |
| 565 "Failed SSL_ConfigServerSessionIDCache call."); | |
| 548 } | 566 } |
| 549 | 567 |
| 550 } else if (report_duplicate_initialization) { | 568 } else if (report_duplicate_initialization) { |
| 551 mutex_.Unlock(); // MutexLocker destructor not called when throwing. | 569 mutex_.Unlock(); // MutexLocker destructor not called when throwing. |
| 552 ThrowException("Called SSLFilter::InitializeLibrary more than once"); | 570 // Like ThrowPRException, without adding an OSError. |
| 571 Dart_ThrowException(DartUtils::NewDartIOException("TlsException", | |
| 572 "Called SSLFilter::InitializeLibrary more than once", | |
|
Anders Johnsen
2013/06/25 05:55:03
:: -> ., we don't have :: in Dart.
Bill Hesse
2013/06/25 12:41:14
Changed message, and added documentation to Secure
| |
| 573 Dart_Null())); | |
| 553 } | 574 } |
| 554 } | 575 } |
| 555 | 576 |
| 556 | 577 |
| 557 char* PasswordCallback(PK11SlotInfo* slot, PRBool retry, void* arg) { | 578 char* PasswordCallback(PK11SlotInfo* slot, PRBool retry, void* arg) { |
| 558 if (!retry) { | 579 if (!retry) { |
| 559 return PL_strdup(static_cast<char*>(arg)); // Freed by NSS internals. | 580 return PL_strdup(static_cast<char*>(arg)); // Freed by NSS internals. |
| 560 } | 581 } |
| 561 return NULL; | 582 return NULL; |
| 562 } | 583 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 589 void SSLFilter::Connect(const char* host_name, | 610 void SSLFilter::Connect(const char* host_name, |
| 590 RawAddr* raw_addr, | 611 RawAddr* raw_addr, |
| 591 int port, | 612 int port, |
| 592 bool is_server, | 613 bool is_server, |
| 593 const char* certificate_name, | 614 const char* certificate_name, |
| 594 bool request_client_certificate, | 615 bool request_client_certificate, |
| 595 bool require_client_certificate, | 616 bool require_client_certificate, |
| 596 bool send_client_certificate) { | 617 bool send_client_certificate) { |
| 597 is_server_ = is_server; | 618 is_server_ = is_server; |
| 598 if (in_handshake_) { | 619 if (in_handshake_) { |
| 599 ThrowException("Connect called while already in handshake state."); | 620 FATAL("Connect called twice on the same _SecureFilter."); |
| 600 } | 621 } |
| 601 | 622 |
| 602 if (!is_server && certificate_name != NULL) { | 623 if (!is_server && certificate_name != NULL) { |
| 603 client_certificate_name_ = strdup(certificate_name); | 624 client_certificate_name_ = strdup(certificate_name); |
| 604 } | 625 } |
| 605 | 626 |
| 606 filter_ = SSL_ImportFD(NULL, filter_); | 627 filter_ = SSL_ImportFD(NULL, filter_); |
| 607 if (filter_ == NULL) { | 628 if (filter_ == NULL) { |
| 608 ThrowPRException("Failed SSL_ImportFD call"); | 629 ThrowPRException("TlsException", "Failed SSL_ImportFD call"); |
| 609 } | 630 } |
| 610 | 631 |
| 611 SSLVersionRange vrange; | 632 SSLVersionRange vrange; |
| 612 vrange.min = SSL_LIBRARY_VERSION_3_0; | 633 vrange.min = SSL_LIBRARY_VERSION_3_0; |
| 613 vrange.max = SSL_LIBRARY_VERSION_TLS_1_1; | 634 vrange.max = SSL_LIBRARY_VERSION_TLS_1_1; |
| 614 SSL_VersionRangeSet(filter_, &vrange); | 635 SSL_VersionRangeSet(filter_, &vrange); |
| 615 | 636 |
| 616 SECStatus status; | 637 SECStatus status; |
| 617 if (is_server) { | 638 if (is_server) { |
| 618 PK11_SetPasswordFunc(PasswordCallback); | 639 PK11_SetPasswordFunc(PasswordCallback); |
| 619 | 640 |
| 620 CERTCertificate* certificate = NULL; | 641 CERTCertificate* certificate = NULL; |
| 621 if (strstr(certificate_name, "CN=") != NULL) { | 642 if (strstr(certificate_name, "CN=") != NULL) { |
| 622 // Look up certificate using the distinguished name (DN) certificate_name. | 643 // Look up certificate using the distinguished name (DN) certificate_name. |
| 623 CERTCertDBHandle* certificate_database = CERT_GetDefaultCertDB(); | 644 CERTCertDBHandle* certificate_database = CERT_GetDefaultCertDB(); |
| 624 if (certificate_database == NULL) { | 645 if (certificate_database == NULL) { |
| 625 ThrowPRException("Certificate database cannot be loaded"); | 646 ThrowPRException("CertificateException", |
| 647 "Certificate database cannot be loaded"); | |
| 626 } | 648 } |
| 627 certificate = CERT_FindCertByNameString(certificate_database, | 649 certificate = CERT_FindCertByNameString(certificate_database, |
| 628 const_cast<char*>(certificate_name)); | 650 const_cast<char*>(certificate_name)); |
| 629 if (certificate == NULL) { | 651 if (certificate == NULL) { |
| 630 ThrowPRException( | 652 ThrowPRException("CertificateException", |
| 631 "Cannot find server certificate by distinguished name"); | 653 "Cannot find server certificate by distinguished name"); |
| 632 } | 654 } |
| 633 } else { | 655 } else { |
| 634 // Look up certificate using the nickname certificate_name. | 656 // Look up certificate using the nickname certificate_name. |
| 635 certificate = PK11_FindCertFromNickname( | 657 certificate = PK11_FindCertFromNickname( |
| 636 const_cast<char*>(certificate_name), | 658 const_cast<char*>(certificate_name), |
| 637 static_cast<void*>(const_cast<char*>(password_))); | 659 static_cast<void*>(const_cast<char*>(password_))); |
| 638 if (certificate == NULL) { | 660 if (certificate == NULL) { |
| 639 ThrowPRException("Cannot find server certificate by nickname"); | 661 ThrowPRException("CertificateException", |
| 662 "Cannot find server certificate by nickname"); | |
| 640 } | 663 } |
| 641 } | 664 } |
| 642 SECKEYPrivateKey* key = PK11_FindKeyByAnyCert( | 665 SECKEYPrivateKey* key = PK11_FindKeyByAnyCert( |
| 643 certificate, | 666 certificate, |
| 644 static_cast<void*>(const_cast<char*>(password_))); | 667 static_cast<void*>(const_cast<char*>(password_))); |
| 645 if (key == NULL) { | 668 if (key == NULL) { |
| 646 CERT_DestroyCertificate(certificate); | 669 CERT_DestroyCertificate(certificate); |
| 647 if (PR_GetError() == -8177) { | 670 if (PR_GetError() == -8177) { |
| 648 ThrowPRException("Certificate database password incorrect"); | 671 ThrowPRException("CertificateException", |
| 672 "Certificate database password incorrect"); | |
| 649 } else { | 673 } else { |
| 650 ThrowPRException("Failed PK11_FindKeyByAnyCert call." | 674 ThrowPRException("CertificateException", |
| 675 "Failed PK11_FindKeyByAnyCert call." | |
| 651 " Cannot find private key for certificate"); | 676 " Cannot find private key for certificate"); |
| 652 } | 677 } |
| 653 } | 678 } |
| 654 // kt_rsa (key type RSA) is an enum constant from the NSS libraries. | 679 // kt_rsa (key type RSA) is an enum constant from the NSS libraries. |
| 655 // TODO(whesse): Allow different key types. | 680 // TODO(whesse): Allow different key types. |
| 656 status = SSL_ConfigSecureServer(filter_, certificate, key, kt_rsa); | 681 status = SSL_ConfigSecureServer(filter_, certificate, key, kt_rsa); |
| 657 CERT_DestroyCertificate(certificate); | 682 CERT_DestroyCertificate(certificate); |
| 658 SECKEY_DestroyPrivateKey(key); | 683 SECKEY_DestroyPrivateKey(key); |
| 659 if (status != SECSuccess) { | 684 if (status != SECSuccess) { |
| 660 ThrowPRException("Failed SSL_ConfigSecureServer call"); | 685 ThrowPRException("CertificateException", |
| 686 "Failed SSL_ConfigSecureServer call"); | |
| 661 } | 687 } |
| 662 | 688 |
| 663 if (request_client_certificate) { | 689 if (request_client_certificate) { |
| 664 status = SSL_OptionSet(filter_, SSL_REQUEST_CERTIFICATE, PR_TRUE); | 690 status = SSL_OptionSet(filter_, SSL_REQUEST_CERTIFICATE, PR_TRUE); |
| 665 if (status != SECSuccess) { | 691 if (status != SECSuccess) { |
| 666 ThrowPRException("Failed SSL_OptionSet(REQUEST_CERTIFICATE) call"); | 692 ThrowPRException("TlsException", |
|
Anders Johnsen
2013/06/25 05:55:03
Here and below, it looks like it should be Certifi
Søren Gjesse
2013/06/25 06:35:49
I think TlsException is fine here. I see Certifica
| |
| 693 "Failed SSL_OptionSet(REQUEST_CERTIFICATE) call"); | |
| 667 } | 694 } |
| 668 PRBool require_cert = require_client_certificate ? PR_TRUE : PR_FALSE; | 695 PRBool require_cert = require_client_certificate ? PR_TRUE : PR_FALSE; |
| 669 status = SSL_OptionSet(filter_, SSL_REQUIRE_CERTIFICATE, require_cert); | 696 status = SSL_OptionSet(filter_, SSL_REQUIRE_CERTIFICATE, require_cert); |
| 670 if (status != SECSuccess) { | 697 if (status != SECSuccess) { |
| 671 ThrowPRException("Failed SSL_OptionSet(REQUIRE_CERTIFICATE) call"); | 698 ThrowPRException("TlsException", |
| 699 "Failed SSL_OptionSet(REQUIRE_CERTIFICATE) call"); | |
| 672 } | 700 } |
| 673 } | 701 } |
| 674 } else { // Client. | 702 } else { // Client. |
| 675 if (SSL_SetURL(filter_, host_name) == -1) { | 703 if (SSL_SetURL(filter_, host_name) == -1) { |
| 676 ThrowPRException("Failed SetURL call"); | 704 ThrowPRException("TlsException", |
| 705 "Failed SetURL call"); | |
| 677 } | 706 } |
| 678 | 707 |
| 679 // This disables the SSL session cache for client connections. | 708 // This disables the SSL session cache for client connections. |
| 680 // This resolves issue 7208, but degrades performance. | 709 // This resolves issue 7208, but degrades performance. |
| 681 // TODO(7230): Reenable session cache, without breaking client connections. | 710 // TODO(7230): Reenable session cache, without breaking client connections. |
| 682 status = SSL_OptionSet(filter_, SSL_NO_CACHE, PR_TRUE); | 711 status = SSL_OptionSet(filter_, SSL_NO_CACHE, PR_TRUE); |
| 683 if (status != SECSuccess) { | 712 if (status != SECSuccess) { |
| 684 ThrowPRException("Failed SSL_OptionSet(NO_CACHE) call"); | 713 ThrowPRException("TlsException", |
| 714 "Failed SSL_OptionSet(NO_CACHE) call"); | |
| 685 } | 715 } |
| 686 | 716 |
| 687 if (send_client_certificate) { | 717 if (send_client_certificate) { |
| 688 status = SSL_GetClientAuthDataHook( | 718 status = SSL_GetClientAuthDataHook( |
| 689 filter_, | 719 filter_, |
| 690 NSS_GetClientAuthData, | 720 NSS_GetClientAuthData, |
| 691 static_cast<void*>(client_certificate_name_)); | 721 static_cast<void*>(client_certificate_name_)); |
| 692 if (status != SECSuccess) { | 722 if (status != SECSuccess) { |
| 693 ThrowPRException("Failed SSL_GetClientAuthDataHook call"); | 723 ThrowPRException("TlsException", |
| 724 "Failed SSL_GetClientAuthDataHook call"); | |
| 694 } | 725 } |
| 695 } | 726 } |
| 696 } | 727 } |
| 697 | 728 |
| 698 // Install bad certificate callback, and pass 'this' to it if it is called. | 729 // Install bad certificate callback, and pass 'this' to it if it is called. |
| 699 status = SSL_BadCertHook(filter_, | 730 status = SSL_BadCertHook(filter_, |
| 700 BadCertificateCallback, | 731 BadCertificateCallback, |
| 701 static_cast<void*>(this)); | 732 static_cast<void*>(this)); |
| 702 | 733 |
| 703 PRBool as_server = is_server ? PR_TRUE : PR_FALSE; | 734 PRBool as_server = is_server ? PR_TRUE : PR_FALSE; |
| 704 status = SSL_ResetHandshake(filter_, as_server); | 735 status = SSL_ResetHandshake(filter_, as_server); |
| 705 if (status != SECSuccess) { | 736 if (status != SECSuccess) { |
| 706 ThrowPRException("Failed SSL_ResetHandshake call"); | 737 ThrowPRException("TlsException", |
| 738 "Failed SSL_ResetHandshake call"); | |
| 707 } | 739 } |
| 708 | 740 |
| 709 // Set the peer address from the address passed. The DNS has already | 741 // Set the peer address from the address passed. The DNS has already |
| 710 // been done in Dart code, so just use that address. This relies on | 742 // been done in Dart code, so just use that address. This relies on |
| 711 // following about PRNetAddr: "The raw member of the union is | 743 // following about PRNetAddr: "The raw member of the union is |
| 712 // equivalent to struct sockaddr", which is stated in the NSS | 744 // equivalent to struct sockaddr", which is stated in the NSS |
| 713 // documentation. | 745 // documentation. |
| 714 PRNetAddr peername; | 746 PRNetAddr peername; |
| 715 memset(&peername, 0, sizeof(peername)); | 747 memset(&peername, 0, sizeof(peername)); |
| 716 intptr_t len = SocketAddress::GetAddrLength(raw_addr); | 748 intptr_t len = SocketAddress::GetAddrLength(raw_addr); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 736 in_handshake_ = false; | 768 in_handshake_ = false; |
| 737 } | 769 } |
| 738 } else { | 770 } else { |
| 739 PRErrorCode error = PR_GetError(); | 771 PRErrorCode error = PR_GetError(); |
| 740 if (error == PR_WOULD_BLOCK_ERROR) { | 772 if (error == PR_WOULD_BLOCK_ERROR) { |
| 741 if (!in_handshake_) { | 773 if (!in_handshake_) { |
| 742 in_handshake_ = true; | 774 in_handshake_ = true; |
| 743 } | 775 } |
| 744 } else { | 776 } else { |
| 745 if (is_server_) { | 777 if (is_server_) { |
| 746 ThrowPRException("Unexpected handshake error in server"); | 778 ThrowPRException("HandshakeException", |
|
Søren Gjesse
2013/06/25 06:35:49
We could consider dropping HandshakeException and
Bill Hesse
2013/06/25 12:41:14
Let's see how it goes. I think we may also get ex
| |
| 779 "Handshake error in server"); | |
| 747 } else { | 780 } else { |
| 748 ThrowPRException("Unexpected handshake error in client"); | 781 ThrowPRException("HandshakeException", |
| 782 "Handshake error in client"); | |
| 749 } | 783 } |
| 750 } | 784 } |
| 751 } | 785 } |
| 752 } | 786 } |
| 753 | 787 |
| 754 | 788 |
| 755 void SSLFilter::Destroy() { | 789 void SSLFilter::Destroy() { |
| 756 for (int i = 0; i < kNumBuffers; ++i) { | 790 for (int i = 0; i < kNumBuffers; ++i) { |
| 757 Dart_DeletePersistentHandle(dart_buffer_objects_[i]); | 791 Dart_DeletePersistentHandle(dart_buffer_objects_[i]); |
| 758 delete[] buffers_[i]; | 792 delete[] buffers_[i]; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 // Return a send port for the service port. | 903 // Return a send port for the service port. |
| 870 Dart_Handle send_port = Dart_NewSendPort(service_port); | 904 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 871 Dart_SetReturnValue(args, send_port); | 905 Dart_SetReturnValue(args, send_port); |
| 872 } | 906 } |
| 873 Dart_ExitScope(); | 907 Dart_ExitScope(); |
| 874 } | 908 } |
| 875 | 909 |
| 876 | 910 |
| 877 } // namespace bin | 911 } // namespace bin |
| 878 } // namespace dart | 912 } // namespace dart |
| OLD | NEW |