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 11583026: Add automatic initialization of SecureSocket library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Change documentation to match code. Created 8 years 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') | sdk/lib/io/secure_socket.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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 DartUtils::GetDartClass(DartUtils::kIOLibURL, "X509Certificate"); 257 DartUtils::GetDartClass(DartUtils::kIOLibURL, "X509Certificate");
258 Dart_Handle arguments[] = { subject_name_object, 258 Dart_Handle arguments[] = { subject_name_object,
259 issuer_name_object, 259 issuer_name_object,
260 start_validity_date, 260 start_validity_date,
261 end_validity_date }; 261 end_validity_date };
262 return Dart_New(x509_class, Dart_Null(), 4, arguments); 262 return Dart_New(x509_class, Dart_Null(), 4, arguments);
263 } 263 }
264 264
265 265
266 void SSLFilter::Init(Dart_Handle dart_this) { 266 void SSLFilter::Init(Dart_Handle dart_this) {
267 if (!library_initialized_) {
268 InitializeLibrary(NULL, "", true, false);
269 }
267 string_start_ = ThrowIfError( 270 string_start_ = ThrowIfError(
268 Dart_NewPersistentHandle(DartUtils::NewString("start"))); 271 Dart_NewPersistentHandle(DartUtils::NewString("start")));
269 string_length_ = ThrowIfError( 272 string_length_ = ThrowIfError(
270 Dart_NewPersistentHandle(DartUtils::NewString("length"))); 273 Dart_NewPersistentHandle(DartUtils::NewString("length")));
271 274
272 InitializeBuffers(dart_this); 275 InitializeBuffers(dart_this);
273 filter_ = memio_CreateIOLayer(kMemioBufferSize); 276 filter_ = memio_CreateIOLayer(kMemioBufferSize);
274 } 277 }
275 278
276 279
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 void SSLFilter::RegisterBadCertificateCallback(Dart_Handle callback) { 316 void SSLFilter::RegisterBadCertificateCallback(Dart_Handle callback) {
314 if (NULL != bad_certificate_callback_) { 317 if (NULL != bad_certificate_callback_) {
315 Dart_DeletePersistentHandle(bad_certificate_callback_); 318 Dart_DeletePersistentHandle(bad_certificate_callback_);
316 } 319 }
317 bad_certificate_callback_ = ThrowIfError(Dart_NewPersistentHandle(callback)); 320 bad_certificate_callback_ = ThrowIfError(Dart_NewPersistentHandle(callback));
318 } 321 }
319 322
320 323
321 void SSLFilter::InitializeLibrary(const char* certificate_database, 324 void SSLFilter::InitializeLibrary(const char* certificate_database,
322 const char* password, 325 const char* password,
323 bool use_builtin_root_certificates) { 326 bool use_builtin_root_certificates,
327 bool report_duplicate_initialization) {
324 MutexLocker locker(&mutex_); 328 MutexLocker locker(&mutex_);
325 if (!library_initialized_) { 329 if (!library_initialized_) {
326 library_initialized_ = true; 330 library_initialized_ = true;
327 password_ = strdup(password); // This one copy persists until Dart exits. 331 password_ = strdup(password); // This one copy persists until Dart exits.
328 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 332 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
329 // TODO(whesse): Verify there are no UTF-8 issues here. 333 // TODO(whesse): Verify there are no UTF-8 issues here.
330 PRUint32 init_flags = NSS_INIT_READONLY; 334 PRUint32 init_flags = NSS_INIT_READONLY;
331 if (certificate_database == NULL) { 335 if (certificate_database == NULL) {
332 // Passing the empty string as the database path does not try to open 336 // Passing the empty string as the database path does not try to open
333 // a database in the current directory. 337 // a database in the current directory.
(...skipping 21 matching lines...) Expand all
355 // Enable TLS, as well as SSL3 and SSL2. 359 // Enable TLS, as well as SSL3 and SSL2.
356 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE); 360 status = SSL_OptionSetDefault(SSL_ENABLE_TLS, PR_TRUE);
357 if (status != SECSuccess) { 361 if (status != SECSuccess) {
358 ThrowPRException("Failed SSL_OptionSetDefault enable TLS call."); 362 ThrowPRException("Failed SSL_OptionSetDefault enable TLS call.");
359 } 363 }
360 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL); 364 status = SSL_ConfigServerSessionIDCache(0, 0, 0, NULL);
361 if (status != SECSuccess) { 365 if (status != SECSuccess) {
362 ThrowPRException("Failed SSL_ConfigServerSessionIDCache call."); 366 ThrowPRException("Failed SSL_ConfigServerSessionIDCache call.");
363 } 367 }
364 368
365 } else { 369 } else if (report_duplicate_initialization) {
370 mutex_.Unlock(); // MutexLocker destructor not called when throwing.
366 ThrowException("Called SSLFilter::InitializeLibrary more than once"); 371 ThrowException("Called SSLFilter::InitializeLibrary more than once");
367 } 372 }
368 } 373 }
369 374
370 375
371 char* PasswordCallback(PK11SlotInfo* slot, PRBool retry, void* arg) { 376 char* PasswordCallback(PK11SlotInfo* slot, PRBool retry, void* arg) {
372 if (!retry) { 377 if (!retry) {
373 return PL_strdup(static_cast<char*>(arg)); // Freed by NSS internals. 378 return PL_strdup(static_cast<char*>(arg)); // Freed by NSS internals.
374 } 379 }
375 return NULL; 380 return NULL;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 if (PR_WOULD_BLOCK_ERROR != pr_error) { 658 if (PR_WOULD_BLOCK_ERROR != pr_error) {
654 ThrowPRException("Error reading plaintext from SSLFilter"); 659 ThrowPRException("Error reading plaintext from SSLFilter");
655 } 660 }
656 bytes_processed = 0; 661 bytes_processed = 0;
657 } 662 }
658 break; 663 break;
659 } 664 }
660 } 665 }
661 return bytes_processed; 666 return bytes_processed;
662 } 667 }
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket.h ('k') | sdk/lib/io/secure_socket.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698