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

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

Issue 12298035: Fix error handling in SecureSocket.initialize (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « no previous file | tests/standalone/io/secure_socket_argument_test.dart » ('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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 bad_certificate_callback_ = ThrowIfError(Dart_NewPersistentHandle(callback)); 333 bad_certificate_callback_ = ThrowIfError(Dart_NewPersistentHandle(callback));
334 } 334 }
335 335
336 336
337 void SSLFilter::InitializeLibrary(const char* certificate_database, 337 void SSLFilter::InitializeLibrary(const char* certificate_database,
338 const char* password, 338 const char* password,
339 bool use_builtin_root_certificates, 339 bool use_builtin_root_certificates,
340 bool report_duplicate_initialization) { 340 bool report_duplicate_initialization) {
341 MutexLocker locker(&mutex_); 341 MutexLocker locker(&mutex_);
342 if (!library_initialized_) { 342 if (!library_initialized_) {
343 library_initialized_ = true;
344 password_ = strdup(password); // This one copy persists until Dart exits. 343 password_ = strdup(password); // This one copy persists until Dart exits.
345 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 344 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
346 // TODO(whesse): Verify there are no UTF-8 issues here. 345 // TODO(whesse): Verify there are no UTF-8 issues here.
347 PRUint32 init_flags = NSS_INIT_READONLY; 346 PRUint32 init_flags = NSS_INIT_READONLY;
348 if (certificate_database == NULL) { 347 if (certificate_database == NULL) {
349 // Passing the empty string as the database path does not try to open 348 // Passing the empty string as the database path does not try to open
350 // a database in the current directory. 349 // a database in the current directory.
351 certificate_database = ""; 350 certificate_database = "";
352 // The flag NSS_INIT_NOCERTDB is documented to do what we want here, 351 // The flag NSS_INIT_NOCERTDB is documented to do what we want here,
353 // however it causes the builtins not to be available on Windows. 352 // however it causes the builtins not to be available on Windows.
354 init_flags |= NSS_INIT_FORCEOPEN; 353 init_flags |= NSS_INIT_FORCEOPEN;
355 } 354 }
356 if (!use_builtin_root_certificates) { 355 if (!use_builtin_root_certificates) {
357 init_flags |= NSS_INIT_NOMODDB; 356 init_flags |= NSS_INIT_NOMODDB;
358 } 357 }
359 SECStatus status = NSS_Initialize(certificate_database, 358 SECStatus status = NSS_Initialize(certificate_database,
360 "", 359 "",
361 "", 360 "",
362 SECMOD_DB, 361 SECMOD_DB,
363 init_flags); 362 init_flags);
364 if (status != SECSuccess) { 363 if (status != SECSuccess) {
364 mutex_.Unlock(); // MutexLocker destructor not called when throwing.
365 ThrowPRException("Failed NSS_Init call."); 365 ThrowPRException("Failed NSS_Init call.");
366 } 366 }
367 library_initialized_ = true;
367 368
368 status = NSS_SetDomesticPolicy(); 369 status = NSS_SetDomesticPolicy();
369 if (status != SECSuccess) { 370 if (status != SECSuccess) {
371 mutex_.Unlock(); // MutexLocker destructor not called when throwing.
370 ThrowPRException("Failed NSS_SetDomesticPolicy call."); 372 ThrowPRException("Failed NSS_SetDomesticPolicy call.");
371 } 373 }
372 // Enable TLS, as well as SSL3 and SSL2. 374 // Enable TLS, as well as SSL3 and SSL2.
373 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); 375 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE);
374 if (status != SECSuccess) { 376 if (status != SECSuccess) {
377 mutex_.Unlock(); // MutexLocker destructor not called when throwing.
375 ThrowPRException("Failed SSL_OptionSetDefault enable TLS call."); 378 ThrowPRException("Failed SSL_OptionSetDefault enable TLS call.");
376 } 379 }
377 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL); 380 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL);
378 if (status != SECSuccess) { 381 if (status != SECSuccess) {
382 mutex_.Unlock(); // MutexLocker destructor not called when throwing.
379 ThrowPRException("Failed SSL_ConfigServerSessionIDCache call."); 383 ThrowPRException("Failed SSL_ConfigServerSessionIDCache call.");
380 } 384 }
381 385
382 } else if (report_duplicate_initialization) { 386 } else if (report_duplicate_initialization) {
383 mutex_.Unlock(); // MutexLocker destructor not called when throwing. 387 mutex_.Unlock(); // MutexLocker destructor not called when throwing.
384 ThrowException("Called SSLFilter::InitializeLibrary more than once"); 388 ThrowException("Called SSLFilter::InitializeLibrary more than once");
385 } 389 }
386 } 390 }
387 391
388 392
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 if (PR_WOULD_BLOCK_ERROR != pr_error) { 676 if (PR_WOULD_BLOCK_ERROR != pr_error) {
673 ThrowPRException("Error reading plaintext from SSLFilter"); 677 ThrowPRException("Error reading plaintext from SSLFilter");
674 } 678 }
675 bytes_processed = 0; 679 bytes_processed = 0;
676 } 680 }
677 break; 681 break;
678 } 682 }
679 } 683 }
680 return bytes_processed; 684 return bytes_processed;
681 } 685 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/secure_socket_argument_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698