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

Side by Side Diff: runtime/bin/secure_socket.cc

Issue 18080010: Remove static mutexes/monitors from dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/secure_socket.h ('k') | runtime/bin/socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 #include "bin/utils.h" 29 #include "bin/utils.h"
30 #include "platform/utils.h" 30 #include "platform/utils.h"
31 31
32 #include "include/dart_api.h" 32 #include "include/dart_api.h"
33 33
34 34
35 namespace dart { 35 namespace dart {
36 namespace bin { 36 namespace bin {
37 37
38 bool SSLFilter::library_initialized_ = false; 38 bool SSLFilter::library_initialized_ = false;
39 dart::Mutex SSLFilter::mutex_; // To protect library initialization. 39 // To protect library initialization.
40 dart::Mutex* SSLFilter::mutex_ = new dart::Mutex();
40 // The password is needed when creating secure server sockets. It can 41 // The password is needed when creating secure server sockets. It can
41 // be null if only secure client sockets are used. 42 // be null if only secure client sockets are used.
42 const char* SSLFilter::password_ = NULL; 43 const char* SSLFilter::password_ = NULL;
43 44
44 // Forward declaration. 45 // Forward declaration.
45 static void ProcessFilter(Dart_Port dest_port_id, 46 static void ProcessFilter(Dart_Port dest_port_id,
46 Dart_Port reply_port_id, 47 Dart_Port reply_port_id,
47 Dart_CObject* message); 48 Dart_CObject* message);
48 49
49 NativeService SSLFilter::filter_service_("FilterService", ProcessFilter, 16); 50 NativeService SSLFilter::filter_service_("FilterService", ProcessFilter, 16);
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 #else 521 #else
521 #error Automatic target os detection failed. 522 #error Automatic target os detection failed.
522 #endif 523 #endif
523 524
524 525
525 526
526 void SSLFilter::InitializeLibrary(const char* certificate_database, 527 void SSLFilter::InitializeLibrary(const char* certificate_database,
527 const char* password, 528 const char* password,
528 bool use_builtin_root_certificates, 529 bool use_builtin_root_certificates,
529 bool report_duplicate_initialization) { 530 bool report_duplicate_initialization) {
530 MutexLocker locker(&mutex_); 531 MutexLocker locker(mutex_);
531 SECStatus status; 532 SECStatus status;
532 if (!library_initialized_) { 533 if (!library_initialized_) {
533 password_ = strdup(password); // This one copy persists until Dart exits. 534 password_ = strdup(password); // This one copy persists until Dart exits.
534 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 535 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
535 // TODO(whesse): Verify there are no UTF-8 issues here. 536 // TODO(whesse): Verify there are no UTF-8 issues here.
536 if (certificate_database == NULL || certificate_database[0] == '\0') { 537 if (certificate_database == NULL || certificate_database[0] == '\0') {
537 status = NSS_NoDB_Init(NULL); 538 status = NSS_NoDB_Init(NULL);
538 if (status != SECSuccess) { 539 if (status != SECSuccess) {
539 mutex_.Unlock(); // MutexLocker destructor not called when throwing. 540 mutex_->Unlock(); // MutexLocker destructor not called when throwing.
540 ThrowPRException("TlsException", 541 ThrowPRException("TlsException",
541 "Failed NSS_NoDB_Init call."); 542 "Failed NSS_NoDB_Init call.");
542 } 543 }
543 if (use_builtin_root_certificates) { 544 if (use_builtin_root_certificates) {
544 SECMODModule* module = SECMOD_LoadUserModule( 545 SECMODModule* module = SECMOD_LoadUserModule(
545 const_cast<char*>(builtin_roots_module), NULL, PR_FALSE); 546 const_cast<char*>(builtin_roots_module), NULL, PR_FALSE);
546 if (!module) { 547 if (!module) {
547 mutex_.Unlock(); // MutexLocker destructor not called when throwing. 548 mutex_->Unlock(); // MutexLocker destructor not called when throwing.
548 ThrowPRException("TlsException", 549 ThrowPRException("TlsException",
549 "Failed to load builtin root certificates."); 550 "Failed to load builtin root certificates.");
550 } 551 }
551 } 552 }
552 } else { 553 } else {
553 PRUint32 init_flags = NSS_INIT_READONLY; 554 PRUint32 init_flags = NSS_INIT_READONLY;
554 if (!use_builtin_root_certificates) { 555 if (!use_builtin_root_certificates) {
555 init_flags |= NSS_INIT_NOMODDB; 556 init_flags |= NSS_INIT_NOMODDB;
556 } 557 }
557 status = NSS_Initialize(certificate_database, 558 status = NSS_Initialize(certificate_database,
558 "", 559 "",
559 "", 560 "",
560 SECMOD_DB, 561 SECMOD_DB,
561 init_flags); 562 init_flags);
562 if (status != SECSuccess) { 563 if (status != SECSuccess) {
563 mutex_.Unlock(); // MutexLocker destructor not called when throwing. 564 mutex_->Unlock(); // MutexLocker destructor not called when throwing.
564 ThrowPRException("TlsException", 565 ThrowPRException("TlsException",
565 "Failed NSS_Init call."); 566 "Failed NSS_Init call.");
566 } 567 }
567 } 568 }
568 library_initialized_ = true; 569 library_initialized_ = true;
569 570
570 status = NSS_SetDomesticPolicy(); 571 status = NSS_SetDomesticPolicy();
571 if (status != SECSuccess) { 572 if (status != SECSuccess) {
572 mutex_.Unlock(); // MutexLocker destructor not called when throwing. 573 mutex_->Unlock(); // MutexLocker destructor not called when throwing.
573 ThrowPRException("TlsException", 574 ThrowPRException("TlsException",
574 "Failed NSS_SetDomesticPolicy call."); 575 "Failed NSS_SetDomesticPolicy call.");
575 } 576 }
576 // Enable TLS, as well as SSL3 and SSL2. 577 // Enable TLS, as well as SSL3 and SSL2.
577 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); 578 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE);
578 if (status != SECSuccess) { 579 if (status != SECSuccess) {
579 mutex_.Unlock(); // MutexLocker destructor not called when throwing. 580 mutex_->Unlock(); // MutexLocker destructor not called when throwing.
580 ThrowPRException("TlsException", 581 ThrowPRException("TlsException",
581 "Failed SSL_OptionSetDefault enable TLS call."); 582 "Failed SSL_OptionSetDefault enable TLS call.");
582 } 583 }
583 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL); 584 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL);
584 if (status != SECSuccess) { 585 if (status != SECSuccess) {
585 mutex_.Unlock(); // MutexLocker destructor not called when throwing. 586 mutex_->Unlock(); // MutexLocker destructor not called when throwing.
586 ThrowPRException("TlsException", 587 ThrowPRException("TlsException",
587 "Failed SSL_ConfigServerSessionIDCache call."); 588 "Failed SSL_ConfigServerSessionIDCache call.");
588 } 589 }
589 590
590 } else if (report_duplicate_initialization) { 591 } else if (report_duplicate_initialization) {
591 mutex_.Unlock(); // MutexLocker destructor not called when throwing. 592 mutex_->Unlock(); // MutexLocker destructor not called when throwing.
592 // Like ThrowPRException, without adding an OSError. 593 // Like ThrowPRException, without adding an OSError.
593 Dart_ThrowException(DartUtils::NewDartIOException("TlsException", 594 Dart_ThrowException(DartUtils::NewDartIOException("TlsException",
594 "Called SecureSocket.initialize more than once", 595 "Called SecureSocket.initialize more than once",
595 Dart_Null())); 596 Dart_Null()));
596 } 597 }
597 } 598 }
598 599
599 600
600 char* PasswordCallback(PK11SlotInfo* slot, PRBool retry, void* arg) { 601 char* PasswordCallback(PK11SlotInfo* slot, PRBool retry, void* arg) {
601 if (!retry) { 602 if (!retry) {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 // Return a send port for the service port. 929 // Return a send port for the service port.
929 Dart_Handle send_port = Dart_NewSendPort(service_port); 930 Dart_Handle send_port = Dart_NewSendPort(service_port);
930 Dart_SetReturnValue(args, send_port); 931 Dart_SetReturnValue(args, send_port);
931 } 932 }
932 Dart_ExitScope(); 933 Dart_ExitScope();
933 } 934 }
934 935
935 936
936 } // namespace bin 937 } // namespace bin
937 } // namespace dart 938 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket.h ('k') | runtime/bin/socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698